Skip to content

Instantly share code, notes, and snippets.

@sammachin
Last active September 14, 2018 11:11
Show Gist options
  • Save sammachin/54f7bfd774b857e839e6637154c7bd56 to your computer and use it in GitHub Desktop.
Save sammachin/54f7bfd774b857e839e6637154c7bd56 to your computer and use it in GitHub Desktop.
Short script to print all the titles in a YouTube Playlist
import requests
playlist = "XXXXXXX" #Playlist ID from URL eg https://www.youtube.com/playlist?list=PL1Hr6VkuONaE4XM52ThiV-s3vXAUT0JCR
key = "XXXXXXXX" # Your YouTube API Key from https://console.developers.google.com/apis/credentials
params = {"part" : "snippet", "maxResults" : 50, "playlistId": playlist, "key" : key}
url = "https://www.googleapis.com/youtube/v3/playlistItems"
items = []
r = requests.get(url, params=params)
rdata=r.json()
items.extend(rdata['items'])
while 'nextPageToken' in rdata:
params['pageToken'] = rdata['nextPageToken']
r = requests.get(url, params=params)
rdata=r.json()
items.extend(rdata['items'])
for i in items:
print(i['snippet']['title'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment