[BACKEND] Try to fetch source metadata from uploader_url

This commit is contained in:
Jesse Bannon 2024-01-08 17:18:08 -08:00
parent 961e04d027
commit 1de0c69223
2 changed files with 18 additions and 7 deletions

View file

@ -216,11 +216,14 @@ class YTDLP:
**kwargs
arguments passed directory to YoutubeDL extract_info
"""
parent_dict: Dict = {}
try:
with cls._listen_and_log_downloaded_info_json(
working_directory=working_directory, log_prefix=log_prefix_on_info_json_dl
):
_ = cls.extract_info(ytdl_options_overrides=ytdl_options_overrides, **kwargs)
parent_dict = cls.extract_info(
ytdl_options_overrides=ytdl_options_overrides, **kwargs
)
except RejectedVideoReached:
cls.logger.debug(
"RejectedVideoReached, stopping additional downloads "
@ -234,4 +237,17 @@ class YTDLP:
except MaxDownloadsReached:
cls.logger.info("MaxDownloadsReached, stopping additional downloads.")
# For YouTube playlists in particular, channel metadata is not fetched. Attempt to get
# channel metadata via grabbing uploader_url info json
url = kwargs.get("url")
uploader_url = parent_dict.get("uploader_url")
while uploader_url and url != uploader_url:
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
parent_dict = cls.extract_info(
ytdl_options_overrides=ytdl_options_overrides | {"playlist_items": "0:0"},
url=uploader_url,
)
url = uploader_url
uploader_url = parent_dict.get("uploader_url")
return cls._get_entry_dicts_from_info_json_files(working_directory=working_directory)

View file

@ -151,15 +151,10 @@ class EntryParent(BaseEntry):
Sometimes the root-level parent is disconnected via playlist_ids Find it if it exists.
"""
def _url_matches(parent: "EntryParent"):
return parent.webpage_url in url or url in parent.webpage_url
def _uid_is_uploader_id(parent: "EntryParent"):
return parent.uid == parent.uploader_id
top_level_parents = [
parent for parent in parents if parent.num_children() == 0 and _url_matches(parent)
]
top_level_parents = [parent for parent in parents if parent.num_children() == 0]
# If more than 1 parent exists, assume the uploader_id is the root parent
if len(top_level_parents) > 1: