[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"""
|
"""Returns an internal kwarg value supplied from ytdl"""
|
||||||
if not self.kwargs_contains(key):
|
if not self.kwargs_contains(key):
|
||||||
raise KeyError(f"Expected '{key}' in {self.__class__.__name__} but does not exist.")
|
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:
|
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.
|
pulled via yt-dlp. Use with caution.
|
||||||
"""
|
"""
|
||||||
# Try to get the track, fall back on title
|
# Try to get the track, fall back on title
|
||||||
if self.kwargs_contains("track"):
|
return self.kwargs_get("track", super().title)
|
||||||
return self.kwargs("track")
|
|
||||||
|
|
||||||
return super().title
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def track_title_sanitized(self) -> str:
|
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
|
NOTE: Even if a video has music metadata, this variable does not always get pulled via
|
||||||
yt-dlp. Use with caution.
|
yt-dlp. Use with caution.
|
||||||
"""
|
"""
|
||||||
if self.kwargs_contains("artist"):
|
return self.kwargs_get("artist", self.kwargs("channel"))
|
||||||
return self.kwargs("artist")
|
|
||||||
|
|
||||||
return self.kwargs("channel")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def artist_sanitized(self) -> str:
|
def artist_sanitized(self) -> str:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ def extractor():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def title():
|
def title():
|
||||||
return "entry title"
|
return "entry {title}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -61,8 +61,8 @@ def mock_entry_to_dict(
|
||||||
):
|
):
|
||||||
return {
|
return {
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
"title": title,
|
"title": "entry {title}",
|
||||||
"title_sanitized": title,
|
"title_sanitized": "entry {title}",
|
||||||
"ext": ext,
|
"ext": ext,
|
||||||
"extractor": extractor,
|
"extractor": extractor,
|
||||||
"upload_date": upload_date,
|
"upload_date": upload_date,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue