Phoe2004 commited on
Commit
cc83ea3
·
verified ·
1 Parent(s): f1a99a3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -323,21 +323,28 @@ def api_cookie_check():
323
  def get_latest_youtube_video(channel_id):
324
  """Use yt-dlp to get latest video ID & title — bypasses RSS cache delay"""
325
  try:
326
- cmd = [
327
- 'yt-dlp',
328
- '--flat-playlist',
329
- '--playlist-end', '1',
330
- '--print', '%(id)s|||%(title)s',
331
- f'https://www.youtube.com/channel/{channel_id}/videos'
332
- ]
333
  if os.path.exists(COOKIES_FILE):
334
- cmd = ['yt-dlp', '--cookies', COOKIES_FILE,
335
- '--flat-playlist', '--playlist-end', '1',
336
- '--print', '%(id)s|||%(title)s',
337
- f'https://www.youtube.com/channel/{channel_id}/videos']
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
339
- result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
340
- if result.returncode == 0 and result.stdout.strip():
341
  line = result.stdout.strip().splitlines()[0]
342
  parts = line.split('|||', 1)
343
  if len(parts) == 2:
@@ -345,7 +352,8 @@ def get_latest_youtube_video(channel_id):
345
  title = parts[1].strip()
346
  if vid_id:
347
  return vid_id, title
348
- add_log(f'⚠️ yt-dlp stderr: {result.stderr[:200]}')
 
349
  except subprocess.TimeoutExpired:
350
  add_log('⚠️ yt-dlp channel check timed out')
351
  except Exception as e:
 
323
  def get_latest_youtube_video(channel_id):
324
  """Use yt-dlp to get latest video ID & title — bypasses RSS cache delay"""
325
  try:
326
+ base_cmd = ['yt-dlp', '--flat-playlist', '--playlist-end', '1',
327
+ '--print', '%(id)s|||%(title)s']
 
 
 
 
 
328
  if os.path.exists(COOKIES_FILE):
329
+ base_cmd = ['yt-dlp', '--cookies', COOKIES_FILE,
330
+ '--flat-playlist', '--playlist-end', '1',
331
+ '--print', '%(id)s|||%(title)s']
332
+
333
+ # Try multiple URL formats — some channels have no /videos tab
334
+ urls_to_try = [
335
+ f'https://www.youtube.com/channel/{channel_id}',
336
+ f'https://www.youtube.com/channel/{channel_id}/streams',
337
+ f'https://www.youtube.com/channel/{channel_id}/videos',
338
+ ]
339
+ result = None
340
+ for url in urls_to_try:
341
+ cmd = base_cmd + [url]
342
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
343
+ if result.returncode == 0 and result.stdout.strip():
344
+ break
345
+ add_log(f'⚠️ Tried {url.split("/")[-1] or "channel"}: {result.stderr[:100]}')
346
 
347
+ if result and result.returncode == 0 and result.stdout.strip():
 
348
  line = result.stdout.strip().splitlines()[0]
349
  parts = line.split('|||', 1)
350
  if len(parts) == 2:
 
352
  title = parts[1].strip()
353
  if vid_id:
354
  return vid_id, title
355
+ if result:
356
+ add_log(f'⚠️ yt-dlp stderr: {result.stderr[:200]}')
357
  except subprocess.TimeoutExpired:
358
  add_log('⚠️ yt-dlp channel check timed out')
359
  except Exception as e: