fork from github/youtube-local

This commit is contained in:
Brandon4466
2025-06-29 20:42:55 -07:00
commit dce02a77a6
75 changed files with 22756 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import os
def save_cookies_to_txt(cookies, path):
with open(path, 'w', encoding='utf-8') as f:
for cookie in cookies:
if 'name' in cookie and 'value' in cookie:
f.write(f"{cookie['name']}={cookie['value']}\n")
def main():
# Update this path to your actual Mercury profile directory
mercury_profile_path = r"C:/Users/spong/AppData/Roaming/mercury/Profiles"
# Auto-detect the first profile (or let user specify)
profiles = [d for d in os.listdir(mercury_profile_path) if d.endswith('.default') or d.endswith('.default-release') or d.endswith('.default-esr')]
if not profiles:
print("No Mercury profiles found in:", mercury_profile_path)
return
profile_dir = os.path.join(mercury_profile_path, profiles[0])
print(f"Using Mercury profile: {profile_dir}")
firefox_options = Options()
firefox_options.set_preference('profile', profile_dir)
# Set Mercury browser binary location
firefox_options.binary_location = r"C:/Program Files/Mercury/mercury.exe" # Update this path if needed
print("Opening Mercury browser to https://www.youtube.com using your real profile ...")
driver = webdriver.Firefox(options=firefox_options)
driver.get('https://www.youtube.com')
print("If not already logged in, log in to your YouTube account in the opened browser window.")
input("Press Enter here after you have logged in and the YouTube homepage is fully loaded...")
cookies = driver.get_cookies()
cookies_path = os.path.join(os.path.dirname(__file__), 'cookies.txt')
save_cookies_to_txt(cookies, cookies_path)
print(f"Cookies saved to {cookies_path}")
driver.quit()
if __name__ == '__main__':
main()