[maybe] native array url support
This commit is contained in:
parent
1abe2a44f5
commit
e874b7bddb
4 changed files with 163 additions and 1007 deletions
|
|
@ -52,12 +52,12 @@ class UrlDownloaderBasePluginExtension(SourcePluginExtension[MultiUrlValidator])
|
|||
|
||||
if 0 <= input_url_idx < len(self.plugin_options.urls.list):
|
||||
validator = self.plugin_options.urls.list[input_url_idx]
|
||||
if self.overrides.apply_formatter(validator.url) == entry_input_url:
|
||||
if entry_input_url in self.overrides.apply_overrides_formatter_to_native(validator.url):
|
||||
return validator
|
||||
|
||||
# Match the first validator based on the URL, if one exists
|
||||
for validator in self.plugin_options.urls.list:
|
||||
if self.overrides.apply_formatter(validator.url) == entry_input_url:
|
||||
if entry_input_url in self.overrides.apply_overrides_formatter_to_native(validator.url):
|
||||
return validator
|
||||
|
||||
# Return the first validator if none exist
|
||||
|
|
@ -487,19 +487,27 @@ class MultiUrlDownloader(SourcePlugin[MultiUrlValidator]):
|
|||
# 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)):
|
||||
if not (urls := self.overrides.apply_overrides_formatter_to_native(url_validator.url)):
|
||||
continue
|
||||
|
||||
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),
|
||||
}
|
||||
)
|
||||
assert isinstance(urls, list)
|
||||
|
||||
yield entry
|
||||
for url in reversed(urls):
|
||||
assert isinstance(url, str)
|
||||
|
||||
if not url:
|
||||
continue
|
||||
|
||||
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),
|
||||
}
|
||||
)
|
||||
|
||||
yield entry
|
||||
|
||||
def download(self, entry: Entry) -> Optional[Entry]:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -43,6 +43,20 @@ class UrlThumbnailListValidator(ListValidator[UrlThumbnailValidator]):
|
|||
_inner_list_type = UrlThumbnailValidator
|
||||
|
||||
|
||||
class OverridesOneOrManyUrlValidator(OverridesStringFormatterValidator):
|
||||
def post_process_native(self, resolved: Any) -> Any:
|
||||
if isinstance(resolved, str):
|
||||
return [resolved]
|
||||
if isinstance(resolved, list):
|
||||
for value in resolved:
|
||||
if not isinstance(value, str):
|
||||
raise self._validation_exception("Must be a string or an array of strings.")
|
||||
return resolved
|
||||
|
||||
raise self._validation_exception("Must be a string or an array of strings.")
|
||||
|
||||
|
||||
|
||||
class UrlValidator(StrictDictValidator):
|
||||
_required_keys = {"url"}
|
||||
_optional_keys = {
|
||||
|
|
@ -68,7 +82,7 @@ class UrlValidator(StrictDictValidator):
|
|||
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=OverridesOneOrManyUrlValidator)
|
||||
self._variables = self._validate_key_if_present(
|
||||
key="variables", validator=DictFormatterValidator, default={}
|
||||
)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import Dict
|
||||
from typing import Dict, Any
|
||||
from typing import Set
|
||||
from typing import Union
|
||||
from typing import final
|
||||
|
|
@ -89,6 +89,14 @@ class StringFormatterValidator(StringValidator):
|
|||
"""
|
||||
return resolved
|
||||
|
||||
def post_process_native(self, resolved: Any) -> Any:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
Apply any post processing to the resolved native value.
|
||||
"""
|
||||
return resolved
|
||||
|
||||
|
||||
class FloatFormatterValidator(StringFormatterValidator):
|
||||
_expected_value_type_name = "float"
|
||||
|
|
|
|||
Loading…
Reference in a new issue