[maybe] URL rewrite to allow list

This commit is contained in:
Jesse Bannon 2025-12-30 17:37:34 -08:00
parent 1abe2a44f5
commit 5224b321c8
5 changed files with 260 additions and 924 deletions

View file

@ -485,21 +485,24 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
def download_metadata(self) -> Iterable[Entry]:
"""The function to perform the download of all media entries"""
# download the bottom-most urls first since they are top-priority
for idx, url_validator in reversed(list(enumerate(self.collection.urls.list))):
# URLs can be empty. If they are, then skip
if not (url := self.overrides.apply_formatter(url_validator.url)):
continue
for idx, validator in reversed(list(enumerate(self.collection.urls.list))):
# Iterate the inner url list bottom-most first as well
for url_validator in reversed(validator.url):
for entry in self._download_metadata(url=url, validator=url_validator):
entry.initialize_script(self.overrides).add(
{
v.ytdl_sub_input_url: url,
v.ytdl_sub_input_url_index: idx,
v.ytdl_sub_input_url_count: len(self.collection.urls.list),
}
)
# URLs can be empty. If they are, then skip
if not (url := self.overrides.apply_formatter(url_validator)):
continue
yield entry
for entry in self._download_metadata(url=url, validator=validator):
entry.initialize_script(self.overrides).add(
{
v.ytdl_sub_input_url: url,
v.ytdl_sub_input_url_index: idx,
v.ytdl_sub_input_url_count: len(self.collection.urls.list),
}
)
yield entry
def download(self, entry: Entry) -> Optional[Entry]:
"""

View file

@ -1,4 +1,4 @@
from typing import Any
from typing import Any, List
from typing import Dict
from typing import Optional
from typing import Set
@ -8,7 +8,8 @@ from ytdl_sub.config.preset_options import YTDLOptions
from ytdl_sub.config.validators.options import OptionsValidator
from ytdl_sub.script.parser import parse
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
from ytdl_sub.validators.string_formatter_validators import DictFormatterValidator
from ytdl_sub.validators.string_formatter_validators import DictFormatterValidator, \
OverridesListFormatterValidator
from ytdl_sub.validators.string_formatter_validators import OverridesBooleanFormatterValidator
from ytdl_sub.validators.string_formatter_validators import OverridesStringFormatterValidator
from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator
@ -67,8 +68,7 @@ class UrlValidator(StrictDictValidator):
def __init__(self, name, value):
super().__init__(name, value)
# TODO: url validate using yt-dlp IE
self._url = self._validate_key(key="url", validator=OverridesStringFormatterValidator)
self._url = self._validate_key(key="url", validator=OverridesListFormatterValidator)
self._variables = self._validate_key_if_present(
key="variables", validator=DictFormatterValidator, default={}
)
@ -95,11 +95,11 @@ class UrlValidator(StrictDictValidator):
)
@property
def url(self) -> OverridesStringFormatterValidator:
def url(self) -> List[OverridesStringFormatterValidator]:
"""
Required. URL to download from.
"""
return self._url
return self._url.list
@property
def variables(self) -> DictFormatterValidator:

File diff suppressed because it is too large Load diff

View file

@ -142,43 +142,17 @@ presets:
uid: "avatar_uncropped"
- name: "{tv_show_fanart_file_name}"
uid: "banner_uncropped"
- url: "{ %get_season_url(collection_season_1_url, 1) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 2) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 3) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 4) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 5) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 6) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 7) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 8) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 9) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
- url: "{ %get_season_url(collection_season_1_url, 10) }"
- url:
- "{ %get_season_url(collection_season_1_url, 1) }"
- "{ %get_season_url(collection_season_1_url, 2) }"
- "{ %get_season_url(collection_season_1_url, 3) }"
- "{ %get_season_url(collection_season_1_url, 4) }"
- "{ %get_season_url(collection_season_1_url, 5) }"
- "{ %get_season_url(collection_season_1_url, 6) }"
- "{ %get_season_url(collection_season_1_url, 7) }"
- "{ %get_season_url(collection_season_1_url, 8) }"
- "{ %get_season_url(collection_season_1_url, 9) }"
- "{ %get_season_url(collection_season_1_url, 10) }"
variables:
collection_season_number: "1"
collection_season_name: "{collection_season_1_name}"
@ -190,46 +164,17 @@ presets:
playlist_thumbnails:
- name: "{season_poster_file_name}"
uid: "latest_entry"
- url: "{ %get_season_url(collection_season_2_url, 1) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 2) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 3) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 4) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 5) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 6) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 7) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 8) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 9) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url: "{ %get_season_url(collection_season_2_url, 10) }"
variables:
collection_season_number: "2"
collection_season_name: "{collection_season_2_name}"
- url:
- "{ %get_season_url(collection_season_2_url, 1) }"
- "{ %get_season_url(collection_season_2_url, 2) }"
- "{ %get_season_url(collection_season_2_url, 3) }"
- "{ %get_season_url(collection_season_2_url, 4) }"
- "{ %get_season_url(collection_season_2_url, 5) }"
- "{ %get_season_url(collection_season_2_url, 6) }"
- "{ %get_season_url(collection_season_2_url, 7) }"
- "{ %get_season_url(collection_season_2_url, 8) }"
- "{ %get_season_url(collection_season_2_url, 9) }"
- "{ %get_season_url(collection_season_2_url, 10) }"
- url: "{ %get_season_url(collection_season_3_url, 0) }"
variables:
@ -238,43 +183,17 @@ presets:
playlist_thumbnails:
- name: "{season_poster_file_name}"
uid: "latest_entry"
- url: "{ %get_season_url(collection_season_3_url, 1) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 2) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 3) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 4) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 5) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 6) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 7) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 8) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 9) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"
- url: "{ %get_season_url(collection_season_3_url, 10) }"
- url:
- "{ %get_season_url(collection_season_3_url, 1) }"
- "{ %get_season_url(collection_season_3_url, 2) }"
- "{ %get_season_url(collection_season_3_url, 3) }"
- "{ %get_season_url(collection_season_3_url, 4) }"
- "{ %get_season_url(collection_season_3_url, 5) }"
- "{ %get_season_url(collection_season_3_url, 6) }"
- "{ %get_season_url(collection_season_3_url, 7) }"
- "{ %get_season_url(collection_season_3_url, 8) }"
- "{ %get_season_url(collection_season_3_url, 9) }"
- "{ %get_season_url(collection_season_3_url, 10) }"
variables:
collection_season_number: "3"
collection_season_name: "{collection_season_3_name}"

View file

@ -162,6 +162,10 @@ class ListFormatterValidator(ListValidator[StringFormatterValidator]):
_inner_list_type = StringFormatterValidator
class OverridesListFormatterValidator(ListValidator[OverridesStringFormatterValidator]):
_inner_list_type = OverridesStringFormatterValidator
class DictFormatterValidator(LiteralDictValidator):
"""
A dict made up of