Created
March 12, 2023 22:30
-
-
Save ShayBox/70d31d1c09f9b1a78b4ab606f4c7b162 to your computer and use it in GitHub Desktop.
Create ProTV YouTube Playlists
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
from dataclasses import astuple, dataclass | |
from yt_dlp import YoutubeDL | |
from json import JSONEncoder | |
from tqdm import tqdm | |
import json | |
class FakeLogger: | |
def debug(self, msg): | |
pass | |
def warning(self, msg): | |
pass | |
def error(self, msg): | |
pass | |
with open("CustomPlaylist.json", "r") as f: | |
data = json.load(f) | |
with YoutubeDL({"quiet": True, "ignoreerrors": True, "logger": FakeLogger()}) as ytdl: | |
with tqdm(total=len(data)) as pbar: | |
data["https://www.youtube.com/@HANDLE/videos"] = {} | |
for key in data: | |
pbar.update() | |
if not data[key]: | |
# Fetch information | |
pbar.write(key) | |
info = ytdl.extract_info(key, download=False) | |
if info is None: | |
continue | |
# Create and Assign data | |
data[key] = [] | |
for entry in info["entries"]: | |
if entry is not None: | |
data[key].append( | |
{ | |
"channel_id": entry["channel_id"], | |
"channel_url": entry["channel_url"], | |
"channel": entry["channel"], | |
"display_id": entry["display_id"], | |
"original_url": entry["original_url"], | |
"tags": entry["tags"], | |
"title": entry["title"], | |
} | |
) | |
# Dump and Write json data | |
with open("CustomPlaylist.json", "w") as f: | |
json.dump(data, f, indent=4, sort_keys=True) | |
with open("CustomPlaylist.txt", "w", encoding="UTF-8") as f: | |
for key in data: | |
for info in data[key]: | |
video = f"@https://shay.loan/{info['display_id']}\n#{info['tags']} {info['display_id']}\n{info['channel']} - {info['title']}\n\n" | |
f.write(video) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment