From f398cc448b39c44a8a51cfe35b59bc714a112e55 Mon Sep 17 00:00:00 2001 From: zuckerberg <5-zuckerberg@users.noreply.git.neet.dev> Date: Fri, 28 May 2021 22:19:37 -0400 Subject: [PATCH] basic streaming to icecast --- default.nix | 2 +- downloader.py | 2 +- radio.py | 18 ++++++++---------- setup.py | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/default.nix b/default.nix index 51dac78..9610e5f 100644 --- a/default.nix +++ b/default.nix @@ -4,5 +4,5 @@ pkgs.python3Packages.buildPythonApplication { pname = "radio"; src = self; version = "0.1"; - propagatedBuildInputs = with pkgs.python3Packages; [ pip ffmpeg-python youtube-dl ]; + propagatedBuildInputs = with pkgs.python3Packages; [ pip ffmpeg-python ]; } \ No newline at end of file diff --git a/downloader.py b/downloader.py index b7fbd72..2e7674c 100644 --- a/downloader.py +++ b/downloader.py @@ -31,7 +31,7 @@ def executeYoutubeDL(url, cb): "-o", "-", "-f", "bestaudio/best", # "--extract-audio", - "--audio-format", "wav", + "--audio-format", "mp3", "--prefer-ffmpeg", #"--postprocessor-args", "-re", #"--external-downloader", "ffmpeg", diff --git a/radio.py b/radio.py index 00377c1..d6bd6fd 100644 --- a/radio.py +++ b/radio.py @@ -3,20 +3,18 @@ import ffmpeg import sys def run(): - # process = ( - # ffmpeg - # .input('pipe:', format='wav') - # .output("icecast://source:hackme@localhost:8000/stream.mp3", format='mp3', content_type="audio/mpeg") - # .global_args("-re") # argument to act as a live stream - # .run_async(pipe_stdin=True) - # ) + process = ( ffmpeg + .input('pipe:', re=None) + .output("icecast://source:hackme@localhost:8000/stream.mp3", format='mp3', content_type="audio/mpeg") + .run_async(pipe_stdin=True) + ) def cb(chunk): - # process.stdin.write(chunk) - sys.stdout.write("".join(map(chr, chunk))) + process.stdin.write(chunk) return False - downloader.download('https://www.youtube.com/watch?v=BaW_jenozKc', cb) + downloader.download('https://www.youtube.com/watch?v=EbnH3VHzhu8', cb) + # downloader.download('https://www.youtube.com/watch?v=BaW_jenozKc', cb) # downloader.download('https://www.youtube.com/watch?v=kgBcg4uBd9Q', cb) # downloader.download('https://www.youtube.com/watch?v=EbnH3VHzhu8', cb) diff --git a/setup.py b/setup.py index 7ab9c1e..9242e5f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -requires = ["pip"] +requires = ["pip","ffmpeg-python"] setup( name='radio',