Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
| #!/usr/bin/env python3 | |
| """ | |
| Export YouTube cookies from Chrome browser database | |
| Requires: pip install pycryptodome | |
| """ | |
| import os | |
| import sqlite3 | |
| import json | |
| from pathlib import Path | |
| def export_chrome_cookies(): | |
| """Export cookies from Chrome to Netscape format""" | |
| # Chrome cookie database location | |
| chrome_cookie_db = Path.home() / '.config/google-chrome/Default/Cookies' | |
| if not chrome_cookie_db.exists(): | |
| # Try other common locations | |
| alternatives = [ | |
| Path.home() / '.config/chromium/Default/Cookies', | |
| Path.home() / 'snap/chromium/common/chromium/Default/Cookies', | |
| ] | |
| for alt in alternatives: | |
| if alt.exists(): | |
| chrome_cookie_db = alt | |
| break | |
| else: | |
| print("❌ Chrome cookies database not found!") | |
| print(f"Looked in: {chrome_cookie_db}") | |
| print("Make sure Chrome/Chromium is installed and you've visited YouTube") | |
| return False | |
| # Copy database (Chrome locks it) | |
| import shutil | |
| temp_db = '/tmp/chrome_cookies.db' | |
| shutil.copy2(chrome_cookie_db, temp_db) | |
| # Connect to database | |
| conn = sqlite3.connect(temp_db) | |
| cursor = conn.cursor() | |
| # Get YouTube cookies | |
| cursor.execute(""" | |
| SELECT host_key, path, is_secure, expires_utc, name, value | |
| FROM cookies | |
| WHERE host_key LIKE '%youtube.com%' | |
| """) | |
| cookies = cursor.fetchall() | |
| conn.close() | |
| if not cookies: | |
| print("❌ No YouTube cookies found!") | |
| print("Make sure you're logged into YouTube in Chrome") | |
| return False | |
| # Write to Netscape format | |
| with open('youtube_cookies.txt', 'w') as f: | |
| f.write("# Netscape HTTP Cookie File\n") | |
| f.write("# This file is generated by export_chrome_cookies.py\n\n") | |
| for host, path, secure, expires, name, value in cookies: | |
| # Convert Chrome's expires format (microseconds since 1601) to Unix timestamp | |
| if expires: | |
| # Chrome uses Windows epoch (1601-01-01), convert to Unix epoch (1970-01-01) | |
| expires_unix = (expires - 11644473600000000) // 1000000 | |
| else: | |
| expires_unix = 0 | |
| secure_str = "TRUE" if secure else "FALSE" | |
| f.write(f"{host}\tTRUE\t{path}\t{secure_str}\t{expires_unix}\t{name}\t{value}\n") | |
| print(f"✅ Exported {len(cookies)} YouTube cookies to youtube_cookies.txt") | |
| # Check for authentication cookies | |
| auth_cookies = [c for c in cookies if c[4] in ['SAPISID', 'HSID', 'SID', 'SSID', 'LOGIN_INFO']] | |
| if auth_cookies: | |
| print(f"✅ Found {len(auth_cookies)} authentication cookies") | |
| print(" Your cookies include login information!") | |
| else: | |
| print("⚠️ No authentication cookies found") | |
| print(" Make sure you're LOGGED IN to YouTube in Chrome") | |
| return True | |
| if __name__ == "__main__": | |
| print("Exporting YouTube cookies from Chrome...") | |
| export_chrome_cookies() | |