mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-25 14:36:34 +00:00
Merge pull request #706 from tcely/patch-5
Add status text to the download task
This commit is contained in:
commit
d4a46f252f
@ -27,6 +27,9 @@ class BaseStatus:
|
|||||||
return status in cls.valid
|
return status in cls.valid
|
||||||
|
|
||||||
def __init__(self, hook_status_dict=None):
|
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._status_dict = hook_status_dict or self.status_dict
|
||||||
self._registered_keys = set()
|
self._registered_keys = set()
|
||||||
|
|
||||||
@ -43,6 +46,24 @@ class BaseStatus:
|
|||||||
if key in self._status_dict:
|
if key in self._status_dict:
|
||||||
del self._status_dict[key]
|
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):
|
class ProgressHookStatus(BaseStatus):
|
||||||
status_dict = progress_hook['status']
|
status_dict = progress_hook['status']
|
||||||
valid = frozenset((
|
valid = frozenset((
|
||||||
@ -121,6 +142,10 @@ def yt_dlp_progress_hook(event):
|
|||||||
percent = round(100 * downloaded_bytes / total_bytes)
|
percent = round(100 * downloaded_bytes / total_bytes)
|
||||||
if percent and (status.next_progress() < percent) and (0 == percent % 5):
|
if percent and (status.next_progress() < percent) and (0 == percent % 5):
|
||||||
status.download_progress = percent
|
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} '
|
log.info(f'[youtube-dl] downloading: {filename} - {percent_str} '
|
||||||
f'of {total} at {speed}, {eta} remaining')
|
f'of {total} at {speed}, {eta} remaining')
|
||||||
elif 'finished' == event['status']:
|
elif 'finished' == event['status']:
|
||||||
@ -171,6 +196,11 @@ def yt_dlp_postprocessor_hook(event):
|
|||||||
del event['info_dict']['automatic_captions']
|
del event['info_dict']['automatic_captions']
|
||||||
log.debug(repr(event['info_dict']))
|
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}')
|
log.info(f'[{event["postprocessor"]}] {event["status"]} for: {name}')
|
||||||
if 'finished' == event['status']:
|
if 'finished' == event['status']:
|
||||||
status.cleanup()
|
status.cleanup()
|
||||||
|
Loading…
Reference in New Issue
Block a user