4 from .common
import InfoExtractor
5 from .dailymotion
import DailymotionIE
6 from ..networking
import HEADRequest
18 from ..utils
.traversal
import traverse_obj
21 class FranceTVBaseInfoExtractor(InfoExtractor
):
22 def _make_url_result(self
, video_id
, url
=None):
23 video_id
= video_id
.split('@')[0] # for compat with old @catalog IDs
24 full_id
= f
'francetv:{video_id}'
26 full_id
= smuggle_url(full_id
, {'hostname': urllib.parse.urlparse(url).hostname}
)
27 return self
.url_result(full_id
, FranceTVIE
, video_id
)
30 class FranceTVIE(InfoExtractor
):
31 _VALID_URL
= r
'francetv:(?P<id>[^@#]+)'
32 _GEO_COUNTRIES
= ['FR']
36 'url': 'francetv:ec217ecc-0733-48cf-ac06-af1347b849d1',
38 'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1',
40 'title': '13h15, le dimanche... - Les mystères de Jésus',
41 'timestamp': 1502623500,
43 'thumbnail': r
're:^https?://.*\.jpg$',
44 'upload_date': '20170813',
46 'params': {'skip_download': 'm3u8'}
,
48 'url': 'francetv:162311093',
49 'only_matching': True,
51 'url': 'francetv:NI_1004933@Zouzous',
52 'only_matching': True,
54 'url': 'francetv:NI_983319@Info-web',
55 'only_matching': True,
57 'url': 'francetv:NI_983319',
58 'only_matching': True,
60 'url': 'francetv:NI_657393@Regions',
61 'only_matching': True,
64 'url': 'francetv:SIM_France3',
65 'only_matching': True,
68 def _extract_video(self
, video_id
, hostname
=None):
80 # desktop+chrome returns dash; mobile+safari returns hls
81 for device_type
, browser
in [('desktop', 'chrome'), ('mobile', 'safari')]:
82 dinfo
= self
._download
_json
(
83 f
'https://k7.ftven.fr/videos/{video_id}', video_id
,
84 f
'Downloading {device_type} {browser} video JSON', query
=filter_dict({
85 'device_type': device_type
,
93 video
= traverse_obj(dinfo
, ('video', {dict}
))
97 duration
= video
.get('duration')
99 is_live
= video
.get('is_live')
100 if spritesheets
is None:
101 spritesheets
= video
.get('spritesheets')
103 meta
= traverse_obj(dinfo
, ('meta', {dict}
))
106 title
= meta
.get('title')
107 # meta['pre_title'] contains season and episode number for series in format "S<ID> E<ID>"
108 season_number
, episode_number
= self
._search
_regex
(
109 r
'S(\d+)\s*E(\d+)', meta
.get('pre_title'), 'episode info', group
=(1, 2), default
=(None, None))
111 subtitle
= meta
.get('additional_title')
113 image
= meta
.get('image_url')
114 if timestamp
is None:
115 timestamp
= parse_iso8601(meta
.get('broadcasted_at'))
117 formats
, subtitles
, video_url
= [], {}, None
118 for video
in traverse_obj(videos
, lambda _
, v
: url_or_none(v
['url'])):
119 video_url
= video
['url']
120 format_id
= video
.get('format')
122 if token_url
:= url_or_none(video
.get('token')):
123 tokenized_url
= traverse_obj(self
._download
_json
(
124 token_url
, video_id
, f
'Downloading signed {format_id} manifest URL',
128 }), ('url', {url_or_none}
))
130 video_url
= tokenized_url
132 ext
= determine_ext(video_url
)
134 formats
.extend(self
._extract
_f
4m
_formats
(
135 video_url
, video_id
, f4m_id
=format_id
or ext
, fatal
=False))
137 format_id
= format_id
or 'hls'
138 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
139 video_url
, video_id
, 'mp4', m3u8_id
=format_id
, fatal
=False)
140 for f
in traverse_obj(fmts
, lambda _
, v
: v
['vcodec'] == 'none' and v
.get('tbr') is None):
141 if mobj
:= re
.match(rf
'{format_id}-[Aa]udio-\w+-(?P<bitrate>\d+)', f
['format_id']):
143 'tbr': int_or_none(mobj
.group('bitrate')),
147 self
._merge
_subtitles
(subs
, target
=subtitles
)
149 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
150 video_url
, video_id
, mpd_id
=format_id
or 'dash', fatal
=False)
152 self
._merge
_subtitles
(subs
, target
=subtitles
)
153 elif video_url
.startswith('rtmp'):
156 'format_id': join_nonempty('rtmp', format_id
),
160 if self
._is
_valid
_url
(video_url
, video_id
, format_id
):
163 'format_id': format_id
,
166 # XXX: what is video['captions']?
168 if not formats
and video_url
:
169 urlh
= self
._request
_webpage
(
170 HEADRequest(video_url
), video_id
, 'Checking for geo-restriction',
171 fatal
=False, expected_status
=403)
172 if urlh
and urlh
.headers
.get('x-errortype') == 'geo':
173 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
, metadata_available
=True)
176 if f
.get('acodec') != 'none' and f
.get('language') in ('qtz', 'qad'):
177 f
['language_preference'] = -10
178 f
['format_note'] = 'audio description%s' % format_field(f
, 'format_note', ', %s')
182 'format_id': 'spritesheets',
183 'format_note': 'storyboard',
188 'url': 'about:invalid',
191 # XXX: not entirely accurate; each spritesheet seems to be
192 # a 10×10 grid of thumbnails corresponding to approximately
193 # 2 seconds of the video; the last spritesheet may be shorter
195 } for sheet
in traverse_obj(spritesheets
, (..., {url_or_none}
))]
200 'title': join_nonempty(title
, subtitle
, delim
=' - ').strip(),
202 'duration': duration
,
203 'timestamp': timestamp
,
206 'subtitles': subtitles
,
207 'episode': subtitle
if episode_number
else None,
208 'series': title
if episode_number
else None,
209 'episode_number': int_or_none(episode_number
),
210 'season_number': int_or_none(season_number
),
211 '_format_sort_fields': ('res', 'tbr', 'proto'), # prioritize m3u8 over dash
214 def _real_extract(self
, url
):
215 url
, smuggled_data
= unsmuggle_url(url
, {})
216 video_id
= self
._match
_id
(url
)
217 hostname
= smuggled_data
.get('hostname') or 'www.france.tv'
219 return self
._extract
_video
(video_id
, hostname
=hostname
)
222 class FranceTVSiteIE(FranceTVBaseInfoExtractor
):
223 _VALID_URL
= r
'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
226 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
228 'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1',
230 'title': '13h15, le dimanche... - Les mystères de Jésus',
231 'timestamp': 1502623500,
233 'thumbnail': r
're:^https?://.*\.jpg$',
234 'upload_date': '20170813',
237 'skip_download': True,
239 'add_ie': [FranceTVIE
.ie_key()],
242 'url': 'https://www.france.tv/enfants/six-huit-ans/foot2rue/saison-1/3066387-duel-au-vieux-port.html',
244 'id': 'a9050959-eedd-4b4a-9b0d-de6eeaa73e44',
246 'title': 'Foot2Rue - Duel au vieux port',
247 'episode': 'Duel au vieux port',
248 'series': 'Foot2Rue',
251 'timestamp': 1642761360,
252 'upload_date': '20220121',
253 'season': 'Season 1',
254 'thumbnail': r
're:^https?://.*\.jpg$',
258 # geo-restricted livestream (workflow == 'token-akamai')
259 'url': 'https://www.france.tv/france-4/direct.html',
261 'id': '9a6a7670-dde9-4264-adbc-55b89558594b',
263 'title': r
're:France 4 en direct .+',
264 'live_status': 'is_live',
266 'skip': 'geo-restricted livestream',
268 # livestream (workflow == 'dai')
269 'url': 'https://www.france.tv/france-2/direct.html',
271 'id': '006194ea-117d-4bcf-94a9-153d999c59ae',
273 'title': r
're:France 2 en direct .+',
274 'live_status': 'is_live',
276 'params': {'skip_download': 'livestream'}
,
279 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
280 'only_matching': True,
283 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
284 'only_matching': True,
287 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
288 'only_matching': True,
291 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
292 'only_matching': True,
294 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
295 'only_matching': True,
297 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
298 'only_matching': True,
300 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
301 'only_matching': True,
303 'url': 'https://www.france.tv/142749-rouge-sang.html',
304 'only_matching': True,
307 'url': 'https://www.france.tv/france-3/direct.html',
308 'only_matching': True,
311 def _real_extract(self
, url
):
312 display_id
= self
._match
_id
(url
)
314 webpage
= self
._download
_webpage
(url
, display_id
)
316 video_id
= self
._search
_regex
(
317 r
'(?:data-main-video\s*=|videoId["\']?\s
*[:=])\s
*(["\'])(?P<id>(?:(?!\1).)+)\1',
318 webpage, 'video id', default=None, group='id')
321 video_id = self._html_search_regex(
322 r'(?:href=|player\.setVideo\(\s*)"http
://videos?\
.francetv\
.fr
/video
/([^
@"]+@[^"]+)"',
325 return self._make_url_result(video_id, url=url)
328 class FranceTVInfoIE(FranceTVBaseInfoExtractor):
329 IE_NAME = 'francetvinfo.fr'
330 _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&.]+)'
333 'url': 'https://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-jeudi-22-aout-2019_3561461.html',
335 'id': 'd12458ee-5062-48fe-bfdd-a30d6a01b793',
338 'upload_date': '20190822',
339 'timestamp': 1566510730,
340 'thumbnail': r're:^https?://.*\.jpe?g$',
347 'skip_download': True,
349 'add_ie': [FranceTVIE.ie_key()],
351 'note': 'Only an image exists in initial webpage instead of the video',
352 'url': 'https://www.francetvinfo.fr/sante/maladie/coronavirus/covid-19-en-inde-une-situation-catastrophique-a-new-dehli_4381095.html',
354 'id': '7d204c9e-a2d3-11eb-9e4c-000d3a23d482',
356 'title': 'Covid-19 : une situation catastrophique à New Dehli - Édition du mercredi 21 avril 2021',
357 'thumbnail': r're:^https?://.*\.jpe?g$',
359 'timestamp': 1619028518,
360 'upload_date': '20210421',
363 'skip_download': True,
365 'add_ie': [FranceTVIE.ie_key()],
367 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
368 'only_matching': True,
370 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
371 'only_matching': True,
373 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
374 'only_matching': True,
377 'url': 'http://www.francetvinfo.fr/politique/notre-dame-des-landes/video-sur-france-inter-cecile-duflot-denonce-le-regard-meprisant-de-patrick-cohen_1520091.html',
378 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
382 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
383 'description': 'md5:fdcb582c370756293a65cdfbc6ecd90e',
384 'timestamp': 1467011958,
385 'uploader': 'France Inter',
386 'uploader_id': 'x2q2ez',
387 'upload_date': '20160627',
389 'tags': ['Politique', 'France Inter', '27 juin 2016', 'Linvité de 8h20', 'Cécile Duflot', 'Patrick Cohen'],
393 'thumbnail': r're:https://[^/?#]+/v/[^/?#]+/x1080',
395 'add_ie': ['Dailymotion'],
397 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
398 'only_matching': True,
400 # "<figure
id=" pattern (#28792)
401 'url': 'https://www.francetvinfo.fr/culture/patrimoine/incendie-de-notre-dame-de-paris/notre-dame-de-paris-de-l-incendie-de-la-cathedrale-a-sa-reconstruction_4372291.html',
402 'only_matching': True,
405 def _real_extract(self, url):
406 display_id = self._match_id(url)
408 webpage = self._download_webpage(url, display_id)
410 dailymotion_urls = tuple(DailymotionIE._extract_embed_urls(url, webpage))
412 return self.playlist_result([
413 self.url_result(dailymotion_url, DailymotionIE.ie_key())
414 for dailymotion_url in dailymotion_urls])
416 video_id = self._search_regex(
417 (r'player\.load[^;]+src:\s*["\']([^
"\']+)',
418 r'id-video=([^@]+@[^"]+)',
419 r'<a
[^
>]+href
="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"',
420 r'(?:data-id|<figure[^<]+\bid)=["\']([\da
-f
]{8}
-[\da
-f
]{4}
-[\da
-f
]{4}
-[\da
-f
]{4}
-[\da
-f
]{12}
)'),
423 return self._make_url_result(video_id, url=url)