do not double-add channel

This commit is contained in:
Jesse Bannon 2024-01-18 15:23:43 -08:00
parent 8ddc0be73e
commit bfd6d459f3
2 changed files with 20 additions and 14 deletions

View file

@ -248,20 +248,22 @@ class YTDLP:
continue
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
parent_dict: Dict = {}
try:
parent_dict = cls.extract_info(
ytdl_options_overrides=ytdl_options_overrides | {"playlist_items": "0:0"},
url=uploader_url,
)
except Exception: # pylint: disable=broad-except
# Do not try this uploader_id again
entry_ids.add(uploader_id)
break
pass
if isinstance(parent_dict, dict):
parent_id = parent_dict.get("id")
parent_id = parent_dict.get("id")
if parent_id and parent_id not in entry_ids:
parent_dicts.append(parent_dict)
entry_ids |= {uploader_id, parent_id}
entry_ids.add(parent_id)
cls.logger.debug("Adding parent metadata with ids [%s, %s]", uploader_id, parent_id)
# Always add the uploader_id since it has been tried
entry_ids.add(uploader_id)
return entry_dicts + parent_dicts

View file

@ -157,10 +157,6 @@ class EntryParent(BaseEntry):
def _uid_is_uploader_id(parent: "EntryParent"):
return parent.uid == parent.uploader_id
# Channels can have two of the same .info.json. Handle it here
if len(parents) == 2 and parents[0].uploader_id == parents[1].uploader_id:
return parents[0] if not parents[0].webpage_url.endswith("/videos") else parents[1]
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
@ -172,10 +168,18 @@ class EntryParent(BaseEntry):
if len(top_level_parents) > 1:
top_level_parents = [parent for parent in top_level_parents if _url_matches(parent)]
if not top_level_parents:
return None
if len(top_level_parents) == 1:
return top_level_parents[0]
match len(top_level_parents):
case 0:
return None
case 1:
return top_level_parents[0]
case 2:
# Channels can have two of the same .info.json. Handle it here
top0 = top_level_parents[0]
top1 = top_level_parents[1]
if top0.uploader_id == top1.uploader_id:
return top0 if not top0.webpage_url.endswith("/videos") else top1
raise ValueError(
"Detected multiple top-level parents. "
"Please file an issue on GitHub with the URLs used to produce this error"