Fix for Playlist Extraction Issue with YouTube Shorts
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
- Call the
get_videosfunction with a playlist URL that contains only YouTube Shorts. - Use
playlistVideoRendereras the renderer parameter. - 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