This commit is contained in:
Jesse Bannon 2023-07-25 14:09:15 -07:00
parent 73411726f5
commit 2c858ffadb
2 changed files with 10 additions and 34 deletions

View file

@ -1,9 +1,7 @@
from typing import Dict
from typing import List
from ytdl_sub.downloaders.url.validators import MultiUrlValidator
# TODO: Remove later - keep for docstring
class MultiUrlDownloadOptions(MultiUrlValidator):
"""
Downloads from multiple URLs. If an entry is returned from more than one URL, it will
@ -38,25 +36,3 @@ class MultiUrlDownloadOptions(MultiUrlValidator):
- name: "season{season_index}-poster.jpg"
uid: "latest_entry"
"""
@property
def collection_validator(self) -> MultiUrlValidator:
"""Returns itself!"""
return self
def validate_with_variables(
self, source_variables: List[str], override_variables: Dict[str, str]
) -> None:
"""
Validates any source variables added by the collection
"""
super().validate_with_variables(
source_variables=source_variables, override_variables=override_variables
)
has_non_empty_url = False
for url_validator in self.urls.list:
has_non_empty_url |= bool(url_validator.url.apply_formatter(override_variables))
if not has_non_empty_url:
raise self._validation_exception("Must contain at least one url that is non-empty")

View file

@ -179,6 +179,15 @@ class MultiUrlValidator(OptionsValidator):
resolve to the bottom-most URL settings.
"""
@classmethod
def partial_validate(cls, name: str, value: Any) -> None:
"""
Partially validate a collection
"""
if isinstance(value, dict):
value["urls"] = value.get("urls", [{"url": "placeholder"}])
_ = cls(name, value)
def __init__(self, name, value):
super().__init__(name, value)
@ -198,15 +207,6 @@ class MultiUrlValidator(OptionsValidator):
name=name, value=UrlValidator(name=name, value=value_copy)
)
@classmethod
def partial_validate(cls, name: str, value: Any) -> None:
"""
Partially validate a collection
"""
if isinstance(value, dict):
value["urls"] = value.get("urls", [{"url": "placeholder"}])
_ = cls(name, value)
@property
def urls(self) -> UrlListValidator:
"""