Skip to content

Fix for Playlist Extraction Issue with YouTube ShortsΒ #63

@ndyanx

Description

@ndyanx

Issue Description

When attempting to extract videos from a YouTube playlist that contains only Shorts(example: https://www.youtube.com/playlist?list=PLxPmekEwS6-bF6AWu3prP2iRltY6Oslrw) using the get_videos function with the playlistVideoRenderer parameter, the function fails to capture any videos. This issue does not occur with playlists containing regular videos or a mix of videos and Shorts.

Steps to Reproduce

  1. Call the get_videos function with a playlist URL that contains only YouTube Shorts.
  2. Use playlistVideoRenderer as the renderer parameter.
  3. Iterate over the generator to yield videos.

Expected Behavior

The function should capture and yield videos from the playlist, regardless of whether they are Shorts or regular videos.

Actual Behavior

No videos are captured or yielded when the playlist consists solely of Shorts.

Solution

A conditional check was implemented to solve this issue. If no videos are captured with playlistVideoRenderer, the function will attempt to use reelItemRenderer instead. Here is the updated code snippet that addresses the problem:

videos = get_videos(url, api_endpoint, "playlistVideoRenderer", limit, sleep)
if not any(videos):  # Check if the generator is empty
    videos = get_videos(url, api_endpoint, "reelItemRenderer", limit, sleep)
for video in videos:
    yield video

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions