do not double-add channel
This commit is contained in:
parent
8ddc0be73e
commit
bfd6d459f3
2 changed files with 20 additions and 14 deletions
|
|
@ -248,20 +248,22 @@ class YTDLP:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
|
cls.logger.debug("Attempting to get parent metadata from URL %s", uploader_url)
|
||||||
|
parent_dict: Dict = {}
|
||||||
try:
|
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
|
except Exception: # pylint: disable=broad-except
|
||||||
# Do not try this uploader_id again
|
pass
|
||||||
entry_ids.add(uploader_id)
|
|
||||||
break
|
|
||||||
|
|
||||||
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)
|
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)
|
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
|
return entry_dicts + parent_dicts
|
||||||
|
|
|
||||||
|
|
@ -157,10 +157,6 @@ class EntryParent(BaseEntry):
|
||||||
def _uid_is_uploader_id(parent: "EntryParent"):
|
def _uid_is_uploader_id(parent: "EntryParent"):
|
||||||
return parent.uid == parent.uploader_id
|
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]
|
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 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:
|
if len(top_level_parents) > 1:
|
||||||
top_level_parents = [parent for parent in top_level_parents if _url_matches(parent)]
|
top_level_parents = [parent for parent in top_level_parents if _url_matches(parent)]
|
||||||
|
|
||||||
if not top_level_parents:
|
match len(top_level_parents):
|
||||||
return None
|
case 0:
|
||||||
if len(top_level_parents) == 1:
|
return None
|
||||||
return top_level_parents[0]
|
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(
|
raise ValueError(
|
||||||
"Detected multiple top-level parents. "
|
"Detected multiple top-level parents. "
|
||||||
"Please file an issue on GitHub with the URLs used to produce this error"
|
"Please file an issue on GitHub with the URLs used to produce this error"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue