logging
This commit is contained in:
parent
f398cc448b
commit
527889317b
@ -11,6 +11,7 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
import pip
|
import pip
|
||||||
import signal
|
import signal
|
||||||
|
from logger import logger
|
||||||
|
|
||||||
def updateYoutubeDL():
|
def updateYoutubeDL():
|
||||||
pip.main(['install', '--target=' + dirpath, '--upgrade', 'youtube_dl'])
|
pip.main(['install', '--target=' + dirpath, '--upgrade', 'youtube_dl'])
|
||||||
@ -38,11 +39,12 @@ def executeYoutubeDL(url, cb):
|
|||||||
#"--external-downloader-args", "-re",
|
#"--external-downloader-args", "-re",
|
||||||
url
|
url
|
||||||
]
|
]
|
||||||
popen = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, preexec_fn=os.setsid)
|
popen = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)
|
||||||
|
|
||||||
# monitor the stdout and send to callback, if result from callback function is true,
|
# monitor the stdout and send to callback, if result from callback function is true,
|
||||||
# then kill the download process
|
# then kill the download process
|
||||||
BUFFER_SIZE = 8096
|
BUFFER_SIZE = 8096
|
||||||
|
logger.add(popen.stderr, "youtube-dl.log")
|
||||||
for chunk in iter(lambda: popen.stdout.read(BUFFER_SIZE), b''):
|
for chunk in iter(lambda: popen.stdout.read(BUFFER_SIZE), b''):
|
||||||
if cb(chunk):
|
if cb(chunk):
|
||||||
os.killpg(os.getpgid(popen.pid), signal.SIGTERM)
|
os.killpg(os.getpgid(popen.pid), signal.SIGTERM)
|
||||||
|
6
radio.py
6
radio.py
@ -1,14 +1,18 @@
|
|||||||
import downloader
|
import downloader
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
import sys
|
import sys
|
||||||
|
from logger import logger
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
process = ( ffmpeg
|
process = ( ffmpeg
|
||||||
.input('pipe:', re=None)
|
.input('pipe:', re=None)
|
||||||
.output("icecast://source:hackme@localhost:8000/stream.mp3", format='mp3', content_type="audio/mpeg")
|
.output("icecast://source:hackme@localhost:8000/stream.mp3", format='mp3', content_type="audio/mpeg")
|
||||||
.run_async(pipe_stdin=True)
|
.run_async(pipe_stdin=True, pipe_stdout=True, pipe_stderr=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.add(process.stdout, "ffmpeg.out.log")
|
||||||
|
logger.add(process.stderr, "ffmpeg.err.log")
|
||||||
|
|
||||||
def cb(chunk):
|
def cb(chunk):
|
||||||
process.stdin.write(chunk)
|
process.stdin.write(chunk)
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user