-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_youtube_auth.py
More file actions
181 lines (157 loc) · 5.42 KB
/
setup_youtube_auth.py
File metadata and controls
181 lines (157 loc) · 5.42 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python3
"""
YouTube Authentication Setup Helper
This script helps you configure YouTube authentication for the AI Content Processor
by setting up browser cookies or cookie files for yt-dlp.
"""
import os
import sys
from pathlib import Path
def print_header():
"""Print setup header."""
print("=" * 60)
print("YouTube Authentication Setup for AI Content Processor")
print("=" * 60)
print()
def print_option_1():
"""Print instructions for browser cookie extraction."""
print("OPTION 1: Use Browser Cookies (Recommended)")
print("-" * 45)
print()
print("This option extracts cookies directly from your browser.")
print("Make sure you're logged into YouTube in the browser.")
print()
print("Supported browsers:")
print(" • chrome")
print(" • firefox")
print(" • safari")
print(" • edge")
print(" • opera")
print()
print("Steps:")
print("1. Log into YouTube in your browser")
print("2. Add this line to your .env file:")
print(" YOUTUBE_COOKIES_BROWSER=chrome")
print(" (replace 'chrome' with your browser)")
print()
def print_option_2():
"""Print instructions for manual cookie file."""
print("OPTION 2: Use Cookie File")
print("-" * 28)
print()
print("This option uses a manually exported cookies.txt file.")
print()
print("Steps:")
print("1. Install a browser extension to export cookies:")
print(" • Chrome: 'Get cookies.txt LOCALLY'")
print(" • Firefox: 'cookies.txt'")
print()
print("2. Go to YouTube and make sure you're logged in")
print()
print("3. Use the extension to export cookies for youtube.com")
print(" Save as 'youtube_cookies.txt' in your project directory")
print()
print("4. Add this line to your .env file:")
print(" YOUTUBE_COOKIES_FILE=./youtube_cookies.txt")
print()
def check_current_setup():
"""Check current authentication setup."""
print("CURRENT SETUP STATUS")
print("-" * 20)
print()
# Check .env file
env_file = Path(".env")
if not env_file.exists():
print("❌ No .env file found")
print(" Create a .env file with your configuration")
return False
# Load environment variables
from dotenv import load_dotenv
load_dotenv()
cookies_browser = os.getenv('YOUTUBE_COOKIES_BROWSER')
cookies_file = os.getenv('YOUTUBE_COOKIES_FILE')
if cookies_browser:
print(f"✅ Browser cookies configured: {cookies_browser}")
return True
elif cookies_file:
cookie_path = Path(cookies_file)
if cookie_path.exists():
print(f"✅ Cookie file configured: {cookies_file}")
return True
else:
print(f"❌ Cookie file specified but not found: {cookies_file}")
return False
else:
print("❌ No YouTube authentication configured")
return False
def print_troubleshooting():
"""Print troubleshooting tips."""
print("TROUBLESHOOTING")
print("-" * 15)
print()
print("If you still get authentication errors:")
print()
print("1. Make sure you're logged into YouTube in your browser")
print("2. Try a different browser (some work better than others)")
print("3. Clear your browser cache and log in again")
print("4. For cookie files, make sure the file is in Netscape format")
print("5. Check that your cookies haven't expired")
print()
print("Common error solutions:")
print("• 'Sign in to confirm you're not a bot'")
print(" → This means you need to authenticate (follow steps above)")
print("• 'Private video' or 'Video unavailable'")
print(" → Video might be restricted or region-locked")
print("• 'HTTP Error 429'")
print(" → Rate limited, wait and try again")
print()
def create_env_template():
"""Create a .env template if it doesn't exist."""
env_file = Path(".env")
if env_file.exists():
return
print("Creating .env template...")
template = """# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Google Gemini Configuration
GOOGLE_API_KEY=your_google_api_key_here
# YouTube Authentication (choose one)
# Option 1: Browser cookies (recommended)
# YOUTUBE_COOKIES_BROWSER=chrome
# Option 2: Cookie file
# YOUTUBE_COOKIES_FILE=./youtube_cookies.txt
"""
env_file.write_text(template)
print("✅ Created .env template file")
print(" Please add your API keys and YouTube authentication settings")
print()
def main():
"""Main setup function."""
print_header()
# Check current setup
setup_ok = check_current_setup()
print()
if setup_ok:
print("✅ YouTube authentication appears to be configured!")
print(" If you're still having issues, see troubleshooting below.")
print()
else:
print("❌ YouTube authentication needs to be configured.")
print()
# Create .env template if needed
create_env_template()
# Show setup options
print_option_1()
print_option_2()
print_troubleshooting()
print("TESTING YOUR SETUP")
print("-" * 18)
print()
print("After configuring authentication, test with:")
print(" python main.py 'https://www.youtube.com/watch?v=VIDEO_ID'")
print()
print("For more help, see:")
print(" https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp")
print()
if __name__ == "__main__":
main()