initial commit
This commit is contained in:
commit
494822935b
8
default.nix
Normal file
8
default.nix
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> { }, self ? ./. }:
|
||||||
|
|
||||||
|
pkgs.python3Packages.buildPythonApplication {
|
||||||
|
pname = "radio";
|
||||||
|
src = self;
|
||||||
|
version = "0.1";
|
||||||
|
propagatedBuildInputs = with pkgs.python3Packages; [ pip ffmpeg-python youtube-dl ];
|
||||||
|
}
|
56
downloader.py
Normal file
56
downloader.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#
|
||||||
|
# Downloads the video/audio as a stream from a provided link using youtube-dl
|
||||||
|
# does not save the file, only the most recent fragment is held. Thus, this is
|
||||||
|
# ideal for devices with little memory
|
||||||
|
# TODO gather video metadata before download
|
||||||
|
#
|
||||||
|
|
||||||
|
# dirpath = tempfile.mkdtemp()
|
||||||
|
# sys.path.append(dirpath)
|
||||||
|
# def import_from_pip(package):
|
||||||
|
# pip.main(['install', '--target=' + dirpath, '--upgrade', package])
|
||||||
|
# return __import__(package)
|
||||||
|
# youtube_dl = import_from_pip('youtube_dl')
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
import pip
|
||||||
|
import sys
|
||||||
|
import youtube_dl
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
dirpath = tempfile.mkdtemp()
|
||||||
|
sys.path.append(dirpath)
|
||||||
|
|
||||||
|
BUFFER_SIZE = 1024
|
||||||
|
|
||||||
|
def execute(cmd):
|
||||||
|
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
|
# monitor the stdout
|
||||||
|
for chunk in iter(lambda: popen.stdout.read(BUFFER_SIZE), b''):
|
||||||
|
yield chunk
|
||||||
|
popen.stdout.close()
|
||||||
|
popen.wait()
|
||||||
|
|
||||||
|
def updateYoutubeDL():
|
||||||
|
pip.main(['install', '--target=' + dirpath, '--upgrade', package])
|
||||||
|
|
||||||
|
def download(url):
|
||||||
|
# update youtube-dl
|
||||||
|
# TODO: do this only every once in a while
|
||||||
|
#updateYoutubeDL()
|
||||||
|
|
||||||
|
# start downloader so that it's stdout (with fragments) may be captured
|
||||||
|
for s in execute(["python3","downloader.py",url]):
|
||||||
|
print(s)
|
||||||
|
|
||||||
|
def runYoutubeDL(url):
|
||||||
|
ydl_opts = {
|
||||||
|
'logtostderr': True,
|
||||||
|
'outtmpl': '-',
|
||||||
|
}
|
||||||
|
|
||||||
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
ydl.download([url])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
runYoutubeDL(sys.argv[1])
|
41
flake.lock
generated
Normal file
41
flake.lock
generated
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1620759905,
|
||||||
|
"narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1621784194,
|
||||||
|
"narHash": "sha256-CQWN/QvVHG8qCn7UhGGwoT3jAPvnJHQUvzBlIt48FGs=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "c5265c01a944b1cecfcfab392d5204d73d65d4ec",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
18
flake.nix
Normal file
18
flake.nix
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
description = "An internet radio service";
|
||||||
|
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let pkgs = nixpkgs.legacyPackages.${system}; in
|
||||||
|
rec {
|
||||||
|
packages = flake-utils.lib.flattenTree {
|
||||||
|
radio = import ./default.nix { inherit pkgs; inherit self; };
|
||||||
|
};
|
||||||
|
defaultPackage = packages.radio;
|
||||||
|
apps.radio = flake-utils.lib.mkApp { drv = packages.radio; };
|
||||||
|
defaultApp = apps.radio;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
8
radio.py
Normal file
8
radio.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import downloader
|
||||||
|
|
||||||
|
def run():
|
||||||
|
downloader.download('https://www.youtube.com/watch?v=BaW_jenozKc')
|
||||||
|
downloader.download('https://www.youtube.com/watch?v=kgBcg4uBd9Q')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
Loading…
x
Reference in New Issue
Block a user