[BUGFIX] Fix source vars containing variable-like syntax (#231)

This commit is contained in:
Jesse Bannon 2022-09-14 08:36:56 -07:00 committed by GitHub
parent c9f0300b39
commit c33eed5a64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View file

@ -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:
"""

View file

@ -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:

View file

@ -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,