[BUGFIX] Fix source metadata getting fetched when yt-dlp breaks
This commit is contained in:
parent
be0f6f2d2d
commit
1ffbb814e8
1 changed files with 24 additions and 18 deletions
|
|
@ -216,15 +216,12 @@ class YTDLP:
|
||||||
**kwargs
|
**kwargs
|
||||||
arguments passed directory to YoutubeDL extract_info
|
arguments passed directory to YoutubeDL extract_info
|
||||||
"""
|
"""
|
||||||
parent_dict: Dict = {}
|
|
||||||
try:
|
try:
|
||||||
with cls._listen_and_log_downloaded_info_json(
|
with cls._listen_and_log_downloaded_info_json(
|
||||||
working_directory=working_directory, log_prefix=log_prefix_on_info_json_dl
|
working_directory=working_directory, log_prefix=log_prefix_on_info_json_dl
|
||||||
):
|
):
|
||||||
# TODO: Fetch parent_dict if it breaks
|
# TODO: Fetch parent_dict if it breaks
|
||||||
parent_dict = cls.extract_info(
|
cls.extract_info(ytdl_options_overrides=ytdl_options_overrides, **kwargs)
|
||||||
ytdl_options_overrides=ytdl_options_overrides, **kwargs
|
|
||||||
)
|
|
||||||
except RejectedVideoReached:
|
except RejectedVideoReached:
|
||||||
cls.logger.debug(
|
cls.logger.debug(
|
||||||
"RejectedVideoReached, stopping additional downloads "
|
"RejectedVideoReached, stopping additional downloads "
|
||||||
|
|
@ -238,23 +235,32 @@ class YTDLP:
|
||||||
except MaxDownloadsReached:
|
except MaxDownloadsReached:
|
||||||
cls.logger.info("MaxDownloadsReached, stopping additional downloads.")
|
cls.logger.info("MaxDownloadsReached, stopping additional downloads.")
|
||||||
|
|
||||||
# For YouTube playlists in particular, channel metadata is not fetched. Attempt to get
|
parent_dicts: List[Dict] = []
|
||||||
# channel metadata via grabbing uploader_url info json a max of 3 times
|
entry_dicts = cls._get_entry_dicts_from_info_json_files(working_directory=working_directory)
|
||||||
if isinstance(parent_dict, dict):
|
entry_ids = {entry_dict.get("id") for entry_dict in entry_dicts}
|
||||||
current_iter = 0
|
|
||||||
url = kwargs.get("url")
|
# Try to get additional uploader (source) metadata that yt-dlp does not fetch
|
||||||
uploader_url = parent_dict.get("uploader_url")
|
# in a single request
|
||||||
while current_iter < 3 and uploader_url and url != uploader_url:
|
for entry_dict in entry_dicts:
|
||||||
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
|
if not (uploader_id := entry_dict.get("uploader_id")):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if uploader_id in entry_ids or not (uploader_url := entry_dict.get("uploader_url")):
|
||||||
|
continue
|
||||||
|
|
||||||
|
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
|
||||||
|
try:
|
||||||
parent_dict = cls.extract_info(
|
parent_dict = cls.extract_info(
|
||||||
ytdl_options_overrides=ytdl_options_overrides | {"playlist_items": "0:0"},
|
ytdl_options_overrides=ytdl_options_overrides | {"playlist_items": "0:0"},
|
||||||
url=uploader_url,
|
url=uploader_url,
|
||||||
)
|
)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
# Do not try this uploader_id again
|
||||||
|
entry_ids.add(uploader_id)
|
||||||
|
break
|
||||||
|
|
||||||
if not isinstance(parent_dict, dict):
|
if isinstance(parent_dict, dict):
|
||||||
break
|
parent_dicts.append(parent_dict)
|
||||||
current_iter += 1
|
entry_ids |= {uploader_id, parent_dict.get("id")}
|
||||||
url = uploader_url
|
|
||||||
uploader_url = parent_dict.get("uploader_url")
|
|
||||||
|
|
||||||
return cls._get_entry_dicts_from_info_json_files(working_directory=working_directory)
|
return entry_dicts + parent_dicts
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue