1
我试图轮询以查看youtube-dl作业的状态。我无法弄清楚如何使这个工作。python-rq任务中的Youtube-dl监控状态
以下是我的python-RQ worker.py文件
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
ydl_opts = {
'format': 'bestaudio/best', # choice of quality
'extractaudio' : True, # only keep the audio
'outtmpl': temp_filepath, # name the location
'noplaylist' : True, # only download single song, not playlist
'prefer-ffmpeg' : True,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.download([url])
在我主要的应用程序我都想尽变异似乎仍不能得到记录器/ my_hook输出。
job = q.fetch_job(job_id)
一旦我有JOB_ID我似乎唯一能够得到的是job.result,而如果它没有这样做只是返回None
,我尝试打印看状态,但似乎无法找到它。
我可能会想让my_hood或logger写入一个单独的临时文件,我可以读取该行,但我认为这可能会过度? 任何帮助将不胜感激或可能的解决办法。