[BUGFIX] Fix source vars containing variable-like syntax (#231)
This commit is contained in:
parent
c9f0300b39
commit
c33eed5a64
3 changed files with 11 additions and 12 deletions
|
|
@ -115,7 +115,12 @@ class BaseEntry(BaseEntryVariables, ABC):
|
|||
"""Returns an internal kwarg value supplied from ytdl"""
|
||||
if not self.kwargs_contains(key):
|
||||
raise KeyError(f"Expected '{key}' in {self.__class__.__name__} but does not exist.")
|
||||
return self._kwargs[key]
|
||||
output = self._kwargs[key]
|
||||
|
||||
# Replace curly braces with unicode version to avoid variable shenanigans
|
||||
if isinstance(output, str):
|
||||
return output.replace("{", "{").replace("}", "}")
|
||||
return output
|
||||
|
||||
def kwargs_get(self, key: str, default: Optional[Any] = None) -> Any:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -39,10 +39,7 @@ class YoutubeVideoVariables(EntryVariables):
|
|||
pulled via yt-dlp. Use with caution.
|
||||
"""
|
||||
# Try to get the track, fall back on title
|
||||
if self.kwargs_contains("track"):
|
||||
return self.kwargs("track")
|
||||
|
||||
return super().title
|
||||
return self.kwargs_get("track", super().title)
|
||||
|
||||
@property
|
||||
def track_title_sanitized(self) -> str:
|
||||
|
|
@ -64,10 +61,7 @@ class YoutubeVideoVariables(EntryVariables):
|
|||
NOTE: Even if a video has music metadata, this variable does not always get pulled via
|
||||
yt-dlp. Use with caution.
|
||||
"""
|
||||
if self.kwargs_contains("artist"):
|
||||
return self.kwargs("artist")
|
||||
|
||||
return self.kwargs("channel")
|
||||
return self.kwargs_get("artist", self.kwargs("channel"))
|
||||
|
||||
@property
|
||||
def artist_sanitized(self) -> str:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ def extractor():
|
|||
|
||||
@pytest.fixture
|
||||
def title():
|
||||
return "entry title"
|
||||
return "entry {title}"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -61,8 +61,8 @@ def mock_entry_to_dict(
|
|||
):
|
||||
return {
|
||||
"uid": uid,
|
||||
"title": title,
|
||||
"title_sanitized": title,
|
||||
"title": "entry {title}",
|
||||
"title_sanitized": "entry {title}",
|
||||
"ext": ext,
|
||||
"extractor": extractor,
|
||||
"upload_date": upload_date,
|
||||
|
|
|
|||
Loading…
Reference in a new issue