[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,12 +485,15 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
def download_metadata(self) -> Iterable[Entry]: def download_metadata(self) -> Iterable[Entry]:
"""The function to perform the download of all media entries""" """The function to perform the download of all media entries"""
# download the bottom-most urls first since they are top-priority # download the bottom-most urls first since they are top-priority
for idx, url_validator in reversed(list(enumerate(self.collection.urls.list))): 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):
# URLs can be empty. If they are, then skip # URLs can be empty. If they are, then skip
if not (url := self.overrides.apply_formatter(url_validator.url)): if not (url := self.overrides.apply_formatter(url_validator)):
continue continue
for entry in self._download_metadata(url=url, validator=url_validator): for entry in self._download_metadata(url=url, validator=validator):
entry.initialize_script(self.overrides).add( entry.initialize_script(self.overrides).add(
{ {
v.ytdl_sub_input_url: url, v.ytdl_sub_input_url: url,

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

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