File size: 3,066 Bytes
d15f07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/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()