From 55637c2cafa3c11901bccf0b50c93d4f50693745 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 10 Feb 2025 04:34:58 -0500 Subject: [PATCH 1/4] Add status text to the download task --- tubesync/sync/hooks.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 3e8722a9..1200bb22 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -4,6 +4,9 @@ import yt_dlp from common.logger import log from django.conf import settings +from .models import Media +from .tasks import get_media_download_task + progress_hook = { 'status': dict(), @@ -27,6 +30,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 +49,17 @@ class BaseStatus: if key in self._status_dict: del self._status_dict[key] + def update_task(self): + if self.media_key is None: + return + 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: + self.task_verbose_name = task.verbose_name + 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 +138,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 +192,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() From 332f34c78e8776f36f1d2a333ea7c4bb2fe4955e Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 10 Feb 2025 04:46:35 -0500 Subject: [PATCH 2/4] Avoid `ImportError` --- tubesync/sync/hooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 1200bb22..6060a3a6 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -4,9 +4,6 @@ import yt_dlp from common.logger import log from django.conf import settings -from .models import Media -from .tasks import get_media_download_task - progress_hook = { 'status': dict(), @@ -18,6 +15,9 @@ postprocessor_hook = { class BaseStatus: + from .models import Media + from .tasks import get_media_download_task + status_dict = dict() valid = set() From b16fb062aaf2af42a16dd3abb1c7a1f652992544 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 10 Feb 2025 04:50:08 -0500 Subject: [PATCH 3/4] Avoid `ImportError` --- tubesync/sync/hooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 6060a3a6..7dcfb25a 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -15,9 +15,6 @@ postprocessor_hook = { class BaseStatus: - from .models import Media - from .tasks import get_media_download_task - status_dict = dict() valid = set() @@ -52,6 +49,9 @@ class BaseStatus: 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: From 33ad4179b86e714b928015db01d7ae5824e243b5 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 10 Feb 2025 05:27:45 -0500 Subject: [PATCH 4/4] Clean up previously prepended task_status --- tubesync/sync/hooks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 7dcfb25a..96c9f98d 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -56,8 +56,12 @@ class BaseStatus: task = get_media_download_task(str(media.pk)) if task: if self.task_verbose_name is None: - self.task_verbose_name = task.verbose_name - task.verbose_name = f'{self.task_status} ' + self.task_verbose_name + # 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):