aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/watch.py
diff options
context:
space:
mode:
Diffstat (limited to 'youtube/watch.py')
-rw-r--r--youtube/watch.py40
1 files changed, 34 insertions, 6 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index aa286e2..14f1dae 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -628,7 +628,12 @@ def get_watch_page(video_id=None):
# prefix urls, and other post-processing not handled by yt_data_extract
for item in info['related_videos']:
- item['thumbnail'] = "https://i.ytimg.com/vi/{}/hqdefault.jpg".format(item['id']) # set HQ relateds thumbnail videos
+ # For playlists, use first_video_id for thumbnail, not playlist id
+ if item.get('type') == 'playlist' and item.get('first_video_id'):
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['first_video_id'])
+ elif item.get('type') == 'video':
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['id'])
+ # For other types, keep existing thumbnail or skip
util.prefix_urls(item)
util.add_extra_html_info(item)
for song in info['music_list']:
@@ -636,6 +641,9 @@ def get_watch_page(video_id=None):
if info['playlist']:
playlist_id = info['playlist']['id']
for item in info['playlist']['items']:
+ # Set high quality thumbnail for playlist videos
+ if item.get('type') == 'video' and item.get('id'):
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['id'])
util.prefix_urls(item)
util.add_extra_html_info(item)
if playlist_id:
@@ -692,12 +700,24 @@ def get_watch_page(video_id=None):
audio_tracks = []
try:
from youtube import ytdlp_integration
+ logger.info(f'Extracting audio tracks for video: {video_id}')
ytdlp_info = ytdlp_integration.extract_video_info_ytdlp(video_id)
audio_tracks = ytdlp_info.get('audio_tracks', [])
+
if audio_tracks:
- logger.info(f'Found {len(audio_tracks)} audio tracks for video {video_id}')
+ logger.info(f'✓ Found {len(audio_tracks)} audio tracks:')
+ for i, track in enumerate(audio_tracks[:10], 1): # Log first 10
+ logger.info(f' [{i}] {track["language_name"]} ({track["language"]}) - '
+ f'bitrate: {track.get("audio_bitrate", "N/A")}k, '
+ f'codec: {track.get("acodec", "N/A")}, '
+ f'format_id: {track.get("format_id", "N/A")}')
+ if len(audio_tracks) > 10:
+ logger.info(f' ... and {len(audio_tracks) - 10} more')
+ else:
+ logger.warning(f'No audio tracks found for video {video_id}')
+
except Exception as e:
- logger.warning(f'Failed to extract audio tracks: {e}')
+ logger.error(f'Failed to extract audio tracks: {e}', exc_info=True)
audio_tracks = []
pair_quality = yt_data_extract.deep_get(pair_sources, pair_idx, 'quality')
@@ -834,9 +854,17 @@ def get_watch_page(video_id=None):
@yt_app.route('/api/<path:dummy>')
def get_captions(dummy):
- result = util.fetch_url('https://www.youtube.com' + request.full_path)
- result = result.replace(b"align:start position:0%", b"")
- return result
+ try:
+ result = util.fetch_url('https://www.youtube.com' + request.full_path)
+ result = result.replace(b"align:start position:0%", b"")
+ return result
+ except util.FetchError as e:
+ # Return empty captions gracefully instead of error page
+ logger.warning(f'Failed to fetch captions: {e}')
+ return flask.Response(b'WEBVTT\n\n', mimetype='text/vtt', status=200)
+ except Exception as e:
+ logger.error(f'Unexpected error fetching captions: {e}')
+ return flask.Response(b'WEBVTT\n\n', mimetype='text/vtt', status=200)
times_reg = re.compile(r'^\d\d:\d\d:\d\d\.\d\d\d --> \d\d:\d\d:\d\d\.\d\d\d.*$')