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.

368 lines
14 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import compat_urlparse
  7. from ..utils import (
  8. clean_html,
  9. ExtractorError,
  10. int_or_none,
  11. parse_duration,
  12. determine_ext,
  13. )
  14. from .dailymotion import (
  15. DailymotionIE,
  16. DailymotionCloudIE,
  17. )
  18. class FranceTVBaseInfoExtractor(InfoExtractor):
  19. def _extract_video(self, video_id, catalogue=None):
  20. info = self._download_json(
  21. 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/',
  22. video_id, 'Downloading video JSON', query={
  23. 'idDiffusion': video_id,
  24. 'catalogue': catalogue or '',
  25. })
  26. if info.get('status') == 'NOK':
  27. raise ExtractorError(
  28. '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True)
  29. allowed_countries = info['videos'][0].get('geoblocage')
  30. if allowed_countries:
  31. georestricted = True
  32. geo_info = self._download_json(
  33. 'http://geo.francetv.fr/ws/edgescape.json', video_id,
  34. 'Downloading geo restriction info')
  35. country = geo_info['reponse']['geo_info']['country_code']
  36. if country not in allowed_countries:
  37. raise ExtractorError(
  38. 'The video is not available from your location',
  39. expected=True)
  40. else:
  41. georestricted = False
  42. formats = []
  43. for video in info['videos']:
  44. if video['statut'] != 'ONLINE':
  45. continue
  46. video_url = video['url']
  47. if not video_url:
  48. continue
  49. format_id = video['format']
  50. ext = determine_ext(video_url)
  51. if ext == 'f4m':
  52. if georestricted:
  53. # See https://github.com/rg3/youtube-dl/issues/3963
  54. # m3u8 urls work fine
  55. continue
  56. f4m_url = self._download_webpage(
  57. 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url,
  58. video_id, 'Downloading f4m manifest token', fatal=False)
  59. if f4m_url:
  60. formats.extend(self._extract_f4m_formats(
  61. f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44',
  62. video_id, f4m_id=format_id, fatal=False))
  63. elif ext == 'm3u8':
  64. formats.extend(self._extract_m3u8_formats(
  65. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  66. m3u8_id=format_id, fatal=False))
  67. elif video_url.startswith('rtmp'):
  68. formats.append({
  69. 'url': video_url,
  70. 'format_id': 'rtmp-%s' % format_id,
  71. 'ext': 'flv',
  72. })
  73. else:
  74. if self._is_valid_url(video_url, video_id, format_id):
  75. formats.append({
  76. 'url': video_url,
  77. 'format_id': format_id,
  78. })
  79. self._sort_formats(formats)
  80. title = info['titre']
  81. subtitle = info.get('sous_titre')
  82. if subtitle:
  83. title += ' - %s' % subtitle
  84. title = title.strip()
  85. subtitles = {}
  86. subtitles_list = [{
  87. 'url': subformat['url'],
  88. 'ext': subformat.get('format'),
  89. } for subformat in info.get('subtitles', []) if subformat.get('url')]
  90. if subtitles_list:
  91. subtitles['fr'] = subtitles_list
  92. return {
  93. 'id': video_id,
  94. 'title': title,
  95. 'description': clean_html(info['synopsis']),
  96. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
  97. 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
  98. 'timestamp': int_or_none(info['diffusion']['timestamp']),
  99. 'formats': formats,
  100. 'subtitles': subtitles,
  101. }
  102. class FranceTVIE(FranceTVBaseInfoExtractor):
  103. _VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
  104. _TESTS = [{
  105. 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
  106. 'info_dict': {
  107. 'id': '157550144',
  108. 'ext': 'mp4',
  109. 'title': '13h15, le dimanche... - Les mystères de Jésus',
  110. 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
  111. 'timestamp': 1494156300,
  112. 'upload_date': '20170507',
  113. },
  114. 'params': {
  115. # m3u8 downloads
  116. 'skip_download': True,
  117. },
  118. }, {
  119. # france3
  120. 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
  121. 'only_matching': True,
  122. }, {
  123. # france4
  124. 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
  125. 'only_matching': True,
  126. }, {
  127. # france5
  128. 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
  129. 'only_matching': True,
  130. }, {
  131. # franceo
  132. 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
  133. 'only_matching': True,
  134. }, {
  135. # france2 live
  136. 'url': 'https://www.france.tv/france-2/direct.html',
  137. 'only_matching': True,
  138. }, {
  139. 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
  140. 'only_matching': True,
  141. }, {
  142. 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
  143. 'only_matching': True,
  144. }, {
  145. 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
  146. 'only_matching': True,
  147. }, {
  148. 'url': 'https://www.france.tv/142749-rouge-sang.html',
  149. 'only_matching': True,
  150. }]
  151. def _real_extract(self, url):
  152. display_id = self._match_id(url)
  153. webpage = self._download_webpage(url, display_id)
  154. catalogue = None
  155. video_id = self._search_regex(
  156. r'data-main-video=(["\'])(?P<id>(?:(?!\1).)+)\1',
  157. webpage, 'video id', default=None, group='id')
  158. if not video_id:
  159. video_id, catalogue = self._html_search_regex(
  160. r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  161. webpage, 'video ID').split('@')
  162. return self._extract_video(video_id, catalogue)
  163. class FranceTVEmbedIE(FranceTVBaseInfoExtractor):
  164. _VALID_URL = r'https?://embed\.francetv\.fr/*\?.*?\bue=(?P<id>[^&]+)'
  165. _TEST = {
  166. 'url': 'http://embed.francetv.fr/?ue=7fd581a2ccf59d2fc5719c5c13cf6961',
  167. 'info_dict': {
  168. 'id': 'NI_983319',
  169. 'ext': 'mp4',
  170. 'title': 'Le Pen Reims',
  171. 'upload_date': '20170505',
  172. 'timestamp': 1493981780,
  173. 'duration': 16,
  174. },
  175. }
  176. def _real_extract(self, url):
  177. video_id = self._match_id(url)
  178. video = self._download_json(
  179. 'http://api-embed.webservices.francetelevisions.fr/key/%s' % video_id,
  180. video_id)
  181. return self._extract_video(video['video_id'], video.get('catalog'))
  182. class FranceTVInfoIE(FranceTVBaseInfoExtractor):
  183. IE_NAME = 'francetvinfo.fr'
  184. _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<title>[^/?#&.]+)'
  185. _TESTS = [{
  186. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  187. 'info_dict': {
  188. 'id': '84981923',
  189. 'ext': 'mp4',
  190. 'title': 'Soir 3',
  191. 'upload_date': '20130826',
  192. 'timestamp': 1377548400,
  193. 'subtitles': {
  194. 'fr': 'mincount:2',
  195. },
  196. },
  197. 'params': {
  198. # m3u8 downloads
  199. 'skip_download': True,
  200. },
  201. }, {
  202. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  203. 'info_dict': {
  204. 'id': 'EV_20019',
  205. 'ext': 'mp4',
  206. 'title': 'Débat des candidats à la Commission européenne',
  207. 'description': 'Débat des candidats à la Commission européenne',
  208. },
  209. 'params': {
  210. 'skip_download': 'HLS (reqires ffmpeg)'
  211. },
  212. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  213. }, {
  214. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  215. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  216. 'info_dict': {
  217. 'id': 'NI_173343',
  218. 'ext': 'mp4',
  219. 'title': 'Les entreprises familiales : le secret de la réussite',
  220. 'thumbnail': r're:^https?://.*\.jpe?g$',
  221. 'timestamp': 1433273139,
  222. 'upload_date': '20150602',
  223. },
  224. 'params': {
  225. # m3u8 downloads
  226. 'skip_download': True,
  227. },
  228. }, {
  229. 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
  230. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  231. 'info_dict': {
  232. 'id': 'NI_657393',
  233. 'ext': 'mp4',
  234. 'title': 'Olivier Monthus, réalisateur de "Bretagne, le choix de l’Armor"',
  235. 'description': 'md5:a3264114c9d29aeca11ced113c37b16c',
  236. 'thumbnail': r're:^https?://.*\.jpe?g$',
  237. 'timestamp': 1458300695,
  238. 'upload_date': '20160318',
  239. },
  240. 'params': {
  241. 'skip_download': True,
  242. },
  243. }, {
  244. # Dailymotion embed
  245. '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',
  246. 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
  247. 'info_dict': {
  248. 'id': 'x4iiko0',
  249. 'ext': 'mp4',
  250. 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
  251. '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',
  252. 'timestamp': 1467011958,
  253. 'upload_date': '20160627',
  254. 'uploader': 'France Inter',
  255. 'uploader_id': 'x2q2ez',
  256. },
  257. 'add_ie': ['Dailymotion'],
  258. }, {
  259. 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
  260. 'only_matching': True,
  261. }]
  262. def _real_extract(self, url):
  263. mobj = re.match(self._VALID_URL, url)
  264. page_title = mobj.group('title')
  265. webpage = self._download_webpage(url, page_title)
  266. dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
  267. if dmcloud_url:
  268. return self.url_result(dmcloud_url, DailymotionCloudIE.ie_key())
  269. dailymotion_urls = DailymotionIE._extract_urls(webpage)
  270. if dailymotion_urls:
  271. return self.playlist_result([
  272. self.url_result(dailymotion_url, DailymotionIE.ie_key())
  273. for dailymotion_url in dailymotion_urls])
  274. video_id, catalogue = self._search_regex(
  275. (r'id-video=([^@]+@[^"]+)',
  276. r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"'),
  277. webpage, 'video id').split('@')
  278. return self._extract_video(video_id, catalogue)
  279. class GenerationQuoiIE(InfoExtractor):
  280. IE_NAME = 'france2.fr:generation-quoi'
  281. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
  282. _TEST = {
  283. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  284. 'info_dict': {
  285. 'id': 'k7FJX8VBcvvLmX4wA5Q',
  286. 'ext': 'mp4',
  287. 'title': 'Génération Quoi - Garde à Vous',
  288. 'uploader': 'Génération Quoi',
  289. },
  290. 'params': {
  291. # It uses Dailymotion
  292. 'skip_download': True,
  293. },
  294. }
  295. def _real_extract(self, url):
  296. display_id = self._match_id(url)
  297. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
  298. info_json = self._download_webpage(info_url, display_id)
  299. info = json.loads(info_json)
  300. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  301. ie='Dailymotion')
  302. class CultureboxIE(FranceTVBaseInfoExtractor):
  303. IE_NAME = 'culturebox.francetvinfo.fr'
  304. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  305. _TEST = {
  306. 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
  307. 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
  308. 'info_dict': {
  309. 'id': 'EV_50111',
  310. 'ext': 'flv',
  311. 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
  312. 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
  313. 'upload_date': '20150320',
  314. 'timestamp': 1426892400,
  315. 'duration': 2760.9,
  316. },
  317. }
  318. def _real_extract(self, url):
  319. mobj = re.match(self._VALID_URL, url)
  320. name = mobj.group('name')
  321. webpage = self._download_webpage(url, name)
  322. if ">Ce live n'est plus disponible en replay<" in webpage:
  323. raise ExtractorError('Video %s is not available' % name, expected=True)
  324. video_id, catalogue = self._search_regex(
  325. r'"https?://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  326. return self._extract_video(video_id, catalogue)