scrapetube icon indicating copy to clipboard operation
scrapetube copied to clipboard

Fix for Playlist Extraction Issue with YouTube Shorts

Open ndyanx opened this issue 1 year ago • 0 comments

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

ndyanx avatar May 08 '24 20:05 ndyanx