Skip to content

Commit

Permalink
Fix Youtube channel with tabs
Browse files Browse the repository at this point in the history
Youtube channel can enable additional features (eg. Shorts) which
results in the channel having corresponding tabs.
Updating such a channel was broken as the object returned by
YoutubeDL.extract_info will contains a "sub playlist".
Fix the issue by checking if we have sub playlists and finding the one
that is used for videos.

Note: this means we don't support any types other than Videos for now.

Fixes woefe#113
  • Loading branch information
chemicalstorm committed Aug 19, 2023
1 parent 8893bc9 commit d46c3be
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ytcc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ async def get_unprocessed_entries(
)
else:
entries = info.get("entries", [])
# 2 options:
# - Some channels will directly list videos in the
# `entries` field
# - Other channels will have tabs (Videos, Stream, Lives)
# that are represented as sub-playlists in the `entries` field
# Note: This is mostly to support channels that enables that
# option without having the user to update the subscription.
if info.get("webpage_url_basename") not in ["videos",
"playlist"]:
logger.debug("Playlist has sub-playlists")
# Entries is a list of info objects for Videos and
# Livestreams
tab_entries = entries
entries = []
for tab in tab_entries:
# Try to find the "videos" tab
# No webpage_url_basename field here :|
# So we need to check that URL ends with /videos
if tab.get("webpage_url").endswith("/videos"):
entries = tab.get("entries", [])
break
if playlist.reverse:
entries = reversed(list(entries))
for entry in take(self.max_items, entries):
Expand Down

0 comments on commit d46c3be

Please sign in to comment.