diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index a2509ee7..4f2c31b3 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -33,7 +33,9 @@ from ytdl_sub.entries.base_entry import BaseEntry from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.entry_parent import EntryParent from ytdl_sub.entries.variables.kwargs import PLAYLIST_ENTRY +from ytdl_sub.entries.variables.kwargs import REQUESTED_SUBTITLES from ytdl_sub.entries.variables.kwargs import SOURCE_ENTRY +from ytdl_sub.entries.variables.kwargs import UPLOAD_DATE_INDEX from ytdl_sub.thread.log_entries_downloaded_listener import LogEntriesDownloadedListener from ytdl_sub.utils.exceptions import FileNotDownloadedException from ytdl_sub.utils.file_handler import FileHandler @@ -382,9 +384,18 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC): ytdl_options_overrides={"writeinfojson": False, "skip_download": self.is_dry_run}, ) - # Workaround for the ytdlp issue - # pylint: disable=protected-access - entry._kwargs["requested_subtitles"] = download_entry_dict.get("requested_subtitles") + upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date( + upload_date_standardized=entry.upload_date_standardized + ) + + entry.add_kwargs( + { + # Workaround for the yt-dlp issue that does not include subs in playlist downloads + REQUESTED_SUBTITLES: download_entry_dict.get(REQUESTED_SUBTITLES), + # Tracks number of entries with the same upload date to make them unique + UPLOAD_DATE_INDEX: upload_date_idx, + } + ) # pylint: enable=protected-access return entry diff --git a/src/ytdl_sub/entries/variables/entry_variables.py b/src/ytdl_sub/entries/variables/entry_variables.py index a37a7eb2..5f537710 100644 --- a/src/ytdl_sub/entries/variables/entry_variables.py +++ b/src/ytdl_sub/entries/variables/entry_variables.py @@ -26,6 +26,7 @@ from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER_ID from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER_URL from ytdl_sub.entries.variables.kwargs import SOURCE_WEBPAGE_URL +from ytdl_sub.entries.variables.kwargs import UPLOAD_DATE_INDEX # This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion # pylint: disable=no-member @@ -376,6 +377,46 @@ class EntryVariables(BaseEntryVariables): """ return "jpg" + @property + def upload_date_index(self: Self) -> int: + """ + Returns + ------- + int + The i'th entry downloaded with this upload date. + """ + return self.kwargs_get(UPLOAD_DATE_INDEX, 0) + 1 + + @property + def upload_date_index_padded(self: Self) -> str: + """ + Returns + ------- + int + The upload_date_index padded two digits + """ + return _pad(self.upload_date_index, 2) + + @property + def upload_date_index_reversed(self: Self) -> int: + """ + Returns + ------- + int + 100 - upload_date_index + """ + return 100 - self.upload_date_index + + @property + def upload_date_index_reversed_padded(self: Self) -> str: + """ + Returns + ------- + int + The upload_date_index padded two digits + """ + return _pad(self.upload_date_index_reversed, 2) + @property def upload_date(self: Self) -> str: """ diff --git a/src/ytdl_sub/entries/variables/kwargs.py b/src/ytdl_sub/entries/variables/kwargs.py index 80304ca2..ec1d14cf 100644 --- a/src/ytdl_sub/entries/variables/kwargs.py +++ b/src/ytdl_sub/entries/variables/kwargs.py @@ -40,6 +40,8 @@ PLAYLIST_UPLOADER = _("playlist_uploader") PLAYLIST_UPLOADER_ID = _("playlist_uploader_id") PLAYLIST_UPLOADER_URL = _("playlist_uploader_url") +UPLOAD_DATE_INDEX = _("upload_date_index", backend=True) +REQUESTED_SUBTITLES = _("requested_subtitles", backend=True) UID = _("id") EXTRACTOR = _("extractor") EPOCH = _("epoch") diff --git a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py index a995983f..dcb10bbb 100644 --- a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py +++ b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py @@ -227,6 +227,21 @@ class DownloadMappings: del self._entry_mappings[entry_id] return self + def get_num_entries_with_upload_date(self, upload_date_standardized: str) -> int: + """ + Parameters + ---------- + upload_date_standardized + A standardized upload date + + Returns + ------- + Number of entries in the mapping with this upload date + """ + return len( + [_ for _ in self._entry_mappings.values() if _.upload_date == upload_date_standardized] + ) + def get_entries_out_of_range(self, date_range: DateRange) -> Dict[str, DownloadMapping]: """ Parameters diff --git a/tests/unit/entries/conftest.py b/tests/unit/entries/conftest.py index 8be3a8b1..91411446 100644 --- a/tests/unit/entries/conftest.py +++ b/tests/unit/entries/conftest.py @@ -75,6 +75,10 @@ def mock_entry_to_dict( "uploader": "abc123", "uploader_id": "abc123", "uploader_url": "https://yourname.here", + "upload_date_index": 1, + "upload_date_index_padded": "01", + "upload_date_index_reversed": 99, + "upload_date_index_reversed_padded": "99", "upload_date": upload_date, "upload_date_standardized": "2021-01-12", "upload_year": 2021,