jarif commited on
Commit
b587870
·
verified ·
1 Parent(s): 09892c6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -76,11 +76,27 @@ def get_youtube_content(url):
76
  'extract_flat': True,
77
  'quiet': True,
78
  'no_warnings': True,
79
- 'cookiefile': 'youtube_cookies.txt' # Use the cookies file we created
 
 
 
 
 
 
 
 
80
  }
81
 
82
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
83
- info = ydl.extract_info(url, download=False)
 
 
 
 
 
 
 
 
84
 
85
  title = info.get('title', '')
86
  description = info.get('description', '')
 
76
  'extract_flat': True,
77
  'quiet': True,
78
  'no_warnings': True,
79
+ 'cookiefile': 'youtube_cookies.txt', # Primary cookie method
80
+ 'cookiesfrombrowser': ('chrome',), # Backup cookie method
81
+ 'extractor_args': { # Additional arguments to help bypass restrictions
82
+ 'youtube': {
83
+ 'skip': ['dash', 'hls'],
84
+ 'player_skip': ['js', 'configs', 'webpage']
85
+ }
86
+ },
87
+ 'no_check_certificate': True,
88
  }
89
 
90
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
91
+ try:
92
+ info = ydl.extract_info(url, download=False)
93
+ except Exception as yt_error:
94
+ if "Sign in to confirm your age" in str(yt_error):
95
+ ydl_opts['format'] = 'best[height<=480]' # Try a different format
96
+ ydl = yt_dlp.YoutubeDL(ydl_opts)
97
+ info = ydl.extract_info(url, download=False)
98
+ else:
99
+ raise yt_error
100
 
101
  title = info.get('title', '')
102
  description = info.get('description', '')