Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Created August 22, 2018 12:49
Show Gist options
  • Save khuangaf/66a8cafc6b7675183944e793e0ebeca6 to your computer and use it in GitHub Desktop.
Save khuangaf/66a8cafc6b7675183944e793e0ebeca6 to your computer and use it in GitHub Desktop.
def get_video_ids(playlist_id):
"""
Get the video ids given a playlist id.
Parameters
----------
playlist_id : str
A Youtube playlist id. (up to 50 results)
Returns
-------
video_ids: list(str)
The video ids associated with the input playlist
"""
#search for all the videos given a playlist id
search_response = youtube.playlistItems().list(part='contentDetails',maxResults=50,playlistId=playlist_id).execute()
all_videos = search_response['items']
video_ids = []
for vid in all_videos:
video_id = vid['contentDetails']['videoId']
video_ids.append(video_id)
return video_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment