Reputation: 742
I would like to know if there's a way to get the number of total videos in a playlist.
I'm building a Python script that need to get the number of videos to do a for loop. Or, if getting this information isn't possible, can you give me a way to do it without a for loop?
Upvotes: 2
Views: 5445
Reputation: 641
Here's another way, using Python and not constructing a URL string from scratch:
With the Python API for listing out playlistItems (assuming you're looking for publicly available playlists only), you build a resource object to interact with the API, and then query the result for your playlistId of choice:
client = build('youtube', 'v3', developerKey=<your_api_key>)
res = client.playlistItems().list(playlistId=<your_playlist_id>, part='snippet').execute()
length_of_playlist = res['pageInfo']['totalResults']
Upvotes: 1
Reputation: 8870
You can use the following request
https://www.googleapis.com/youtube/v3/playlistItems?part=id&maxResults=0&playlistId={PLAYLIST_ID}&key={YOUR_API_KEY}
Look for 'totalResults' in the response, which will give you a total number of videos in the playlist
Upvotes: 9