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

Update tv5mondeplus.py to detect subtitles #4209

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions yt_dlp/extractor/tv5mondeplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
int_or_none,
parse_duration,
try_get,
url_or_none,
)


Expand Down Expand Up @@ -48,6 +49,16 @@ class TV5MondePlusIE(InfoExtractor):
}]
_GEO_BYPASS = False

@staticmethod
def _extract_subtitles(data_captions):
subtitles = {}
for f in try_get(data_captions, lambda x: x['files'], list) or []:
subtitle_url = url_or_none(f.get('file'))
if subtitle_url:
lang = f.get('label') or 'fra'
subtitles.setdefault(lang, []).append({'url': subtitle_url})
return subtitles

bashonly marked this conversation as resolved.
Show resolved Hide resolved
def _real_extract(self, url):
display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id)
Expand Down Expand Up @@ -95,6 +106,9 @@ def _real_extract(self, url):
if series and series != title:
title = '%s - %s' % (series, title)

subtitles = self._extract_subtitles(self._parse_json(
vpl_data.get('data-captions', '{}'), video_id, fatal=False))
pukkandan marked this conversation as resolved.
Show resolved Hide resolved

upload_date = self._search_regex(
r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})',
webpage, 'upload date', default=None)
Expand All @@ -117,4 +131,5 @@ def _real_extract(self, url):
'formats': formats,
'series': series,
'episode': episode,
'subtitles': subtitles,
bashonly marked this conversation as resolved.
Show resolved Hide resolved
}