Last active
September 14, 2018 11:11
-
-
Save sammachin/54f7bfd774b857e839e6637154c7bd56 to your computer and use it in GitHub Desktop.
Short script to print all the titles in a YouTube Playlist
This file contains 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
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