We are trying to get all videos in a channel, like this. This list has 291k videos, we figured out the channel id of this channel (and replaced the second alphabet "C" in the id by "U"), and trying this code, iterating over 50 videos at a time. We are getting only upto some 20k videos, not more than that. Any idea on how to fix this and get all 291k videos in this channel? Checked this for a variety of channels with large number of videos, all have the same problem.
api_key = "my Google YouTube API V3 key"
from googleapiclient.discovery import build
youtube = build('youtube', 'v3', developerKey=api_key)
def get_channel_videos():
videos = []
next_page_token = None
while 1:
res = youtube.playlistItems().list(playlistId="UU...",
part='snippet',
maxResults=50,
pageToken=next_page_token).execute()
videos += res['items']
next_page_token = res.get('nextPageToken')
if next_page_token is None:
break
return videos
videos = get_channel_videos()
with open("video.txt", "a") as myfile:
for video in videos:
myfile.write(f"{video['snippet']['resourceId']['videoId']} => {video['snippet']['title']}\n")
print(f"Total video count => {len(videos)}")
I investigated many different approaches and the only one which seems to perfectly work is the following one based on web-scraping the
Videostab of the specified channel:While @MLB
Aboutclaims291,597 videos, my method finds289,814unique videos. It is unknown where the count difference comes from, possibly fromLives and unlisted videos.