diff --git a/src/ytdl_sub/config/overrides.py b/src/ytdl_sub/config/overrides.py index 2467fee1..e4dd4c92 100644 --- a/src/ytdl_sub/config/overrides.py +++ b/src/ytdl_sub/config/overrides.py @@ -2,7 +2,6 @@ import copy from typing import Any from typing import Dict from typing import Optional -from typing import Set from yt_dlp.utils import sanitize_filename diff --git a/src/ytdl_sub/config/preset.py b/src/ytdl_sub/config/preset.py index 8eff310d..e666b68c 100644 --- a/src/ytdl_sub/config/preset.py +++ b/src/ytdl_sub/config/preset.py @@ -21,7 +21,6 @@ from ytdl_sub.config.preset_options import OutputOptions from ytdl_sub.config.preset_options import TOptionsValidator from ytdl_sub.config.preset_options import YTDLOptions from ytdl_sub.downloaders.url.validators import MultiUrlValidator -from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.script.variable_definitions import VARIABLES from ytdl_sub.entries.script.variable_scripts import VARIABLE_SCRIPTS from ytdl_sub.prebuilt_presets import PREBUILT_PRESET_NAMES diff --git a/src/ytdl_sub/downloaders/info_json/info_json_downloader.py b/src/ytdl_sub/downloaders/info_json/info_json_downloader.py index 0ba65354..60983a1e 100644 --- a/src/ytdl_sub/downloaders/info_json/info_json_downloader.py +++ b/src/ytdl_sub/downloaders/info_json/info_json_downloader.py @@ -87,7 +87,6 @@ class InfoJsonDownloader(SourcePlugin[InfoJsonDownloaderOptions]): return Entry( entry_dict=entry_dict, working_directory=self.working_directory, - override_variables=self.overrides.dict_with_format_strings, ) raise ValidationException( @@ -102,13 +101,10 @@ class InfoJsonDownloader(SourcePlugin[InfoJsonDownloaderOptions]): entries: List[Entry] = [] for download_mapping in self._enhanced_download_archive.mapping.entry_mappings.values(): - entry = self._get_entry_from_download_mapping(download_mapping) - entries.append(entry) + entry = self._get_entry_from_download_mapping(download_mapping).initialize_script( + override_variables=self.overrides.dict_with_format_strings + ) - # Remove each entry from the live download archive since it will get re-added - # unless it is filtered - for entry in entries: - self._enhanced_download_archive.mapping.remove_entry(entry.uid) prior_variables = entry.kwargs_get(YTDL_SUB_ENTRY_VARIABLES_KWARG_KEY, {}) entry.add( @@ -123,8 +119,12 @@ class InfoJsonDownloader(SourcePlugin[InfoJsonDownloaderOptions]): ), } ) + entries.append(entry) for entry in sorted(entries, key=lambda ent: ent.get(v.download_index)): + # Remove each entry from the live download archive since it will get re-added + # unless it is filtered + self._enhanced_download_archive.mapping.remove_entry(entry.uid) yield entry # If the original entry file_path is no longer maintained in the new mapping, then diff --git a/src/ytdl_sub/downloaders/url/downloader.py b/src/ytdl_sub/downloaders/url/downloader.py index 1cf129ca..53b1dc72 100644 --- a/src/ytdl_sub/downloaders/url/downloader.py +++ b/src/ytdl_sub/downloaders/url/downloader.py @@ -360,7 +360,6 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]): return Entry( download_entry_dict, working_directory=self.working_directory, - override_variables=self.overrides.dict_with_format_strings, ) def _iterate_child_entries( @@ -421,7 +420,6 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]): parents=parents, entry_dicts=entry_dicts, working_directory=self.working_directory, - override_variables=self.overrides.dict_with_format_strings, ) return parents, orphans @@ -471,7 +469,9 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]): entry.add_kwargs( {COLLECTION_URL: self.overrides.apply_formatter(collection_url.url)} ) - yield entry + yield entry.initialize_script( + override_variables=self.overrides.dict_with_format_strings + ) def download(self, entry: Entry) -> Optional[Entry]: """ @@ -504,11 +504,6 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]): download_logger.info("Entry rejected by download match-filter, skipping ..") return None - upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date( - upload_date_standardized=entry.get(v.upload_date_standardized) - ) - download_idx = self._enhanced_download_archive.num_entries - entry.add_kwargs( { # Subtitles are not downloaded in metadata run, only here, so move over @@ -518,6 +513,11 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]): COMMENTS: download_entry.kwargs_get(COMMENTS), } ) + + upload_date_idx = self._enhanced_download_archive.mapping.get_num_entries_with_upload_date( + upload_date_standardized=entry.get(v.upload_date_standardized) + ) + download_idx = self._enhanced_download_archive.num_entries entry.add( { # Tracks number of entries downloaded diff --git a/src/ytdl_sub/entries/base_entry.py b/src/ytdl_sub/entries/base_entry.py index c05da40a..276e9297 100644 --- a/src/ytdl_sub/entries/base_entry.py +++ b/src/ytdl_sub/entries/base_entry.py @@ -3,7 +3,6 @@ from datetime import datetime from pathlib import Path from typing import Any from typing import Dict -from typing import List from typing import Optional from typing import Type from typing import TypeVar diff --git a/src/ytdl_sub/entries/entry.py b/src/ytdl_sub/entries/entry.py index bb2503e1..a0f55629 100644 --- a/src/ytdl_sub/entries/entry.py +++ b/src/ytdl_sub/entries/entry.py @@ -21,15 +21,15 @@ class Entry(BaseEntry, Scriptable): Entry object to represent a single media object returned from yt-dlp. """ - def __init__( - self, entry_dict: Dict, working_directory: str, override_variables: Dict[str, str] - ): + def __init__(self, entry_dict: Dict, working_directory: str): BaseEntry.__init__(self, entry_dict=entry_dict, working_directory=working_directory) Scriptable.__init__(self) + def initialize_script(self, override_variables: Dict[str, str]) -> "Entry": self.script.add({VARIABLES.entry_metadata.variable_name: f"{{{json.dumps(self._kwargs)}}}"}) self.add(override_variables) self.update_script() + return self def get(self, variable: Variable) -> str: return self.script.resolve(unresolvable=self.unresolvable).get_str(variable.variable_name) diff --git a/src/ytdl_sub/entries/entry_parent.py b/src/ytdl_sub/entries/entry_parent.py index 252c1030..d1afa715 100644 --- a/src/ytdl_sub/entries/entry_parent.py +++ b/src/ytdl_sub/entries/entry_parent.py @@ -283,7 +283,6 @@ class EntryParent(BaseEntry): parents: List["EntryParent"], entry_dicts: List[Dict], working_directory: str, - override_variables: Dict[str, str], ) -> List[Entry]: """ Reads all entries that do not have any parents @@ -296,7 +295,6 @@ class EntryParent(BaseEntry): Entry( entry_dict=entry_dict, working_directory=working_directory, - override_variables=override_variables, ) for entry_dict in entry_dicts if cls.is_entry(entry_dict) and not _in_any_parents(entry_dict) diff --git a/src/ytdl_sub/entries/script/variable_scripts.py b/src/ytdl_sub/entries/script/variable_scripts.py index 57b58c09..4525420f 100644 --- a/src/ytdl_sub/entries/script/variable_scripts.py +++ b/src/ytdl_sub/entries/script/variable_scripts.py @@ -147,7 +147,7 @@ ENTRY_DERIVED_VARIABLES: Dict[Variable, str] = { v.creator_sanitized: sanitized(v.creator), v.download_index_padded6: pad_int(v.download_index, 6), v.upload_date_index_padded: pad_int(v.upload_date_index, 2), - v.upload_date_index_reversed: f"{{%sub(100, {v.download_index.variable_name})}}", + v.upload_date_index_reversed: f"{{%sub(100, {v.upload_date_index.variable_name})}}", v.upload_date_index_reversed_padded: pad_int(v.upload_date_index_reversed, 2), } diff --git a/src/ytdl_sub/plugins/regex.py b/src/ytdl_sub/plugins/regex.py index 5b2f2428..678e50df 100644 --- a/src/ytdl_sub/plugins/regex.py +++ b/src/ytdl_sub/plugins/regex.py @@ -12,7 +12,6 @@ from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.script.variable_scripts import VARIABLE_SCRIPTS from ytdl_sub.entries.variables.kwargs import YTDL_SUB_REGEX_SOURCE_VARS from ytdl_sub.script.script import Script -from ytdl_sub.script.script import ScriptBuilder from ytdl_sub.utils.exceptions import RegexNoMatchException from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException from ytdl_sub.utils.logger import Logger diff --git a/src/ytdl_sub/utils/scriptable.py b/src/ytdl_sub/utils/scriptable.py index 50bd9891..5f1c21b2 100644 --- a/src/ytdl_sub/utils/scriptable.py +++ b/src/ytdl_sub/utils/scriptable.py @@ -5,7 +5,6 @@ from typing import Any from typing import Dict from typing import Set -from ytdl_sub.entries.script.variable_scripts import ENTRY_INJECTED_VARIABLES from ytdl_sub.entries.script.variable_scripts import UNRESOLVED_VARIABLES from ytdl_sub.entries.script.variable_scripts import VARIABLE_SCRIPTS from ytdl_sub.script.script import Script @@ -46,4 +45,4 @@ class Scriptable(ABC): ) self.unresolvable -= set(list(values.keys())) - self.script.resolve(unresolvable=self.unresolvable, update=True) + self.update_script() diff --git a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py index 0c91c050..7cb9cdd7 100644 --- a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py +++ b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py @@ -653,7 +653,6 @@ class EnhancedDownloadArchive: parent_entry = Entry( entry_dict=entry.kwargs(SPLIT_BY_CHAPTERS_PARENT_ENTRY), working_directory=entry.working_directory(), - override_variables={}, ) self.mapping.add_entry(parent_entry, entry_file_path=output_file_name) elif entry: diff --git a/tests/unit/entries/conftest.py b/tests/unit/entries/conftest.py index ff888a76..6fdf8e62 100644 --- a/tests/unit/entries/conftest.py +++ b/tests/unit/entries/conftest.py @@ -174,7 +174,7 @@ def mock_entry_kwargs( @pytest.fixture def mock_entry(mock_entry_kwargs): - return Entry(entry_dict=mock_entry_kwargs, working_directory=".", override_variables={}) + return Entry(entry_dict=mock_entry_kwargs, working_directory=".") @pytest.fixture