From 4b6c79caefd71af43ae234427a35e54a40cdf2c5 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Thu, 8 Sep 2022 09:54:57 -0700 Subject: [PATCH] [FEATURE] Add `webpage_url` source variable (#224) --- .../downloaders/soundcloud/albums_and_singles.py | 4 ++-- src/ytdl_sub/downloaders/youtube/channel.py | 2 +- src/ytdl_sub/downloaders/youtube/merge_playlist.py | 2 ++ src/ytdl_sub/downloaders/youtube/playlist.py | 2 +- src/ytdl_sub/entries/variables/entry_variables.py | 10 ++++++++++ tests/unit/entries/conftest.py | 12 +++++++++++- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py index 3052576b..3bc11119 100644 --- a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py +++ b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py @@ -147,7 +147,7 @@ class SoundcloudAlbumsAndSinglesDownloader( if not self.is_dry_run: _ = self.extract_info_with_retry( is_downloaded_fn=track.is_downloaded, - url=album.kwargs("webpage_url"), + url=album.webpage_url, ytdl_options_overrides={ "playlist_items": str(track.kwargs("playlist_index")), "writeinfojson": False, @@ -177,7 +177,7 @@ class SoundcloudAlbumsAndSinglesDownloader( if not self.is_dry_run: _ = self.extract_info_with_retry( is_downloaded_fn=track.is_downloaded, - url=track.kwargs("webpage_url"), + url=track.webpage_url, ytdl_options_overrides={"writeinfojson": False}, ) diff --git a/src/ytdl_sub/downloaders/youtube/channel.py b/src/ytdl_sub/downloaders/youtube/channel.py index 4a369cc8..cf587289 100644 --- a/src/ytdl_sub/downloaders/youtube/channel.py +++ b/src/ytdl_sub/downloaders/youtube/channel.py @@ -214,7 +214,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions as_single_video_dict = self.extract_info_with_retry( is_downloaded_fn=None if self.is_dry_run else video.is_downloaded, ytdl_options_overrides={"writeinfojson": False, "skip_download": self.is_dry_run}, - url=video.kwargs("webpage_url"), + url=video.webpage_url, ) # Workaround for the ytdlp issue diff --git a/src/ytdl_sub/downloaders/youtube/merge_playlist.py b/src/ytdl_sub/downloaders/youtube/merge_playlist.py index 2c0da03f..b699e278 100644 --- a/src/ytdl_sub/downloaders/youtube/merge_playlist.py +++ b/src/ytdl_sub/downloaders/youtube/merge_playlist.py @@ -141,6 +141,8 @@ class YoutubeMergePlaylistDownloader( if "requested_downloads" in entry_dict else "mkv" ) + entry_dict["webpage_url"] = self.download_options.playlist_url + return YoutubeVideo(entry_dict=entry_dict, working_directory=self.working_directory) def download(self) -> List[Tuple[YoutubeVideo, FileMetadata]]: diff --git a/src/ytdl_sub/downloaders/youtube/playlist.py b/src/ytdl_sub/downloaders/youtube/playlist.py index 76843307..69b48085 100644 --- a/src/ytdl_sub/downloaders/youtube/playlist.py +++ b/src/ytdl_sub/downloaders/youtube/playlist.py @@ -119,7 +119,7 @@ class YoutubePlaylistDownloader( as_single_video_dict = self.extract_info_with_retry( is_downloaded_fn=None if self.is_dry_run else video.is_downloaded, ytdl_options_overrides={"writeinfojson": False, "skip_download": self.is_dry_run}, - url=video.kwargs("webpage_url"), + url=video.webpage_url, ) # Workaround for the ytdlp issue diff --git a/src/ytdl_sub/entries/variables/entry_variables.py b/src/ytdl_sub/entries/variables/entry_variables.py index c4f42fe5..d1883990 100644 --- a/src/ytdl_sub/entries/variables/entry_variables.py +++ b/src/ytdl_sub/entries/variables/entry_variables.py @@ -99,6 +99,16 @@ class EntryVariables(SourceVariables): """ return sanitize_filename(self.title) + @property + def webpage_url(self: BaseEntry) -> str: + """ + Returns + ------- + str + The url to the webpage. + """ + return self.kwargs("webpage_url") + @property def ext(self: BaseEntry) -> str: """ diff --git a/tests/unit/entries/conftest.py b/tests/unit/entries/conftest.py index 012ba56c..110f637c 100644 --- a/tests/unit/entries/conftest.py +++ b/tests/unit/entries/conftest.py @@ -34,6 +34,11 @@ def thumbnail_ext(): return "jpg" +@pytest.fixture +def webpage_url() -> str: + return "https://yourname.here" + + @pytest.fixture def download_thumbnail_name(uid, thumbnail_ext): return f"{uid}.{thumbnail_ext}" @@ -52,6 +57,7 @@ def mock_entry_to_dict( extractor, upload_date, thumbnail_ext, + webpage_url, ): return { "uid": uid, @@ -78,11 +84,14 @@ def mock_entry_to_dict( "upload_day_of_year_reversed_padded": "354", "thumbnail_ext": thumbnail_ext, "info_json_ext": "info.json", + "webpage_url": webpage_url, } @pytest.fixture -def mock_entry_kwargs(uid, title, ext, upload_date, extractor, download_thumbnail_name): +def mock_entry_kwargs( + uid, title, ext, upload_date, extractor, download_thumbnail_name, webpage_url +): return { "id": uid, "extractor": extractor, @@ -90,6 +99,7 @@ def mock_entry_kwargs(uid, title, ext, upload_date, extractor, download_thumbnai "ext": ext, "upload_date": upload_date, "thumbnail": download_thumbnail_name, + "webpage_url": webpage_url, }