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.

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