Skip to content

Instantly share code, notes, and snippets.

@MateoWartelle
Last active January 25, 2020 20:56
Show Gist options
  • Save MateoWartelle/72fd8596200137377501bac47f79f59c to your computer and use it in GitHub Desktop.
Save MateoWartelle/72fd8596200137377501bac47f79f59c to your computer and use it in GitHub Desktop.
api_key = "YOUR API KEY"
from apiclient.discovery import build
import csv
youtube = build('youtube', 'v3', developerKey=api_key)
def get_channel_videos(channel_id):
res = youtube.channels().list(id=channel_id,
part='contentDetails').execute()
playlist_id = res['items'][0]['contentDetails']['relatedPlaylists']['uploads']
videos = []
next_page_token = None
while 1:
res = youtube.playlistItems().list(playlistId=playlist_id,
part='snippet',
maxResults=50,
pageToken=next_page_token).execute()
videos += res['items']
next_page_token = res.get('nextPageToken')
if next_page_token is None:
break
return videos
videos = get_channel_videos('YOUR CHANNEL ID')
print(len(videos))
with open('VIDEOURLS.csv', 'w', newline='') as file:
writer = csv.writer(file)
for video in videos:
writer.writerow([video['snippet']['resourceId']['videoId'], video['snippet']['title'], video['snippet']['publishedAt']])
print('done boss')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment