3 from __future__
import unicode_literals
7 from .common
import InfoExtractor
22 from .dailymotion
import DailymotionIE
25 class FranceTVBaseInfoExtractor(InfoExtractor
):
26 def _make_url_result(self
, video_or_full_id
, catalog
=None):
27 full_id
= 'francetv:%s' % video_or_full_id
28 if '@' not in video_or_full_id
and catalog
:
29 full_id
+= '@%s' % catalog
30 return self
.url_result(
31 full_id
, ie
=FranceTVIE
.ie_key(),
32 video_id
=video_or_full_id
.split('@')[0])
35 class FranceTVIE(InfoExtractor
):
39 sivideo\.webservices\.francetelevisions\.fr/tools/getInfosOeuvre/v2/\?
40 .*?\bidDiffusion=[^&]+|
42 https?://videos\.francetv\.fr/video/|
45 (?P<id>[^@]+)(?:@(?P<catalog>.+))?
51 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=162311093&callback=_jsonp_loader_callback_request_0',
52 'md5': 'c2248a8de38c4e65ea8fae7b5df2d84f',
56 'title': '13h15, le dimanche... - Les mystères de Jésus',
57 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
58 'timestamp': 1502623500,
59 'upload_date': '20170813',
63 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=NI_1004933&catalogue=Zouzous&callback=_jsonp_loader_callback_request_4',
64 'only_matching': True,
66 'url': 'http://videos.francetv.fr/video/NI_657393@Regions',
67 'only_matching': True,
69 'url': 'francetv:162311093',
70 'only_matching': True,
72 'url': 'francetv:NI_1004933@Zouzous',
73 'only_matching': True,
75 'url': 'francetv:NI_983319@Info-web',
76 'only_matching': True,
78 'url': 'francetv:NI_983319',
79 'only_matching': True,
81 'url': 'francetv:NI_657393@Regions',
82 'only_matching': True,
85 'url': 'francetv:SIM_France3',
86 'only_matching': True,
89 def _extract_video(self
, video_id
, catalogue
=None):
90 # Videos are identified by idDiffusion so catalogue part is optional.
91 # However when provided, some extra formats may be returned so we pass
93 info
= self
._download
_json
(
94 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/',
95 video_id
, 'Downloading video JSON', query
={
96 'idDiffusion': video_id
,
97 'catalogue': catalogue
or '',
100 if info
.get('status') == 'NOK':
101 raise ExtractorError(
102 '%s returned error: %s' % (self
.IE_NAME
, info
['message']),
104 allowed_countries
= info
['videos'][0].get('geoblocage')
105 if allowed_countries
:
107 geo_info
= self
._download
_json
(
108 'http://geo.francetv.fr/ws/edgescape.json', video_id
,
109 'Downloading geo restriction info')
110 country
= geo_info
['reponse']['geo_info']['country_code']
111 if country
not in allowed_countries
:
112 raise ExtractorError(
113 'The video is not available from your location',
116 georestricted
= False
118 def sign(manifest_url
, manifest_id
):
119 for host
in ('hdfauthftv-a.akamaihd.net', 'hdfauth.francetv.fr'):
120 signed_url
= url_or_none(self
._download
_webpage
(
121 'https://%s/esi/TA' % host
, video_id
,
122 'Downloading signed %s manifest URL' % manifest_id
,
134 for video
in (info
.get('videos') or []):
135 if video
.get('statut') != 'ONLINE':
137 if not video
.get('url'):
142 for device_type
in ['desktop', 'mobile']:
143 fallback_info
= self
._download
_json
(
144 'https://player.webservices.francetelevisions.fr/v1/videos/%s' % video_id
,
145 video_id
, 'Downloading fallback %s video JSON' % device_type
, query
={
146 'device_type': device_type
,
150 if fallback_info
and fallback_info
.get('video'):
151 videos
.append(fallback_info
['video'])
156 video_url
= video
.get('url')
161 video
, lambda x
: x
['plages_ouverture'][0]['direct'], bool) is True
162 or video
.get('is_live') is True
163 or '/live.francetv.fr/' in video_url
)
164 format_id
= video
.get('format')
165 ext
= determine_ext(video_url
)
168 # See https://github.com/ytdl-org/youtube-dl/issues/3963
169 # m3u8 urls work fine
171 formats
.extend(self
._extract
_f
4m
_formats
(
172 sign(video_url
, format_id
) + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44',
173 video_id
, f4m_id
=format_id
, fatal
=False))
175 m3u8_fmts
, m3u8_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
176 sign(video_url
, format_id
), video_id
, 'mp4',
177 entry_protocol
='m3u8_native', m3u8_id
=format_id
,
179 formats
.extend(m3u8_fmts
)
180 subtitles
= self
._merge
_subtitles
(subtitles
, m3u8_subs
)
182 formats
.extend(self
._extract
_mpd
_formats
(
183 sign(video_url
, format_id
), video_id
, mpd_id
=format_id
, fatal
=False))
184 elif video_url
.startswith('rtmp'):
187 'format_id': 'rtmp-%s' % format_id
,
191 if self
._is
_valid
_url
(video_url
, video_id
, format_id
):
194 'format_id': format_id
,
197 self
._sort
_formats
(formats
)
199 title
= info
['titre']
200 subtitle
= info
.get('sous_titre')
202 title
+= ' - %s' % subtitle
203 title
= title
.strip()
205 subtitles
.setdefault('fr', []).extend(
207 'url': subformat
['url'],
208 'ext': subformat
.get('format'),
209 } for subformat
in info
.get('subtitles', []) if subformat
.get('url')]
214 'title': self
._live
_title
(title
) if is_live
else title
,
215 'description': clean_html(info
.get('synopsis')),
216 'thumbnail': urljoin('https://sivideo.webservices.francetelevisions.fr', info
.get('image')),
217 'duration': int_or_none(info
.get('real_duration')) or parse_duration(info
.get('duree')),
218 'timestamp': int_or_none(try_get(info
, lambda x
: x
['diffusion']['timestamp'])),
221 'subtitles': subtitles
,
224 def _real_extract(self
, url
):
225 mobj
= re
.match(self
._VALID
_URL
, url
)
226 video_id
= mobj
.group('id')
227 catalog
= mobj
.group('catalog')
230 qs
= compat_urlparse
.parse_qs(compat_urlparse
.urlparse(url
).query
)
231 video_id
= qs
.get('idDiffusion', [None])[0]
232 catalog
= qs
.get('catalogue', [None])[0]
234 raise ExtractorError('Invalid URL', expected
=True)
236 return self
._extract
_video
(video_id
, catalog
)
239 class FranceTVSiteIE(FranceTVBaseInfoExtractor
):
240 _VALID_URL
= r
'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
243 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
245 'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1',
247 'title': '13h15, le dimanche... - Les mystères de Jésus',
248 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
249 'timestamp': 1502623500,
250 'upload_date': '20170813',
253 'skip_download': True,
255 'add_ie': [FranceTVIE
.ie_key()],
258 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
259 'only_matching': True,
262 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
263 'only_matching': True,
266 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
267 'only_matching': True,
270 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
271 'only_matching': True,
274 'url': 'https://www.france.tv/france-2/direct.html',
275 'only_matching': True,
277 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
278 'only_matching': True,
280 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
281 'only_matching': True,
283 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
284 'only_matching': True,
286 'url': 'https://www.france.tv/142749-rouge-sang.html',
287 'only_matching': True,
290 'url': 'https://www.france.tv/france-3/direct.html',
291 'only_matching': True,
294 def _real_extract(self
, url
):
295 display_id
= self
._match
_id
(url
)
297 webpage
= self
._download
_webpage
(url
, display_id
)
300 video_id
= self
._search
_regex
(
301 r
'(?:data-main-video\s*=|videoId["\']?\s
*[:=])\s
*(["\'])(?P<id>(?:(?!\1).)+)\1',
302 webpage, 'video id', default=None, group='id')
305 video_id, catalogue = self._html_search_regex(
306 r'(?:href=|player\.setVideo\(\s*)"http
://videos?\
.francetv\
.fr
/video
/([^
@]+@[^
"]+)"',
307 webpage, 'video ID
').split('@')
309 return self._make_url_result(video_id, catalogue)
312 class FranceTVEmbedIE(FranceTVBaseInfoExtractor):
313 _VALID_URL = r'https?
://embed\
.francetv\
.fr
/*\?.*?
\bue
=(?P
<id>[^
&]+)'
316 'url
': 'http
://embed
.francetv
.fr
/?ue
=7fd581a2ccf59d2fc5719c5c13cf6961
',
320 'title
': 'Le Pen Reims
',
321 'upload_date
': '20170505',
322 'timestamp
': 1493981780,
326 'skip_download
': True,
328 'add_ie
': [FranceTVIE.ie_key()],
331 def _real_extract(self, url):
332 video_id = self._match_id(url)
334 video = self._download_json(
335 'http
://api
-embed
.webservices
.francetelevisions
.fr
/key
/%s' % video_id,
338 return self._make_url_result(video['video_id
'], video.get('catalog
'))
341 class FranceTVInfoIE(FranceTVBaseInfoExtractor):
342 IE_NAME = 'francetvinfo
.fr
'
343 _VALID_URL = r'https?
://(?
:www|mobile|france3
-regions
)\
.francetvinfo\
.fr
/(?
:[^
/]+/)*(?P
<id>[^
/?
#&.]+)'
346 'url': 'https://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-jeudi-22-aout-2019_3561461.html',
348 'id': 'd12458ee-5062-48fe-bfdd-a30d6a01b793',
351 'upload_date': '20190822',
352 'timestamp': 1566510900,
353 'description': 'md5:72d167097237701d6e8452ff03b83c00',
359 'skip_download': True,
361 'add_ie': [FranceTVIE
.ie_key()],
363 'note': 'Only an image exists in initial webpage instead of the video',
364 'url': 'https://www.francetvinfo.fr/sante/maladie/coronavirus/covid-19-en-inde-une-situation-catastrophique-a-new-dehli_4381095.html',
366 'id': '7d204c9e-a2d3-11eb-9e4c-000d3a23d482',
368 'title': 'Covid-19 : une situation catastrophique à New Dehli',
371 'timestamp': 1619028518,
372 'upload_date': '20210421',
375 'skip_download': True,
377 'add_ie': [FranceTVIE
.ie_key()],
379 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
380 'only_matching': True,
382 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
383 'only_matching': True,
385 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
386 'only_matching': True,
389 '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',
390 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
394 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
395 'description': 'Au lendemain de la victoire du "oui" au référendum sur l\'aéroport de Notre-Dame-des-Landes, l\'ancienne ministre écologiste est l\'invitée de Patrick Cohen. Plus d\'info : https://www.franceinter.fr/emissions/le-7-9/le-7-9-27-juin-2016',
396 'timestamp': 1467011958,
397 'upload_date': '20160627',
398 'uploader': 'France Inter',
399 'uploader_id': 'x2q2ez',
401 'add_ie': ['Dailymotion'],
403 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
404 'only_matching': True,
407 def _real_extract(self
, url
):
408 display_id
= self
._match
_id
(url
)
410 webpage
= self
._download
_webpage
(url
, display_id
)
412 dailymotion_urls
= DailymotionIE
._extract
_urls
(webpage
)
414 return self
.playlist_result([
415 self
.url_result(dailymotion_url
, DailymotionIE
.ie_key())
416 for dailymotion_url
in dailymotion_urls
])
418 video_id
= self
._search
_regex
(
419 (r
'player\.load[^;]+src:\s*["\']([^
"\']+)',
420 r'id-video=([^@]+@[^"]+)',
421 r'<a
[^
>]+href
="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"',
422 r'data-id=["\']([\da
-f
]{8}
-[\da
-f
]{4}
-[\da
-f
]{4}
-[\da
-f
]{4}
-[\da
-f
]{12}
)',
423 r'<figure
[^
>]+id=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'),
426 return self._make_url_result(video_id)
429 class FranceTVInfoSportIE(FranceTVBaseInfoExtractor):
430 IE_NAME = 'sport.francetvinfo.fr'
431 _VALID_URL = r'https?://sport\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&]+)'
433 'url': 'https://sport.francetvinfo.fr/les-jeux-olympiques/retour-sur-les-meilleurs-moments-de-pyeongchang-2018',
435 'id': '6e49080e-3f45-11e8-b459-000d3a2439ea',
437 'title': 'Retour sur les meilleurs moments de Pyeongchang 2018',
438 'timestamp': 1523639962,
439 'upload_date': '20180413',
442 'skip_download': True,
444 'add_ie': [FranceTVIE.ie_key()],
447 def _real_extract(self, url):
448 display_id = self._match_id(url)
449 webpage = self._download_webpage(url, display_id)
450 video_id = self._search_regex(r'data-video="([^
"]+)"', webpage, 'video_id
')
451 return self._make_url_result(video_id, 'Sport
-web
')
454 class GenerationWhatIE(InfoExtractor):
455 IE_NAME = 'france2
.fr
:generation
-what
'
456 _VALID_URL = r'https?
://generation
-what\
.francetv\
.fr
/[^
/]+/video
/(?P
<id>[^
/?
#&]+)'
459 'url': 'http://generation-what.francetv.fr/portrait/video/present-arms',
463 'title': 'Generation What - Garde à vous - FRA',
464 'uploader': 'Generation What',
465 'uploader_id': 'UCHH9p1eetWCgt4kXBYCb3_w',
466 'upload_date': '20160411',
469 'skip_download': True,
471 'add_ie': ['Youtube'],
473 'url': 'http://generation-what.francetv.fr/europe/video/present-arms',
474 'only_matching': True,
477 def _real_extract(self
, url
):
478 display_id
= self
._match
_id
(url
)
480 webpage
= self
._download
_webpage
(url
, display_id
)
482 youtube_id
= self
._search
_regex
(
483 r
"window\.videoURL\s*=\s*'([0-9A-Za-z_-]{11})';",
484 webpage
, 'youtube id')
486 return self
.url_result(youtube_id
, ie
='Youtube', video_id
=youtube_id
)
489 class CultureboxIE(FranceTVBaseInfoExtractor
):
490 _VALID_URL
= r
'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&]+)'
493 'url': 'https://culturebox.francetvinfo.fr/opera-classique/musique-classique/c-est-baroque/concerts/cantates-bwv-4-106-et-131-de-bach-par-raphael-pichon-57-268689',
497 'title': 'Cantates BWV 4, 106 et 131 de Bach par Raphaël Pichon 5/7',
498 'description': 'md5:19c44af004b88219f4daa50fa9a351d4',
499 'upload_date': '20180206',
500 'timestamp': 1517945220,
504 'skip_download': True,
506 'add_ie': [FranceTVIE
.ie_key()],
509 def _real_extract(self
, url
):
510 display_id
= self
._match
_id
(url
)
512 webpage
= self
._download
_webpage
(url
, display_id
)
514 if ">Ce live n'est plus disponible en replay<" in webpage
:
515 raise ExtractorError(
516 'Video %s is not available' % display_id
, expected
=True)
518 video_id
, catalogue
= self
._search
_regex
(
519 r
'["\'>]https?
://videos\
.francetv\
.fr
/video
/([^
@]+@.+?
)["\'<]',
520 webpage, 'video id').split('@')
522 return self._make_url_result(video_id, catalogue)
525 class FranceTVJeunesseIE(FranceTVBaseInfoExtractor):
526 _VALID_URL = r'(?P<url>https?://(?:www\.)?(?:zouzous|ludo)\.fr/heros/(?P<id>[^/?#&]+))'
529 'url': 'https://www.zouzous.fr/heros/simon',
535 'url': 'https://www.ludo.fr/heros/ninjago',
539 'playlist_count': 10,
541 'url': 'https://www.zouzous.fr/heros/simon?abc',
542 'only_matching': True,
545 def _real_extract(self, url):
546 mobj = re.match(self._VALID_URL, url)
547 playlist_id = mobj.group('id')
549 playlist = self._download_json(
550 '%s/%s' % (mobj.group('url'), 'playlist'), playlist_id)
552 if not playlist.get('count'):
553 raise ExtractorError(
554 '%s is not available' % playlist_id, expected=True)
557 for item in playlist['items']:
558 identity = item.get('identity')
559 if identity and isinstance(identity, compat_str):
560 entries.append(self._make_url_result(identity))
562 return self.playlist_result(entries, playlist_id)