From 74d07f5cb27e7c1dec062ab5504b1356c88ba4fc Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Thu, 16 Nov 2023 15:54:36 +0300 Subject: [PATCH 1/4] Added support for showing when live stream starts as error message. --- app/ytdl.py | 14 ++++++++++++-- ui/src/app/app.component.html | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/ytdl.py b/app/ytdl.py index 44eceb5..6740de1 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -28,7 +28,7 @@ class DownloadQueueNotifier: raise NotImplementedError class DownloadInfo: - def __init__(self, id, title, url, quality, format, folder, custom_name_prefix): + def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error=None): self.id = id if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{id}' self.title = title if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{title}' self.url = url @@ -38,6 +38,7 @@ class DownloadInfo: self.custom_name_prefix = custom_name_prefix self.status = self.msg = self.percent = self.speed = self.eta = None self.timestamp = time.time_ns() + self.error = error class Download: manager = None @@ -86,6 +87,7 @@ class Download: 'outtmpl': { "default": self.output_template, "chapter": self.output_template_chapter }, 'format': self.format, 'socket_timeout': 30, + 'ignore_no_formats_error': True, 'progress_hooks': [put_status], 'postprocessor_hooks': [put_status_postprocessor], **self.ytdl_opts, @@ -216,6 +218,7 @@ class DownloadQueue: 'quiet': True, 'no_color': True, 'extract_flat': True, + 'ignore_no_formats_error': True, **self.config.YTDL_OPTIONS, }).extract_info(url, download=False) @@ -246,6 +249,13 @@ class DownloadQueue: if not entry: return {'status': 'error', 'msg': "Invalid/empty data was given."} + error = None + if "live_status" in entry and "release_timestamp" in entry and entry.get("live_status") == "is_upcoming": + error = f"Live stream is scheduled to start at {time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(entry.get('release_timestamp')))}" + else: + if "msg" in entry: + error = entry["msg"] + etype = entry.get('_type') or 'video' if etype == 'playlist': entries = entry['entries'] @@ -264,7 +274,7 @@ class DownloadQueue: return {'status': 'ok'} elif etype == 'video' or etype.startswith('url') and 'id' in entry and 'title' in entry: if not self.queue.exists(entry['id']): - dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder, custom_name_prefix) + dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder, custom_name_prefix, error) dldirectory, error_message = self.__calc_download_path(quality, format, folder) if error_message is not None: return error_message diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html index a339eb7..dcba6ec 100644 --- a/ui/src/app/app.component.html +++ b/ui/src/app/app.component.html @@ -156,14 +156,19 @@ - {{ download.value.title }} - {{ download.value.title }} + {{ download.value.title }} + + {{download.value.title}} +
{{download.value.msg}}
+
Error: {{download.value.error}}
+
- + + From 9552fb3ca05e69568e82b97fea9792eff4479840 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Thu, 16 Nov 2023 16:16:00 +0300 Subject: [PATCH 2/4] report date time correctly. --- app/ytdl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/ytdl.py b/app/ytdl.py index 6740de1..ddf7386 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -8,6 +8,7 @@ import multiprocessing import logging import re from dl_formats import get_format, get_opts, AUDIO_FORMATS +from datetime import datetime log = logging.getLogger('ytdl') @@ -251,7 +252,8 @@ class DownloadQueue: error = None if "live_status" in entry and "release_timestamp" in entry and entry.get("live_status") == "is_upcoming": - error = f"Live stream is scheduled to start at {time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(entry.get('release_timestamp')))}" + dt_ts = datetime.fromtimestamp(entry.get("release_timestamp")).strftime('%Y-%m-%d %H:%M:%S %z') + error = f"Live stream is scheduled to start at {dt_ts}" else: if "msg" in entry: error = entry["msg"] From 2a574470186b664adc89fd0b5f2c3ba39e92650c Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Thu, 16 Nov 2023 20:50:02 +0300 Subject: [PATCH 3/4] Removed default param for error --- app/ytdl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ytdl.py b/app/ytdl.py index ddf7386..8e32292 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -29,7 +29,7 @@ class DownloadQueueNotifier: raise NotImplementedError class DownloadInfo: - def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error=None): + def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error): self.id = id if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{id}' self.title = title if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{title}' self.url = url From add2a04003cb7b03e079cb0891843c6242be2d7b Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Thu, 16 Nov 2023 23:11:15 +0300 Subject: [PATCH 4/4] Hide download button if no file has been downloaded. --- ui/src/app/app.component.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html index dcba6ec..98248b5 100644 --- a/ui/src/app/app.component.html +++ b/ui/src/app/app.component.html @@ -167,8 +167,7 @@ - - +