import json from yt_dlp import YoutubeDL # Replace with your playlist URL playlist_url = "https://www.youtube.com/playlist?list=PLhrdHlkOIj-Xed4qLDAxITQCGEOTVXSfl" # yt-dlp options ydl_opts = { 'quiet': True, # suppress console output 'skip_download': True, # only get metadata 'extract_flat': True, # only get video IDs, no download } urls = [] with YoutubeDL(ydl_opts) as ydl: info_dict = ydl.extract_info(playlist_url, download=False) entries : list = list(info_dict.get('entries', [])) # Filter out any None or malformed entries entries = [e for e in entries if e and "title" in e] for entry in entries: entry["title"] = str(entry["title"]).replace(" l Velukkudi"," | Velukkudi").replace("Thirupaavai","Thiruppavai") entries.sort(key = lambda x: x["title"]) for i, entry in enumerate(entries, start=31): # Skip removed/private videos if entry and 'id' in entry: urls.append({ "scripture": "divya_prabandham", "global_index": i, "video_url": f"https://www.youtube.com/watch?v={entry['id']}", "type": "upanyasam 3", "title" : entry["title"] }) print(json.dumps(urls, indent=1))