Created
May 13, 2019 13:21
-
-
Save masyanru/147ac05bb7cc733ce0637d83356f0530 to your computer and use it in GitHub Desktop.
get list of videos from youtube channel
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
api_key = "###############" | |
from apiclient.discovery import build | |
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('UCsMica-v34Irf9KVTh6xx-g') | |
for video in videos: | |
print(video['snippet']['title'] + ' | ' + 'https://www.youtube.com/watch?v=' + video['snippet']['resourceId']['videoId']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment