Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Created August 22, 2018 12:44
Show Gist options
  • Save khuangaf/a5b4655f69b686aaeadaabcea7b478e1 to your computer and use it in GitHub Desktop.
Save khuangaf/a5b4655f69b686aaeadaabcea7b478e1 to your computer and use it in GitHub Desktop.
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