pythonyoutubeyoutube-dltermuxyt-dlp

How to make a excel or a file containing title & thumbnail if possible of videos of a YouTube playlist?


Is it possible to make a list of title and thumbnail of videos of playlist? Then we can try to run macros or cronjob to automate it in regular basis.

So I'm a newbie here. I've found out today that more than 25 of my fav videos are gone from YouTube playlist which is irrecoverable as far as I know by now. Anyways that brings me an idea to try to make or perhaps if already exists such program, then trying to find out. Is it possible to make a list of title and thumbnail of videos of playlist? Then we can try to run macros or cronjob to automate it in regular basis. I know that it's possible to get title list from yt-dlp but how can I integrate thumbnail to the list? Or are there such site/program exist already? Any help is very much appreciated. For the information, I'm basically on Android.....so any python/ html/site/android app solution Will be very much helpful in this regard.


Solution

  • You are looking for YouTube Data API v3 PlaylistItems: list endpoint. You can use it the following way in Python:

    import requests, json, csv
    
    API_KEY = 'AIzaSy...'
    PLAYLIST_ID = 'YOUR_PLAYLIST_ID'
    
    with open('playlist.csv', 'w') as csvFile:
        csvWriter = csv.writer(csvFile)
        csvWriter.writerow(['videoId', 'title', 'thumbnails'])
    
        pageToken = ''
        while True:
            url = f'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&playlistId={PLAYLIST_ID}&maxResults=50&pageToken={pageToken}&key={API_KEY}'
            content = requests.get(url).text
            data = json.loads(content)
            for item in data['items']:
                print(json.dumps(item, indent=4))
                snippet = item['snippet']
                csvWriter.writerow([snippet['resourceId']['videoId'], snippet['title'], snippet['thumbnails']])
            if 'nextPageToken' in data:
                pageToken = data['nextPageToken']
            else:
                break