Created
August 22, 2018 12:49
-
-
Save khuangaf/66a8cafc6b7675183944e793e0ebeca6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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