Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ie/reddit] Fix subtitle extraction #10006

Merged
merged 8 commits into from
May 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions yt_dlp/extractor/reddit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import urllib.parse

from .common import InfoExtractor
Expand Down Expand Up @@ -76,7 +77,7 @@ class RedditIE(InfoExtractor):
'like_count': int,
'dislike_count': int,
'comment_count': int,
'age_limit': 0,
'age_limit': 18,
'channel_id': 'u_creepyt0es',
},
'params': {
Expand Down Expand Up @@ -150,6 +151,48 @@ class RedditIE(InfoExtractor):
'like_count': int,
},
'skip': 'Requires account that has opted-in to the GenZedong subreddit',
}, {
# subtitle in HLS manifest
'url': 'https://www.reddit.com/r/Unexpected/comments/1cl9h0u/the_insurance_claim_will_be_interesting/',
'info_dict': {
'id': 'a2mdj5d57qyc1',
'ext': 'mp4',
'display_id': '1cl9h0u',
'title': 'The insurance claim will be interesting',
'uploader': 'darrenpauli',
'channel_id': 'Unexpected',
'duration': 53,
'upload_date': '20240506',
'timestamp': 1714966382,
'age_limit': 0,
'comment_count': int,
'dislike_count': int,
'like_count': int,
},
'params': {
'skip_download': True,
},
}, {
# subtitle from caption-url
'url': 'https://www.reddit.com/r/soccer/comments/1cxwzso/tottenham_1_0_newcastle_united_james_maddison_31/',
'info_dict': {
'id': 'xbmj4t3igy1d1',
'ext': 'mp4',
'display_id': '1cxwzso',
'title': 'Tottenham [1] - 0 Newcastle United - James Maddison 31\'',
'uploader': 'Woodstovia',
'channel_id': 'soccer',
'duration': 30,
'upload_date': '20240522',
'timestamp': 1716373798,
'age_limit': 0,
'comment_count': int,
'dislike_count': int,
'like_count': int,
},
'params': {
'skip_download': True,
},
}, {
'url': 'https://www.reddit.com/r/videos/comments/6rrwyj',
'only_matching': True,
Expand Down Expand Up @@ -306,7 +349,8 @@ def add_thumbnail(src):
'video_id', default=display_id)

dash_playlist_url = playlist_urls[0] or f'https://v.redd.it/{video_id}/DASHPlaylist.mpd'
hls_playlist_url = playlist_urls[1] or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8'
hls_playlist_url = re.sub(r'(f=[^&]+)', r'\1%2CsubsAll', playlist_urls[1]) or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8?f=hd%2CsubsAll'
caption_url = f'https://v.redd.it/{video_id}/wh_ben_en.vtt'
kclauhk marked this conversation as resolved.
Show resolved Hide resolved

formats = [{
'url': unescapeHTML(reddit_video['fallback_url']),
Expand All @@ -326,6 +370,8 @@ def add_thumbnail(src):
dash_playlist_url, display_id, mpd_id='dash', fatal=False)
formats.extend(dash_fmts)
self._merge_subtitles(dash_subs, target=subtitles)
if not subtitles and self._is_valid_url(caption_url, video_id, item='subtitle'):
kclauhk marked this conversation as resolved.
Show resolved Hide resolved
self._merge_subtitles({'en': [{'url': caption_url}]}, target=subtitles)
kclauhk marked this conversation as resolved.
Show resolved Hide resolved

return {
**info,
Expand Down
Loading