Reputation: 3
I wanna get all videos from playlist with it's url. So, it works, but I have a problem, that youtube removed a way to get videos duration using playlistItems().list(). It used to be in 'contentDetails', but now there are only 'videoId' and 'videoPublishedAt'. We can request every single video using videos().list(), but I'm afraid of the speed of this way… May be, there is a way to avoid using request to every video to get it's duration?
Sorry for my English :) You may write in any language you want.
There is a python code that I'm using for getting videos from playlist:
youtube = build("youtube", "v3", developerKey=API_KEY)
def get_videos(url):
# ........
collected_data = []
next_page_token = None
while True:
request = youtube.playlistItems().list(
part='snippet,contentDetails',
playlistId=playlist_id,
maxResults=50,
pageToken=next_page_token
)
response = request.execute()
collected_data.append(response)
next_page_token = response.get('nextPageToken')
if not next_page_token:
break
return collected_data[0]
Upvotes: 0
Views: 392
Reputation: 5642
Using YouTube Data API v3 Videos: list endpoint it only divides the speed of your algorithm by two by making another request to this endpoint. Indeed it seems that you aren't aware that this endpoint supports up to 50
provided id
s within each request.
Upvotes: 0