From 3b14e03842d1ae46b24850472621379fd5aeedc7 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 01:50:23 -0500 Subject: [PATCH 01/16] Add & use functions from status classes --- tubesync/sync/hooks.py | 78 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index f39f7e76..491d0bbb 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -12,8 +12,31 @@ class ProgressHookStatus: 'error', )) - def __init__(self): + def valid_status(status): + return status in self.valid + + def get(key): + return progress_hook['status'].get(key, None) + + def __init__(self, *args, status=None, info_dict={}, filename=None, **kwargs): + self.filename = filename + self.info = info_dict + self.status = status self.download_progress = 0 + self._registered_keys = set() + + def register(self, *args): + additions = dict() + for key in args: + if key is not None: + self._registered_keys.add(key) + additions[key] = self + progress_hook['status'].update(additions) + + def cleanup(self): + for key in self._registered_keys: + if key in progress_hook['status']: + del progress_hook['status'][key] class PPHookStatus: valid = frozenset(( @@ -22,18 +45,39 @@ class PPHookStatus: 'finished', )) - def __init__(self, *args, status=None, postprocessor=None, info_dict={}, **kwargs): + def valid_status(status): + return status in self.valid + + def get(key): + return postprocessor_hook['status'].get(key, None) + + def __init__(self, *args, status=None, postprocessor=None, info_dict={}, filename=None, **kwargs): + self.filename = filename self.info = info_dict + self.media_name = None self.name = postprocessor self.status = status + self._registered_keys = set() + def register(self, *args): + additions = dict() + for key in args: + if key is not None: + self._registered_keys.add(key) + additions[key] = self + postprocessor_hook['status'].update(additions) + + def cleanup(self): + for key in self._registered_keys: + if key in postprocessor_hook['status']: + del postprocessor_hook['status'][key] def yt_dlp_progress_hook(event): - if event['status'] not in ProgressHookStatus.valid: + if not ProgressHookStatus.valid_status(event['status']): log.warn(f'[youtube-dl] unknown progress event: {str(event)}') return None - name = key = 'Unknown' + key = 'Unknown' if 'display_id' in event['info_dict']: key = event['info_dict']['display_id'] elif 'id' in event['info_dict']: @@ -44,9 +88,10 @@ def yt_dlp_progress_hook(event): log.error(f'[youtube-dl] error occured downloading: {filename}') elif 'downloading' == event['status']: # get or create the status for key - status = progress_hook['status'].get(key, None) + status = ProgressHookStatus.get(key) if status is None: - progress_hook['status'].update({key: ProgressHookStatus()}) + status = ProgressHookStatus(**event) + status.register(key, filename, status.filename) downloaded_bytes = event.get('downloaded_bytes', 0) or 0 total_bytes_estimate = event.get('total_bytes_estimate', 0) or 0 @@ -68,9 +113,10 @@ def yt_dlp_progress_hook(event): status.download_progress = percent or 0 elif 'finished' == event['status']: # update the status for key to the finished value - status = progress_hook['status'].get(key, None) + status = ProgressHookStatus.get(key) if status is None: - progress_hook['status'].update({key: ProgressHookStatus()}) + status = ProgressHookStatus(**event) + status.register(key, filename, status.filename) status.download_progress = 100 total_size_str = event.get('_total_bytes_str', '?').strip() @@ -78,22 +124,22 @@ def yt_dlp_progress_hook(event): log.info(f'[youtube-dl] finished downloading: {filename} - ' f'{total_size_str} in {elapsed_str}') - # clean up the status for key - if key in progress_hook['status']: - del progress_hook['status'][key] + status.cleanup() def yt_dlp_postprocessor_hook(event): - if event['status'] not in PPHookStatus.valid: + if not PPHookStatus.valid_status(event['status']): log.warn(f'[youtube-dl] unknown postprocessor event: {str(event)}') return None name = key = 'Unknown' + filename = os.path.basename(event.get('filename', '???')) if 'display_id' in event['info_dict']: key = event['info_dict']['display_id'] elif 'id' in event['info_dict']: key = event['info_dict']['id'] - postprocessor_hook['status'].update({key: PPHookStatus(*event)}) + status = PPHookStatus(**event) + status.register(key, filename, status.filename) title = None if 'fulltitle' in event['info_dict']: @@ -104,6 +150,8 @@ def yt_dlp_postprocessor_hook(event): if title: name = f'{key}: {title}' + status.media_name = name + if 'started' == event['status']: if 'formats' in event['info_dict']: del event['info_dict']['formats'] @@ -112,8 +160,8 @@ def yt_dlp_postprocessor_hook(event): log.debug(repr(event['info_dict'])) log.info(f'[{event["postprocessor"]}] {event["status"]} for: {name}') - if 'finished' == event['status'] and key in postprocessor_hook['status']: - del postprocessor_hook['status'][key] + if 'finished' == event['status']: + status.cleanup() progress_hook = { From 08842752d487bd3f4cb5af8580d60fb36ad56095 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 03:06:21 -0500 Subject: [PATCH 02/16] We can't use `self` without an instance --- tubesync/sync/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 491d0bbb..2f248a48 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -13,7 +13,7 @@ class ProgressHookStatus: )) def valid_status(status): - return status in self.valid + return status in ProgressHookStatus.valid def get(key): return progress_hook['status'].get(key, None) @@ -46,7 +46,7 @@ class PPHookStatus: )) def valid_status(status): - return status in self.valid + return status in PPHookStatus.valid def get(key): return postprocessor_hook['status'].get(key, None) From 75df4a57e38171c77bae878d27456846fae0f3a4 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 03:44:12 -0500 Subject: [PATCH 03/16] Move common methods to a `BaseStatus` class --- tubesync/sync/hooks.py | 66 +++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 2f248a48..c669a3b9 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -5,72 +5,66 @@ from common.logger import log from django.conf import settings -class ProgressHookStatus: +class BaseStatus: + valid = set() + + @classmethod + def valid_status(cls, status): + return status in cls.valid + + def __init__(self, hook_status_dict=None): + self._status_dict = hook_status_dict or dict() + self._registered_keys = set() + + def register(self, *args): + additions = dict() + for key in args: + if key is not None: + self._registered_keys.add(key) + additions[key] = self + self._status_dict.update(additions) + + def cleanup(self): + for key in self._registered_keys: + if key in self._status_dict: + del self._status_dict[key] + +class ProgressHookStatus(BaseStatus): valid = frozenset(( 'downloading', 'finished', 'error', )) - def valid_status(status): - return status in ProgressHookStatus.valid - + @staticmethod def get(key): return progress_hook['status'].get(key, None) def __init__(self, *args, status=None, info_dict={}, filename=None, **kwargs): + super().__init__(progress_hook['status']) self.filename = filename self.info = info_dict self.status = status self.download_progress = 0 - self._registered_keys = set() - def register(self, *args): - additions = dict() - for key in args: - if key is not None: - self._registered_keys.add(key) - additions[key] = self - progress_hook['status'].update(additions) - - def cleanup(self): - for key in self._registered_keys: - if key in progress_hook['status']: - del progress_hook['status'][key] - -class PPHookStatus: +class PPHookStatus(BaseStatus): valid = frozenset(( 'started', 'processing', 'finished', )) - def valid_status(status): - return status in PPHookStatus.valid - + @staticmethod def get(key): return postprocessor_hook['status'].get(key, None) def __init__(self, *args, status=None, postprocessor=None, info_dict={}, filename=None, **kwargs): + super().__init__(postprocessor_hook['status']) self.filename = filename self.info = info_dict self.media_name = None self.name = postprocessor self.status = status - self._registered_keys = set() - - def register(self, *args): - additions = dict() - for key in args: - if key is not None: - self._registered_keys.add(key) - additions[key] = self - postprocessor_hook['status'].update(additions) - - def cleanup(self): - for key in self._registered_keys: - if key in postprocessor_hook['status']: - del postprocessor_hook['status'][key] def yt_dlp_progress_hook(event): if not ProgressHookStatus.valid_status(event['status']): From 3c4849551bc9e32a9ef502cb3090dab199c1ac15 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 03:50:48 -0500 Subject: [PATCH 04/16] Define then update `*_hook` dictionaries --- tubesync/sync/hooks.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index c669a3b9..27133b49 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -5,6 +5,14 @@ from common.logger import log from django.conf import settings +progress_hook = { + 'status': dict(), +} + +postprocessor_hook = { + 'status': dict(), +} + class BaseStatus: valid = set() @@ -158,15 +166,13 @@ def yt_dlp_postprocessor_hook(event): status.cleanup() -progress_hook = { +progress_hook.update({ 'class': ProgressHookStatus(), 'function': yt_dlp_progress_hook, - 'status': dict(), -} +}) -postprocessor_hook = { +postprocessor_hook.update({ 'class': PPHookStatus(), 'function': yt_dlp_postprocessor_hook, - 'status': dict(), -} +}) From 09812019b561f2fc60504821fb9a7ff7b9dcc2f2 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 04:28:52 -0500 Subject: [PATCH 05/16] Use `next_progress` to avoid logging in spurts --- tubesync/sync/hooks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 27133b49..e3f55557 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -13,6 +13,7 @@ postprocessor_hook = { 'status': dict(), } + class BaseStatus: valid = set() @@ -55,6 +56,11 @@ class ProgressHookStatus(BaseStatus): self.status = status self.download_progress = 0 + def next_progress(self): + if 0 == self.download_progress: + return 0 + return 5 + self.download_progress + class PPHookStatus(BaseStatus): valid = frozenset(( 'started', @@ -109,10 +115,10 @@ def yt_dlp_progress_hook(event): pass if downloaded_bytes > 0 and total_bytes > 0: percent = round(100 * downloaded_bytes / total_bytes) - if percent and (0 < percent) and (0 == percent % 5): + if percent and (self.next_progress() < percent) and (0 == percent % 5): + status.download_progress = percent log.info(f'[youtube-dl] downloading: {filename} - {percent_str} ' f'of {total} at {speed}, {eta} remaining') - status.download_progress = percent or 0 elif 'finished' == event['status']: # update the status for key to the finished value status = ProgressHookStatus.get(key) From afa5ec8684cb3919261faf7262d201a0c4f53cd7 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 04:45:11 -0500 Subject: [PATCH 06/16] fixup: it is `status` not `self` needed here --- tubesync/sync/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index e3f55557..c6fddb70 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -115,7 +115,7 @@ def yt_dlp_progress_hook(event): pass if downloaded_bytes > 0 and total_bytes > 0: percent = round(100 * downloaded_bytes / total_bytes) - if percent and (self.next_progress() < percent) and (0 == percent % 5): + if percent and (status.next_progress() < percent) and (0 == percent % 5): status.download_progress = percent log.info(f'[youtube-dl] downloading: {filename} - {percent_str} ' f'of {total} at {speed}, {eta} remaining') From 6177ff4c597407b975cbe35bea9cc0d32ac27ec0 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 05:42:34 -0500 Subject: [PATCH 07/16] Move `get` into `BaseStatus` --- tubesync/sync/hooks.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index c6fddb70..a5c7f9ad 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -15,14 +15,19 @@ postprocessor_hook = { class BaseStatus: + status_dict = dict() valid = set() + @classmethod + def get(cls, key): + return cls.status_dict.get(key, None) + @classmethod def valid_status(cls, status): return status in cls.valid def __init__(self, hook_status_dict=None): - self._status_dict = hook_status_dict or dict() + self._status_dict = hook_status_dict or self.status_dict self._registered_keys = set() def register(self, *args): @@ -39,18 +44,15 @@ class BaseStatus: del self._status_dict[key] class ProgressHookStatus(BaseStatus): + status_dict = progress_hook['status'] valid = frozenset(( 'downloading', 'finished', 'error', )) - @staticmethod - def get(key): - return progress_hook['status'].get(key, None) - def __init__(self, *args, status=None, info_dict={}, filename=None, **kwargs): - super().__init__(progress_hook['status']) + super().__init__(self.status_dict) self.filename = filename self.info = info_dict self.status = status @@ -62,18 +64,15 @@ class ProgressHookStatus(BaseStatus): return 5 + self.download_progress class PPHookStatus(BaseStatus): + status_dict = postprocessor_hook['status'] valid = frozenset(( 'started', 'processing', 'finished', )) - @staticmethod - def get(key): - return postprocessor_hook['status'].get(key, None) - def __init__(self, *args, status=None, postprocessor=None, info_dict={}, filename=None, **kwargs): - super().__init__(postprocessor_hook['status']) + super().__init__(self.status_dict) self.filename = filename self.info = info_dict self.media_name = None @@ -100,6 +99,7 @@ def yt_dlp_progress_hook(event): if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) + log.info(ProgressHookStatus.status_dict) downloaded_bytes = event.get('downloaded_bytes', 0) or 0 total_bytes_estimate = event.get('total_bytes_estimate', 0) or 0 @@ -125,6 +125,7 @@ def yt_dlp_progress_hook(event): if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) + log.info(ProgressHookStatus.status_dict) status.download_progress = 100 total_size_str = event.get('_total_bytes_str', '?').strip() @@ -133,6 +134,7 @@ def yt_dlp_progress_hook(event): f'{total_size_str} in {elapsed_str}') status.cleanup() + log.info(ProgressHookStatus.status_dict) def yt_dlp_postprocessor_hook(event): if not PPHookStatus.valid_status(event['status']): From 71d84e1d74975ebba43dcc43b739978ffa5f7e9e Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 06:11:09 -0500 Subject: [PATCH 08/16] Better output --- tubesync/sync/hooks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index a5c7f9ad..26ab2c64 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -58,6 +58,9 @@ class ProgressHookStatus(BaseStatus): self.status = status self.download_progress = 0 + def __str__(self): + return f'{self.__name__}: {self.status} ({self.download_progress}) file: {self.filename}' + def next_progress(self): if 0 == self.download_progress: return 0 @@ -134,7 +137,6 @@ def yt_dlp_progress_hook(event): f'{total_size_str} in {elapsed_str}') status.cleanup() - log.info(ProgressHookStatus.status_dict) def yt_dlp_postprocessor_hook(event): if not PPHookStatus.valid_status(event['status']): From f5c832e5aba65a27bd41f9944dac7d1dcd9f061e Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 07:35:51 -0500 Subject: [PATCH 09/16] fixup: use repr to identify the class --- tubesync/sync/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 26ab2c64..3d679460 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -59,7 +59,7 @@ class ProgressHookStatus(BaseStatus): self.download_progress = 0 def __str__(self): - return f'{self.__name__}: {self.status} ({self.download_progress}) file: {self.filename}' + return f'{self!r}: {self.status} ({self.download_progress}) file: {self.filename}' def next_progress(self): if 0 == self.download_progress: From 034110e6fea83a4a8c09247056d1bcace1aa2ac7 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 11:42:19 -0500 Subject: [PATCH 10/16] Log str output --- tubesync/sync/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 3d679460..a64688f9 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -102,7 +102,7 @@ def yt_dlp_progress_hook(event): if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) - log.info(ProgressHookStatus.status_dict) + log.info(str(ProgressHookStatus.status_dict)) downloaded_bytes = event.get('downloaded_bytes', 0) or 0 total_bytes_estimate = event.get('total_bytes_estimate', 0) or 0 @@ -128,7 +128,7 @@ def yt_dlp_progress_hook(event): if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) - log.info(ProgressHookStatus.status_dict) + log.info(str(ProgressHookStatus.status_dict)) status.download_progress = 100 total_size_str = event.get('_total_bytes_str', '?').strip() From 074230b737cf123a156e1061105b8ca653984b9e Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 13:04:23 -0500 Subject: [PATCH 11/16] Switch from key to filename When downloading subtitles, key isn't available. --- tubesync/sync/hooks.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index a64688f9..24568a82 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -58,9 +58,6 @@ class ProgressHookStatus(BaseStatus): self.status = status self.download_progress = 0 - def __str__(self): - return f'{self!r}: {self.status} ({self.download_progress}) file: {self.filename}' - def next_progress(self): if 0 == self.download_progress: return 0 @@ -87,7 +84,7 @@ def yt_dlp_progress_hook(event): log.warn(f'[youtube-dl] unknown progress event: {str(event)}') return None - key = 'Unknown' + key = None if 'display_id' in event['info_dict']: key = event['info_dict']['display_id'] elif 'id' in event['info_dict']: @@ -97,12 +94,11 @@ def yt_dlp_progress_hook(event): if 'error' == event['status']: log.error(f'[youtube-dl] error occured downloading: {filename}') elif 'downloading' == event['status']: - # get or create the status for key - status = ProgressHookStatus.get(key) + # get or create the status for filename + status = ProgressHookStatus.get(filename) if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) - log.info(str(ProgressHookStatus.status_dict)) downloaded_bytes = event.get('downloaded_bytes', 0) or 0 total_bytes_estimate = event.get('total_bytes_estimate', 0) or 0 @@ -123,12 +119,11 @@ def yt_dlp_progress_hook(event): log.info(f'[youtube-dl] downloading: {filename} - {percent_str} ' f'of {total} at {speed}, {eta} remaining') elif 'finished' == event['status']: - # update the status for key to the finished value - status = ProgressHookStatus.get(key) + # update the status for filename to the finished value + status = ProgressHookStatus.get(filename) if status is None: status = ProgressHookStatus(**event) status.register(key, filename, status.filename) - log.info(str(ProgressHookStatus.status_dict)) status.download_progress = 100 total_size_str = event.get('_total_bytes_str', '?').strip() From ee9849a1aac45217cae8ebbabbaf3cf085fb69e6 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 13:58:22 -0500 Subject: [PATCH 12/16] Calculate percent from number of fragments downloaded --- tubesync/sync/hooks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 24568a82..1d6eb330 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -103,6 +103,8 @@ def yt_dlp_progress_hook(event): downloaded_bytes = event.get('downloaded_bytes', 0) or 0 total_bytes_estimate = event.get('total_bytes_estimate', 0) or 0 total_bytes = event.get('total_bytes', 0) or total_bytes_estimate + fragment_index = event.get('fragment_index', 0) or 0 + fragment_count = event.get('fragment_count', 0) or 0 eta = event.get('_eta_str', '?').strip() percent_str = event.get('_percent_str', '?').strip() speed = event.get('_speed_str', '?').strip() @@ -114,6 +116,8 @@ def yt_dlp_progress_hook(event): pass if downloaded_bytes > 0 and total_bytes > 0: percent = round(100 * downloaded_bytes / total_bytes) + if fragment_index > 0 and fragment_count > 0: + percent = round(100 * fragment_index / fragment_count) if percent and (status.next_progress() < percent) and (0 == percent % 5): status.download_progress = percent log.info(f'[youtube-dl] downloading: {filename} - {percent_str} ' From 90b892fd85ceb155717e7d2ce491a91fb1cf5815 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 15:21:23 -0500 Subject: [PATCH 13/16] Prefer fragment count calculation When the first fragment is downloaded, the percent is calculated as `100`, because the bytes and total are from the fragment, which prevents additional logging. --- tubesync/sync/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 1d6eb330..b03f7128 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -114,10 +114,10 @@ def yt_dlp_progress_hook(event): percent = int(float(percent_str.rstrip('%'))) except: pass - if downloaded_bytes > 0 and total_bytes > 0: - percent = round(100 * downloaded_bytes / total_bytes) if fragment_index > 0 and fragment_count > 0: percent = round(100 * fragment_index / fragment_count) + elif downloaded_bytes > 0 and total_bytes > 0: + percent = round(100 * downloaded_bytes / total_bytes) if percent and (status.next_progress() < percent) and (0 == percent % 5): status.download_progress = percent log.info(f'[youtube-dl] downloading: {filename} - {percent_str} ' From 23abc545d28e5d7dfd1e1cdc33bcdfa22984d16f Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 15:34:24 -0500 Subject: [PATCH 14/16] Replace '100%' with the calculated percent --- tubesync/sync/hooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index b03f7128..3c506eb7 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -116,6 +116,7 @@ def yt_dlp_progress_hook(event): pass if fragment_index > 0 and fragment_count > 0: percent = round(100 * fragment_index / fragment_count) + percent_str = f'{percent}%' elif downloaded_bytes > 0 and total_bytes > 0: percent = round(100 * downloaded_bytes / total_bytes) if percent and (status.next_progress() < percent) and (0 == percent % 5): From d7d1f52ff3077555d6269f3010cd1aead3bbec82 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 15:59:44 -0500 Subject: [PATCH 15/16] Completed fragments or bytes can be zero --- tubesync/sync/hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index 3c506eb7..faeeb81e 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -114,10 +114,10 @@ def yt_dlp_progress_hook(event): percent = int(float(percent_str.rstrip('%'))) except: pass - if fragment_index > 0 and fragment_count > 0: + if fragment_index >= 0 and fragment_count > 0: percent = round(100 * fragment_index / fragment_count) percent_str = f'{percent}%' - elif downloaded_bytes > 0 and total_bytes > 0: + elif downloaded_bytes >= 0 and total_bytes > 0: percent = round(100 * downloaded_bytes / total_bytes) if percent and (status.next_progress() < percent) and (0 == percent % 5): status.download_progress = percent From 64302e8191663d716deca1a8a6de6fc478026657 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 7 Feb 2025 17:15:45 -0500 Subject: [PATCH 16/16] Change the minimum next step to 1 --- tubesync/sync/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/hooks.py b/tubesync/sync/hooks.py index faeeb81e..3e8722a9 100644 --- a/tubesync/sync/hooks.py +++ b/tubesync/sync/hooks.py @@ -61,7 +61,7 @@ class ProgressHookStatus(BaseStatus): def next_progress(self): if 0 == self.download_progress: return 0 - return 5 + self.download_progress + return 1 + self.download_progress class PPHookStatus(BaseStatus): status_dict = postprocessor_hook['status']