From 54b8b76034908c4d9cfb42aa87247fd93b3a4f97 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Tue, 21 Mar 2023 13:39:41 -0700 Subject: [PATCH] [BACKEND] Handle case when collection url is missing from entry (#558) * [BACKEND] Handle case when collection url is missing from entry * hide experimental docs --- docs/config.rst | 2 +- src/ytdl_sub/downloaders/url/downloader.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 7205e55d..94ea50d5 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -29,7 +29,7 @@ and subscriptions. .. autoclass:: ytdl_sub.config.config_validator.ConfigOptions() :members: :member-order: bysource - :exclude-members: persist_logs + :exclude-members: persist_logs, experimental persist_logs """""""""""" diff --git a/src/ytdl_sub/downloaders/url/downloader.py b/src/ytdl_sub/downloaders/url/downloader.py index a54c848d..dfebcf7c 100644 --- a/src/ytdl_sub/downloaders/url/downloader.py +++ b/src/ytdl_sub/downloaders/url/downloader.py @@ -175,7 +175,7 @@ class UrlDownloaderThumbnailPlugin(BaseDownloaderPlugin): """ Use the entry to download thumbnails (or move if LATEST_ENTRY) """ - if entry.kwargs(COLLECTION_URL) in self._collection_url_mapping: + if entry.kwargs_get(COLLECTION_URL) in self._collection_url_mapping: self._download_url_thumbnails( collection_url=self._collection_url_mapping[entry.kwargs(COLLECTION_URL)], entry=entry, @@ -205,11 +205,17 @@ class UrlDownloaderCollectionVariablePlugin(BaseDownloaderPlugin): """ Add collection variables to the entry """ - collection_url: Optional[UrlValidator] = self._collection_url_mapping.get( - entry.kwargs(COLLECTION_URL) + # COLLECTION_URL is a recent variable that may not exist for old entries when updating. + # Try to use source_webpage_url if it does not exist + entry_collection_url = entry.kwargs_get(COLLECTION_URL, entry.source_webpage_url) + + # If the collection URL cannot find its mapping, use the last URL + collection_url = ( + self._collection_url_mapping.get(entry_collection_url) + or list(self._collection_url_mapping.values())[-1] ) - if collection_url: - entry.add_variables(variables_to_add=collection_url.variables.dict_with_format_strings) + + entry.add_variables(variables_to_add=collection_url.variables.dict_with_format_strings) return entry