Created
August 22, 2018 12:44
-
-
Save khuangaf/a5b4655f69b686aaeadaabcea7b478e1 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
from googleapiclient.discovery import build | |
# developer keys for Youtube V3 API | |
DEVELOPER_KEY = 'YOUR_API_KEY' | |
YOUTUBE_API_SERVICE_NAME = "youtube" | |
YOUTUBE_API_VERSION = "v3" | |
# creating youtube resource object for interacting with api | |
youtube = build(YOUTUBE_API_SERVICE_NAME, | |
YOUTUBE_API_VERSION, | |
developerKey=DEVELOPER_KEY) | |
def get_playlist_id(name): | |
""" | |
Search for the playlist id given a drama name. | |
Parameters | |
---------- | |
name : str | |
The name of the drama | |
Returns | |
------- | |
playlist_id: str | |
Resulted playlist id returned by Youtube API | |
""" | |
#search for the first playlist result given a drama name | |
search_response = youtube.search().list(q=name,type="playlist",part="id",maxResults=1).execute() | |
result = search_response.get("items", []) | |
playlist_id = result[0]['id']['playlistId'] | |
return playlist_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment