From 4fd92f7834d8ffede3cb3a18530860ecf035e077 Mon Sep 17 00:00:00 2001 From: insert Date: Sat, 18 Jan 2025 15:14:23 -0500 Subject: [PATCH] Require youtube PO token --- .env.example | 2 ++ .gitignore | 1 + newbot.py | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 848b9cb..feafe6c 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ TOKEN="" +PO_TOKEN="" +COOKIES_FILE="" GUILD_ID="" QUEUE_PATH="" MAX_MIN="8" diff --git a/.gitignore b/.gitignore index 60edee5..4bf7ef2 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ share/python-wheels/ *.egg *.mp4 *.vtt +cookies* testing/ *.db next* diff --git a/newbot.py b/newbot.py index 0296dec..8d3b44b 100644 --- a/newbot.py +++ b/newbot.py @@ -81,6 +81,9 @@ ydl_opts = { 'match_filter': video_check, 'hls_prefer_native': True, 'extract_flat': 'discard_in_playlist', + 'cookiefile': f'{os.getenv("COOKIES_FILE")}', + 'extractor_args': {'youtube': {'player_client': ['web', 'default'], + 'po_token': [f'web+{os.getenv("PO_TOKEN")}']}}, 'format': 'bestvideo[height<=1080][vcodec!*=av01][ext=mp4]+bestaudio[abr<=256][ext=m4a]/best[ext=mp4]/best', 'fragment_retries': 10, 'noplaylist': True, @@ -154,7 +157,7 @@ def download_video(index): sleep(2) #allow ytdlp to fully cleanup except Exception as e: print("handling youtube exception") - if "Sign in to confirm" in str(e): + if "Sign in to confirm" in str(e) or "forbidden" in str(e).lower(): print("youtube ban detected") #This is the worst possible case and therefore all activity must halt obs.set_current_program_scene("banned")