You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
18 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. clean_html,
  11. determine_ext,
  12. ExtractorError,
  13. int_or_none,
  14. parse_duration,
  15. try_get,
  16. )
  17. from .dailymotion import DailymotionIE
  18. class FranceTVBaseInfoExtractor(InfoExtractor):
  19. def _make_url_result(self, video_or_full_id, catalog=None):
  20. full_id = 'francetv:%s' % video_or_full_id
  21. if '@' not in video_or_full_id and catalog:
  22. full_id += '@%s' % catalog
  23. return self.url_result(
  24. full_id, ie=FranceTVIE.ie_key(),
  25. video_id=video_or_full_id.split('@')[0])
  26. class FranceTVIE(InfoExtractor):
  27. _VALID_URL = r'''(?x)
  28. (?:
  29. https?://
  30. sivideo\.webservices\.francetelevisions\.fr/tools/getInfosOeuvre/v2/\?
  31. .*?\bidDiffusion=[^&]+|
  32. (?:
  33. https?://videos\.francetv\.fr/video/|
  34. francetv:
  35. )
  36. (?P<id>[^@]+)(?:@(?P<catalog>.+))?
  37. )
  38. '''
  39. _TESTS = [{
  40. # without catalog
  41. 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=162311093&callback=_jsonp_loader_callback_request_0',
  42. 'md5': 'c2248a8de38c4e65ea8fae7b5df2d84f',
  43. 'info_dict': {
  44. 'id': '162311093',
  45. 'ext': 'mp4',
  46. 'title': '13h15, le dimanche... - Les mystères de Jésus',
  47. 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
  48. 'timestamp': 1502623500,
  49. 'upload_date': '20170813',
  50. },
  51. }, {
  52. # with catalog
  53. 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=NI_1004933&catalogue=Zouzous&callback=_jsonp_loader_callback_request_4',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'http://videos.francetv.fr/video/NI_657393@Regions',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'francetv:162311093',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'francetv:NI_1004933@Zouzous',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'francetv:NI_983319@Info-web',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'francetv:NI_983319',
  69. 'only_matching': True,
  70. }, {
  71. 'url': 'francetv:NI_657393@Regions',
  72. 'only_matching': True,
  73. }, {
  74. # france-3 live
  75. 'url': 'francetv:SIM_France3',
  76. 'only_matching': True,
  77. }]
  78. def _extract_video(self, video_id, catalogue=None):
  79. # Videos are identified by idDiffusion so catalogue part is optional.
  80. # However when provided, some extra formats may be returned so we pass
  81. # it if available.
  82. info = self._download_json(
  83. 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/',
  84. video_id, 'Downloading video JSON', query={
  85. 'idDiffusion': video_id,
  86. 'catalogue': catalogue or '',
  87. })
  88. if info.get('status') == 'NOK':
  89. raise ExtractorError(
  90. '%s returned error: %s' % (self.IE_NAME, info['message']),
  91. expected=True)
  92. allowed_countries = info['videos'][0].get('geoblocage')
  93. if allowed_countries:
  94. georestricted = True
  95. geo_info = self._download_json(
  96. 'http://geo.francetv.fr/ws/edgescape.json', video_id,
  97. 'Downloading geo restriction info')
  98. country = geo_info['reponse']['geo_info']['country_code']
  99. if country not in allowed_countries:
  100. raise ExtractorError(
  101. 'The video is not available from your location',
  102. expected=True)
  103. else:
  104. georestricted = False
  105. def sign(manifest_url, manifest_id):
  106. for host in ('hdfauthftv-a.akamaihd.net', 'hdfauth.francetv.fr'):
  107. signed_url = self._download_webpage(
  108. 'https://%s/esi/TA' % host, video_id,
  109. 'Downloading signed %s manifest URL' % manifest_id,
  110. fatal=False, query={
  111. 'url': manifest_url,
  112. })
  113. if (signed_url and isinstance(signed_url, compat_str) and
  114. re.search(r'^(?:https?:)?//', signed_url)):
  115. return signed_url
  116. return manifest_url
  117. is_live = None
  118. formats = []
  119. for video in info['videos']:
  120. if video['statut'] != 'ONLINE':
  121. continue
  122. video_url = video['url']
  123. if not video_url:
  124. continue
  125. if is_live is None:
  126. is_live = (try_get(
  127. video, lambda x: x['plages_ouverture'][0]['direct'],
  128. bool) is True) or '/live.francetv.fr/' in video_url
  129. format_id = video['format']
  130. ext = determine_ext(video_url)
  131. if ext == 'f4m':
  132. if georestricted:
  133. # See https://github.com/rg3/youtube-dl/issues/3963
  134. # m3u8 urls work fine
  135. continue
  136. formats.extend(self._extract_f4m_formats(
  137. sign(video_url, format_id) + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44',
  138. video_id, f4m_id=format_id, fatal=False))
  139. elif ext == 'm3u8':
  140. formats.extend(self._extract_m3u8_formats(
  141. sign(video_url, format_id), video_id, 'mp4',
  142. entry_protocol='m3u8_native', m3u8_id=format_id,
  143. fatal=False))
  144. elif video_url.startswith('rtmp'):
  145. formats.append({
  146. 'url': video_url,
  147. 'format_id': 'rtmp-%s' % format_id,
  148. 'ext': 'flv',
  149. })
  150. else:
  151. if self._is_valid_url(video_url, video_id, format_id):
  152. formats.append({
  153. 'url': video_url,
  154. 'format_id': format_id,
  155. })
  156. self._sort_formats(formats)
  157. title = info['titre']
  158. subtitle = info.get('sous_titre')
  159. if subtitle:
  160. title += ' - %s' % subtitle
  161. title = title.strip()
  162. subtitles = {}
  163. subtitles_list = [{
  164. 'url': subformat['url'],
  165. 'ext': subformat.get('format'),
  166. } for subformat in info.get('subtitles', []) if subformat.get('url')]
  167. if subtitles_list:
  168. subtitles['fr'] = subtitles_list
  169. return {
  170. 'id': video_id,
  171. 'title': self._live_title(title) if is_live else title,
  172. 'description': clean_html(info['synopsis']),
  173. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
  174. 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
  175. 'timestamp': int_or_none(info['diffusion']['timestamp']),
  176. 'is_live': is_live,
  177. 'formats': formats,
  178. 'subtitles': subtitles,
  179. }
  180. def _real_extract(self, url):
  181. mobj = re.match(self._VALID_URL, url)
  182. video_id = mobj.group('id')
  183. catalog = mobj.group('catalog')
  184. if not video_id:
  185. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  186. video_id = qs.get('idDiffusion', [None])[0]
  187. catalog = qs.get('catalogue', [None])[0]
  188. if not video_id:
  189. raise ExtractorError('Invalid URL', expected=True)
  190. return self._extract_video(video_id, catalog)
  191. class FranceTVSiteIE(FranceTVBaseInfoExtractor):
  192. _VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
  193. _TESTS = [{
  194. 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
  195. 'info_dict': {
  196. 'id': '162311093',
  197. 'ext': 'mp4',
  198. 'title': '13h15, le dimanche... - Les mystères de Jésus',
  199. 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
  200. 'timestamp': 1502623500,
  201. 'upload_date': '20170813',
  202. },
  203. 'params': {
  204. 'skip_download': True,
  205. },
  206. 'add_ie': [FranceTVIE.ie_key()],
  207. }, {
  208. # france3
  209. 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
  210. 'only_matching': True,
  211. }, {
  212. # france4
  213. 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
  214. 'only_matching': True,
  215. }, {
  216. # france5
  217. 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
  218. 'only_matching': True,
  219. }, {
  220. # franceo
  221. 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
  222. 'only_matching': True,
  223. }, {
  224. # france2 live
  225. 'url': 'https://www.france.tv/france-2/direct.html',
  226. 'only_matching': True,
  227. }, {
  228. 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
  229. 'only_matching': True,
  230. }, {
  231. 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
  232. 'only_matching': True,
  233. }, {
  234. 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
  235. 'only_matching': True,
  236. }, {
  237. 'url': 'https://www.france.tv/142749-rouge-sang.html',
  238. 'only_matching': True,
  239. }, {
  240. # france-3 live
  241. 'url': 'https://www.france.tv/france-3/direct.html',
  242. 'only_matching': True,
  243. }]
  244. def _real_extract(self, url):
  245. display_id = self._match_id(url)
  246. webpage = self._download_webpage(url, display_id)
  247. catalogue = None
  248. video_id = self._search_regex(
  249. r'data-main-video=(["\'])(?P<id>(?:(?!\1).)+)\1',
  250. webpage, 'video id', default=None, group='id')
  251. if not video_id:
  252. video_id, catalogue = self._html_search_regex(
  253. r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  254. webpage, 'video ID').split('@')
  255. return self._make_url_result(video_id, catalogue)
  256. class FranceTVEmbedIE(FranceTVBaseInfoExtractor):
  257. _VALID_URL = r'https?://embed\.francetv\.fr/*\?.*?\bue=(?P<id>[^&]+)'
  258. _TESTS = [{
  259. 'url': 'http://embed.francetv.fr/?ue=7fd581a2ccf59d2fc5719c5c13cf6961',
  260. 'info_dict': {
  261. 'id': 'NI_983319',
  262. 'ext': 'mp4',
  263. 'title': 'Le Pen Reims',
  264. 'upload_date': '20170505',
  265. 'timestamp': 1493981780,
  266. 'duration': 16,
  267. },
  268. 'params': {
  269. 'skip_download': True,
  270. },
  271. 'add_ie': [FranceTVIE.ie_key()],
  272. }]
  273. def _real_extract(self, url):
  274. video_id = self._match_id(url)
  275. video = self._download_json(
  276. 'http://api-embed.webservices.francetelevisions.fr/key/%s' % video_id,
  277. video_id)
  278. return self._make_url_result(video['video_id'], video.get('catalog'))
  279. class FranceTVInfoIE(FranceTVBaseInfoExtractor):
  280. IE_NAME = 'francetvinfo.fr'
  281. _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&.]+)'
  282. _TESTS = [{
  283. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  284. 'info_dict': {
  285. 'id': '84981923',
  286. 'ext': 'mp4',
  287. 'title': 'Soir 3',
  288. 'upload_date': '20130826',
  289. 'timestamp': 1377548400,
  290. 'subtitles': {
  291. 'fr': 'mincount:2',
  292. },
  293. },
  294. 'params': {
  295. 'skip_download': True,
  296. },
  297. 'add_ie': [FranceTVIE.ie_key()],
  298. }, {
  299. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  300. 'only_matching': True,
  301. }, {
  302. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  303. 'only_matching': True,
  304. }, {
  305. 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
  306. 'only_matching': True,
  307. }, {
  308. # Dailymotion embed
  309. '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',
  310. 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
  311. 'info_dict': {
  312. 'id': 'x4iiko0',
  313. 'ext': 'mp4',
  314. 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
  315. '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',
  316. 'timestamp': 1467011958,
  317. 'upload_date': '20160627',
  318. 'uploader': 'France Inter',
  319. 'uploader_id': 'x2q2ez',
  320. },
  321. 'add_ie': ['Dailymotion'],
  322. }, {
  323. 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
  324. 'only_matching': True,
  325. }]
  326. def _real_extract(self, url):
  327. display_id = self._match_id(url)
  328. webpage = self._download_webpage(url, display_id)
  329. dailymotion_urls = DailymotionIE._extract_urls(webpage)
  330. if dailymotion_urls:
  331. return self.playlist_result([
  332. self.url_result(dailymotion_url, DailymotionIE.ie_key())
  333. for dailymotion_url in dailymotion_urls])
  334. video_id, catalogue = self._search_regex(
  335. (r'id-video=([^@]+@[^"]+)',
  336. r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"'),
  337. webpage, 'video id').split('@')
  338. return self._make_url_result(video_id, catalogue)
  339. class GenerationWhatIE(InfoExtractor):
  340. IE_NAME = 'france2.fr:generation-what'
  341. _VALID_URL = r'https?://generation-what\.francetv\.fr/[^/]+/video/(?P<id>[^/?#&]+)'
  342. _TESTS = [{
  343. 'url': 'http://generation-what.francetv.fr/portrait/video/present-arms',
  344. 'info_dict': {
  345. 'id': 'wtvKYUG45iw',
  346. 'ext': 'mp4',
  347. 'title': 'Generation What - Garde à vous - FRA',
  348. 'uploader': 'Generation What',
  349. 'uploader_id': 'UCHH9p1eetWCgt4kXBYCb3_w',
  350. 'upload_date': '20160411',
  351. },
  352. 'params': {
  353. 'skip_download': True,
  354. },
  355. 'add_ie': ['Youtube'],
  356. }, {
  357. 'url': 'http://generation-what.francetv.fr/europe/video/present-arms',
  358. 'only_matching': True,
  359. }]
  360. def _real_extract(self, url):
  361. display_id = self._match_id(url)
  362. webpage = self._download_webpage(url, display_id)
  363. youtube_id = self._search_regex(
  364. r"window\.videoURL\s*=\s*'([0-9A-Za-z_-]{11})';",
  365. webpage, 'youtube id')
  366. return self.url_result(youtube_id, ie='Youtube', video_id=youtube_id)
  367. class CultureboxIE(FranceTVBaseInfoExtractor):
  368. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  369. _TESTS = [{
  370. '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',
  371. 'info_dict': {
  372. 'id': 'EV_134885',
  373. 'ext': 'mp4',
  374. 'title': 'Cantates BWV 4, 106 et 131 de Bach par Raphaël Pichon 5/7',
  375. 'description': 'md5:19c44af004b88219f4daa50fa9a351d4',
  376. 'upload_date': '20180206',
  377. 'timestamp': 1517945220,
  378. 'duration': 5981,
  379. },
  380. 'params': {
  381. 'skip_download': True,
  382. },
  383. 'add_ie': [FranceTVIE.ie_key()],
  384. }]
  385. def _real_extract(self, url):
  386. display_id = self._match_id(url)
  387. webpage = self._download_webpage(url, display_id)
  388. if ">Ce live n'est plus disponible en replay<" in webpage:
  389. raise ExtractorError(
  390. 'Video %s is not available' % display_id, expected=True)
  391. video_id, catalogue = self._search_regex(
  392. r'["\'>]https?://videos\.francetv\.fr/video/([^@]+@.+?)["\'<]',
  393. webpage, 'video id').split('@')
  394. return self._make_url_result(video_id, catalogue)
  395. class FranceTVJeunesseIE(FranceTVBaseInfoExtractor):
  396. _VALID_URL = r'(?P<url>https?://(?:www\.)?(?:zouzous|ludo)\.fr/heros/(?P<id>[^/?#&]+))'
  397. _TESTS = [{
  398. 'url': 'https://www.zouzous.fr/heros/simon',
  399. 'info_dict': {
  400. 'id': 'simon',
  401. },
  402. 'playlist_count': 9,
  403. }, {
  404. 'url': 'https://www.ludo.fr/heros/ninjago',
  405. 'info_dict': {
  406. 'id': 'ninjago',
  407. },
  408. 'playlist_count': 10,
  409. }, {
  410. 'url': 'https://www.zouzous.fr/heros/simon?abc',
  411. 'only_matching': True,
  412. }]
  413. def _real_extract(self, url):
  414. mobj = re.match(self._VALID_URL, url)
  415. playlist_id = mobj.group('id')
  416. playlist = self._download_json(
  417. '%s/%s' % (mobj.group('url'), 'playlist'), playlist_id)
  418. if not playlist.get('count'):
  419. raise ExtractorError(
  420. '%s is not available' % playlist_id, expected=True)
  421. entries = []
  422. for item in playlist['items']:
  423. identity = item.get('identity')
  424. if identity and isinstance(identity, compat_str):
  425. entries.append(self._make_url_result(identity))
  426. return self.playlist_result(entries, playlist_id)