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