From 247808563aa236bd0c3749d04da1f370f7780419 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 16 Jun 2023 15:47:38 +0700 Subject: [PATCH] download error recovering --- tubearchivist/home/src/download/queue.py | 8 +++++++- tubearchivist/home/src/download/yt_dlp_base.py | 18 +++++++++++++++--- tubearchivist/home/tasks.py | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/src/download/queue.py b/tubearchivist/home/src/download/queue.py index 006b7a04..97636bb4 100644 --- a/tubearchivist/home/src/download/queue.py +++ b/tubearchivist/home/src/download/queue.py @@ -114,7 +114,13 @@ class PendingInteract: def update_status(self): """update status of pending item""" if self.status == "priority": - data = {"doc": {"status": "pending", "auto_start": True}} + data = { + "doc": { + "status": "pending", + "auto_start": True, + "message": None, + } + } else: data = {"doc": {"status": self.status}} diff --git a/tubearchivist/home/src/download/yt_dlp_base.py b/tubearchivist/home/src/download/yt_dlp_base.py index 62e5b028..526dbd40 100644 --- a/tubearchivist/home/src/download/yt_dlp_base.py +++ b/tubearchivist/home/src/download/yt_dlp_base.py @@ -49,7 +49,10 @@ class YtWrap: try: ydl.download([url]) except yt_dlp.utils.DownloadError as err: - print(f"{url}: failed to download.") + print(f"{url}: failed to download with message {err}") + if "Temporary failure in name resolution" in str(err): + raise ConnectionError("lost the internet, abort!") from err + return False, str(err) return True, True @@ -61,8 +64,17 @@ class YtWrap: except cookiejar.LoadError: print("cookie file is invalid") return False - except (yt_dlp.utils.ExtractorError, yt_dlp.utils.DownloadError): - print(f"{url}: failed to get info from youtube") + except yt_dlp.utils.ExtractorError as err: + print(f"{url}: failed to extract with message: {err}, continue...") + return False + except yt_dlp.utils.DownloadError as err: + if "This channel does not have a" in str(err): + return False + + print(f"{url}: failed to get info from youtube with message {err}") + if "Temporary failure in name resolution" in str(err): + raise ConnectionError("lost the internet, abort!") from err + return False return response diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index c5907839..76bc888c 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -113,7 +113,7 @@ class BaseTask(Task): """callback for task failure""" print(f"{task_id} Failed callback") message, key = self._build_message(level="error") - message.update({"messages": ["Task failed"]}) + message.update({"messages": [f"Task failed: {exc}"]}) RedisArchivist().set_message(key, message, expire=20) def on_success(self, retval, task_id, args, kwargs):