[BACKEND] upload_date_index source variables (#261)
* [BACKEND] `upload_date_index` source variables * len
This commit is contained in:
parent
897ea52e33
commit
6d52177104
5 changed files with 76 additions and 3 deletions
|
|
@ -33,7 +33,9 @@ from ytdl_sub.entries.base_entry import BaseEntry
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.entries.entry_parent import EntryParent
|
from ytdl_sub.entries.entry_parent import EntryParent
|
||||||
from ytdl_sub.entries.variables.kwargs import PLAYLIST_ENTRY
|
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 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.thread.log_entries_downloaded_listener import LogEntriesDownloadedListener
|
||||||
from ytdl_sub.utils.exceptions import FileNotDownloadedException
|
from ytdl_sub.utils.exceptions import FileNotDownloadedException
|
||||||
from ytdl_sub.utils.file_handler import FileHandler
|
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},
|
ytdl_options_overrides={"writeinfojson": False, "skip_download": self.is_dry_run},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Workaround for the ytdlp issue
|
upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date(
|
||||||
# pylint: disable=protected-access
|
upload_date_standardized=entry.upload_date_standardized
|
||||||
entry._kwargs["requested_subtitles"] = download_entry_dict.get("requested_subtitles")
|
)
|
||||||
|
|
||||||
|
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
|
# pylint: enable=protected-access
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
|
||||||
|
|
@ -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_ID
|
||||||
from ytdl_sub.entries.variables.kwargs import SOURCE_UPLOADER_URL
|
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 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
|
# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
|
|
@ -376,6 +377,46 @@ class EntryVariables(BaseEntryVariables):
|
||||||
"""
|
"""
|
||||||
return "jpg"
|
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
|
@property
|
||||||
def upload_date(self: Self) -> str:
|
def upload_date(self: Self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ PLAYLIST_UPLOADER = _("playlist_uploader")
|
||||||
PLAYLIST_UPLOADER_ID = _("playlist_uploader_id")
|
PLAYLIST_UPLOADER_ID = _("playlist_uploader_id")
|
||||||
PLAYLIST_UPLOADER_URL = _("playlist_uploader_url")
|
PLAYLIST_UPLOADER_URL = _("playlist_uploader_url")
|
||||||
|
|
||||||
|
UPLOAD_DATE_INDEX = _("upload_date_index", backend=True)
|
||||||
|
REQUESTED_SUBTITLES = _("requested_subtitles", backend=True)
|
||||||
UID = _("id")
|
UID = _("id")
|
||||||
EXTRACTOR = _("extractor")
|
EXTRACTOR = _("extractor")
|
||||||
EPOCH = _("epoch")
|
EPOCH = _("epoch")
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,21 @@ class DownloadMappings:
|
||||||
del self._entry_mappings[entry_id]
|
del self._entry_mappings[entry_id]
|
||||||
return self
|
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]:
|
def get_entries_out_of_range(self, date_range: DateRange) -> Dict[str, DownloadMapping]:
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ def mock_entry_to_dict(
|
||||||
"uploader": "abc123",
|
"uploader": "abc123",
|
||||||
"uploader_id": "abc123",
|
"uploader_id": "abc123",
|
||||||
"uploader_url": "https://yourname.here",
|
"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": upload_date,
|
||||||
"upload_date_standardized": "2021-01-12",
|
"upload_date_standardized": "2021-01-12",
|
||||||
"upload_year": 2021,
|
"upload_year": 2021,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue