I'm trying to poll to see the status of a youtube-dl job. I am having trouble figuring out how to get this to work.
The following is my python-rq worker.py file
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])
And in my main app I have tried every variation and still can not seem to get the logger/my_hook output.
job = q.fetch_job(job_id)
Once I have the job_id the only thing I seem to be able to get is the job.result, which if its not done just returns None
, I try to print to see the status but can not seem to find it.
I was possibly thinking of having the my_hood or logger writing to a separate temporary file and I can read that line, but i think that might be excessive? Any help would be greatly appreciated or a possible work around.
After some help from the github isues, I was able to use the get_current_job to update it and pass it to meta.
class MyLogger(object):
def debug(self, msg):
print(msg)
job = get_current_job()
job.meta['progress'] = msg
job.save()