Merge pull request #706 from tcely/patch-5

Add status text to the download task
This commit is contained in:
meeb 2025-02-12 05:46:39 +11:00 committed by GitHub
commit d4a46f252f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,6 +27,9 @@ class BaseStatus:
return status in cls.valid
def __init__(self, hook_status_dict=None):
self.media_key = None
self.task_status = '[Started: 0%]'
self.task_verbose_name = None
self._status_dict = hook_status_dict or self.status_dict
self._registered_keys = set()
@ -43,6 +46,24 @@ class BaseStatus:
if key in self._status_dict:
del self._status_dict[key]
def update_task(self):
if self.media_key is None:
return
from .models import Media
from .tasks import get_media_download_task
media = Media.objects.get(key=self.media_key)
task = get_media_download_task(str(media.pk))
if task:
if self.task_verbose_name is None:
# clean up any previously prepended task_status
# this happened because of duplicated tasks on my test system
s = task.verbose_name
cleaned = s[1+s.find(' Downloading '):]
self.task_verbose_name = cleaned
task.verbose_name = f'{self.task_status} {self.task_verbose_name}'
task.save()
class ProgressHookStatus(BaseStatus):
status_dict = progress_hook['status']
valid = frozenset((
@ -121,6 +142,10 @@ def yt_dlp_progress_hook(event):
percent = round(100 * downloaded_bytes / total_bytes)
if percent and (status.next_progress() < percent) and (0 == percent % 5):
status.download_progress = percent
if key:
status.media_key = key
status.task_status = f'[downloading: {percent_str}]'
status.update_task()
log.info(f'[youtube-dl] downloading: {filename} - {percent_str} '
f'of {total} at {speed}, {eta} remaining')
elif 'finished' == event['status']:
@ -171,6 +196,11 @@ def yt_dlp_postprocessor_hook(event):
del event['info_dict']['automatic_captions']
log.debug(repr(event['info_dict']))
if 'Unknown' != key:
status.media_key = key
status.task_status = f'[{event["postprocessor"]}: {event["status"]}]'
status.update_task()
log.info(f'[{event["postprocessor"]}] {event["status"]} for: {name}')
if 'finished' == event['status']:
status.cleanup()