diff --git a/newbot.py b/newbot.py index 8d3b44b..ab2befe 100644 --- a/newbot.py +++ b/newbot.py @@ -1,4 +1,10 @@ import obsws_python +from selenium.webdriver.firefox.options import Options +from seleniumwire import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.wait import WebDriverWait +from netscape_cookies import to_netscape_string +import json import yt_dlp from time import sleep import time @@ -37,6 +43,26 @@ full_dl_dir = Path(download_dir.name) vid_details = {"title": "", "channel": ""} con = sqlite3.connect(os.getenv("QUEUE_PATH","queue.db"), check_same_thread=False) cur = con.cursor() +options = Options() +options.add_argument("--headless") +options.profile = webdriver.FirefoxProfile(os.getenv("PROFILE_PATH")) +driver = webdriver.Firefox(options=options) + +print("Getting potoken from firefox...") +driver.get("https://www.youtube.com/embed/aqz-KE-bpKQ") +elem = WebDriverWait(driver, 8, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-video-player")) +sleep(1) +elem.click() +sleep(2) +for r in driver.requests: + if "https://www.youtube.com/youtubei/v1/player" in r.url: + potoken = json.loads(r.body)['serviceIntegrityDimensions']["poToken"] + break +cookiesstr = to_netscape_string(driver.get_cookies()) +with open("cookies.txt", 'w') as f: + f.write(f'# Netscape HTTP Cookie File\n# https://curl.haxx.se/rfc/cookie_spec.html\n# This is a generated file! Do not edit.\n\n{cookiesstr}') +driver.close() +print(f"Success! Potoken is {potoken}") def countuser(usrid): res = cur.execute(f"SELECT ROWID FROM queue WHERE " + ("hasplayed = false AND " if not (os.getenv("PERMANENT_MAX_QUEUE","FALSE") == "TRUE") else "") + f"user = {usrid}") @@ -81,9 +107,9 @@ ydl_opts = { 'match_filter': video_check, 'hls_prefer_native': True, 'extract_flat': 'discard_in_playlist', - 'cookiefile': f'{os.getenv("COOKIES_FILE")}', + 'cookiefile': f'cookies.txt', 'extractor_args': {'youtube': {'player_client': ['web', 'default'], - 'po_token': [f'web+{os.getenv("PO_TOKEN")}']}}, + 'po_token': [f'web+{potoken}']}}, 'format': 'bestvideo[height<=1080][vcodec!*=av01][ext=mp4]+bestaudio[abr<=256][ext=m4a]/best[ext=mp4]/best', 'fragment_retries': 10, 'noplaylist': True, diff --git a/requirements.txt b/requirements.txt index 731a58e..d259908 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ disnake -obsws_python \ No newline at end of file +obsws_python +netscape-cookies +blinker==1.7.0 +selenium-wire \ No newline at end of file