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.

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