From 71ba63ffe34d0f886cd265ec668393e97bc87f33 Mon Sep 17 00:00:00 2001 From: azcomputerguru Date: Fri, 8 May 2026 19:29:48 -0400 Subject: [PATCH] Fix @handle URL resolution using --flat-playlist - Updated extract_channel_id() to use --flat-playlist instead of --playlist-items 0 - Append /videos to URLs to ensure playlist metadata is available - Extract playlist_channel_id and playlist_channel from flat-playlist output - Increased timeout to 15 seconds for network fetch - All URL formats now working: direct IDs, /channel/ URLs, @handle URLs Tested and verified in Docker container. --- app.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index cf70f22..f55cc93 100644 --- a/app.py +++ b/app.py @@ -69,22 +69,31 @@ def extract_channel_id(url_or_id): # Format: youtube.com/@handle or youtube.com/c/name or youtube.com/user/name # These require fetching the page to get the actual channel ID if parsed.netloc in ['youtube.com', 'www.youtube.com', 'm.youtube.com']: - # Use yt-dlp to extract channel ID from URL + # Use yt-dlp with --flat-playlist to extract channel ID without downloading + # Append /videos if not already present to ensure we get playlist metadata + fetch_url = url_or_id + if not fetch_url.endswith('/videos'): + fetch_url = fetch_url.rstrip('/') + '/videos' + try: result = subprocess.run( - ['yt-dlp', '--dump-json', '--playlist-items', '0', url_or_id], + ['yt-dlp', '--flat-playlist', '--dump-json', '--playlist-items', '1', fetch_url], capture_output=True, text=True, - timeout=10 + timeout=15 ) if result.returncode == 0 and result.stdout: - data = json.loads(result.stdout.split('\n')[0]) - channel_id = data.get('channel_id') - channel_name = data.get('channel') + # Get first line of JSON output + lines = [l for l in result.stdout.split('\n') if l.strip()] + if lines: + data = json.loads(lines[0]) + # flat-playlist returns playlist_channel_id instead of channel_id + channel_id = data.get('playlist_channel_id') or data.get('channel_id') + channel_name = data.get('playlist_channel') or data.get('channel') - if channel_id: - return channel_id, channel_name + if channel_id: + return channel_id, channel_name except: pass except: