Python 3 Script to Get All Videos From Channel ID or Username Using Youtube Data API V3 Full Project For Beginners

 

 

main.py

 

 

import urllib.request
import json

def get_all_video_in_channel(channel_id):
    api_key = ""

    base_video_url = 'https://www.youtube.com/watch?v='
    base_search_url = 'https://www.googleapis.com/youtube/v3/search?'

    first_url = base_search_url+'key={}&channelId={}&part=snippet,id&order=date&maxResults=25'.format(api_key, channel_id)

    video_links = []
    url = first_url
    while True:
        inp = urllib.request.urlopen(url)
        resp = json.load(inp)

        for i in resp['items']:
            if i['id']['kind'] == "youtube#video":
                video_links.append(base_video_url + i['id']['videoId'])

        try:
            next_page_token = resp['nextPageToken']
            url = first_url + '&pageToken={}'.format(next_page_token)
        except:
            break
    return video_links

print(get_all_video_in_channel("UCA1Ew_1Z424uA0zxiejdczg"))

Leave a Reply