← All field notes
CTO notes 2 min read

Python script that uses the YouTube API to retrieve the titles, descriptions, and URLs of all the videos in a given YouTube channel

Here is an example python script that uses the YouTube API to retrieve the titles, descriptions, and URLs of all the videos in a given YouTube channel: Remember to replace […]

Here is an example python script that uses the YouTube API to retrieve the titles, descriptions, and URLs of all the videos in a given YouTube channel:

import requests
import json
import csv

def get_channel_info(channel_id, api_key):
    # Make an API call to retrieve channel information
    url = "https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet&order=date&maxResults=50".format(api_key, channel_id)
    response = requests.get(url)
    data = json.loads(response.text)
    
    # Extract the relevant information from the API response
    videos = []
    for item in data["items"]:
        if item['id']['kind'] == 'youtube#video':
            video = {}
            video["title"] = item["snippet"]["title"]
            video["description"] = item["snippet"]["description"]
            video["url"] = "https://www.youtube.com/watch?v={}".format(item['id']['videoId'])
            videos.append(video)
    
    return videos

if __name__ == "__main__":
    # Replace channel_id and api_key with your own values
    channel_id = "YOUR_CHANNEL_ID"
    api_key = "YOUR_API_KEY"
    videos = get_channel_info(channel_id, api_key)

    # Write the results to a CSV file
    with open("videos.csv", "w", newline="") as csvfile:
        fieldnames = ["title", "description", "url"]
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()
        for video in videos:
            writer.writerow(video)

Remember to replace YOUR_CHANNEL_ID and YOUR_API_KEY with your own YouTube channel ID and API key, respectively.

AS

Written by Alan Son

CTO judgment, grounded in delivery.

I build commercial AI products and help founders turn ambitious technical ideas into reliable production systems.

More about my work

Need an experienced technical partner?

Let’s work out the right next move.