gpt4 book ai didi

python - Youtube-dl 在 python-rq 任务中监控状态

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:20 26 4
gpt4 key购买 nike

我正在尝试轮询以查看 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])

在我的主应用程序中,我尝试了所有变体,但似乎仍然无法获得 logger/my_hook 输出。

job = q.fetch_job(job_id)

一旦我有了 job_id,我似乎唯一能得到的是 job.result,如果它没有完成,就返回 None,我尝试打印以查看状态,但可以好像没找到。

我可能正在考虑将 my_hood 或记录器写入一个单独的临时文件,并且我可以读取该行,但我认为这可能过多?任何帮助或可能的解决方法将不胜感激。

最佳答案

在 github 问题的一些帮助后,我能够使用 get_current_job 来更新它并将其传递给元。

class MyLogger(object):
def debug(self, msg):
print(msg)
job = get_current_job()
job.meta['progress'] = msg
job.save()

关于python - Youtube-dl 在 python-rq 任务中监控状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32269387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com