The easiest way to get all the videos,
DEVELOPER_KEY = "REPLACE_ME" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3"
youtube = build("youtube", "v3", developerKey=api_key)
def get_videos_from_playlist(youtube, items, playlistID):
response = items.list(part="snippet", playlistId=playlistID)
while response:
playlistitems_list_response = response.execute()
for playlist_item in playlistitems_list_response["items"]:
# title = playlist_item["snippet"]["title"]
video_id = playlist_item["snippet"]["resourceId"]["videoId"]
yield video_id
response = youtube.playlistItems().list_next(
response, playlistitems_list_response)
Pass the playlist id,
items = youtube.playlistItems()
playlist = get_videos_from_playlist(youtube, items, 'PLoROMvodv4rOhcuXMZkNm7j3fVwBBY42z')
and then parse through the list:
for videoID in playlist:
print(videoID)
additionally, you can use pages to scrape through multiple pages use something like:
nextPageToken = res.get('nextPageToken')
while ('nextPageToken' in res):
nextPage = youtube.playlistItems().list(
part="snippet",
playlistId=playlistId,
maxResults="50",
pageToken=nextPageToken
).execute()
res['items'] = res['items'] + nextPage['items']
if 'nextPageToken' not in nextPage:
res.pop('nextPageToken', None)
else:
nextPageToken = nextPage['nextPageToken']