francetv.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. def _real_extract(self, url):
  149. display_id = self._match_id(url)
  150. webpage = self._download_webpage(url, display_id)
  151. catalogue = None
  152. video_id = self._search_regex(
  153. r'data-main-video=(["\'])(?P<id>(?:(?!\1).)+)\1',
  154. webpage, 'video id', default=None, group='id')
  155. if not video_id:
  156. video_id, catalogue = self._html_search_regex(
  157. r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  158. webpage, 'video ID').split('@')
  159. return self._extract_video(video_id, catalogue)
  160. class FranceTVEmbedIE(FranceTVBaseInfoExtractor):
  161. _VALID_URL = r'https?://embed\.francetv\.fr/*\?.*?\bue=(?P<id>[^&]+)'
  162. _TEST = {
  163. 'url': 'http://embed.francetv.fr/?ue=7fd581a2ccf59d2fc5719c5c13cf6961',
  164. 'info_dict': {
  165. 'id': 'NI_983319',
  166. 'ext': 'mp4',
  167. 'title': 'Le Pen Reims',
  168. 'upload_date': '20170505',
  169. 'timestamp': 1493981780,
  170. 'duration': 16,
  171. },
  172. }
  173. def _real_extract(self, url):
  174. video_id = self._match_id(url)
  175. video = self._download_json(
  176. 'http://api-embed.webservices.francetelevisions.fr/key/%s' % video_id,
  177. video_id)
  178. return self._extract_video(video['video_id'], video.get('catalog'))
  179. class FranceTVInfoIE(FranceTVBaseInfoExtractor):
  180. IE_NAME = 'francetvinfo.fr'
  181. _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<title>[^/?#&.]+)'
  182. _TESTS = [{
  183. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  184. 'info_dict': {
  185. 'id': '84981923',
  186. 'ext': 'mp4',
  187. 'title': 'Soir 3',
  188. 'upload_date': '20130826',
  189. 'timestamp': 1377548400,
  190. 'subtitles': {
  191. 'fr': 'mincount:2',
  192. },
  193. },
  194. 'params': {
  195. # m3u8 downloads
  196. 'skip_download': True,
  197. },
  198. }, {
  199. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  200. 'info_dict': {
  201. 'id': 'EV_20019',
  202. 'ext': 'mp4',
  203. 'title': 'Débat des candidats à la Commission européenne',
  204. 'description': 'Débat des candidats à la Commission européenne',
  205. },
  206. 'params': {
  207. 'skip_download': 'HLS (reqires ffmpeg)'
  208. },
  209. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  210. }, {
  211. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  212. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  213. 'info_dict': {
  214. 'id': 'NI_173343',
  215. 'ext': 'mp4',
  216. 'title': 'Les entreprises familiales : le secret de la réussite',
  217. 'thumbnail': r're:^https?://.*\.jpe?g$',
  218. 'timestamp': 1433273139,
  219. 'upload_date': '20150602',
  220. },
  221. 'params': {
  222. # m3u8 downloads
  223. 'skip_download': True,
  224. },
  225. }, {
  226. 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
  227. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  228. 'info_dict': {
  229. 'id': 'NI_657393',
  230. 'ext': 'mp4',
  231. 'title': 'Olivier Monthus, réalisateur de "Bretagne, le choix de l’Armor"',
  232. 'description': 'md5:a3264114c9d29aeca11ced113c37b16c',
  233. 'thumbnail': r're:^https?://.*\.jpe?g$',
  234. 'timestamp': 1458300695,
  235. 'upload_date': '20160318',
  236. },
  237. 'params': {
  238. 'skip_download': True,
  239. },
  240. }, {
  241. # Dailymotion embed
  242. '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',
  243. 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
  244. 'info_dict': {
  245. 'id': 'x4iiko0',
  246. 'ext': 'mp4',
  247. 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
  248. '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',
  249. 'timestamp': 1467011958,
  250. 'upload_date': '20160627',
  251. 'uploader': 'France Inter',
  252. 'uploader_id': 'x2q2ez',
  253. },
  254. 'add_ie': ['Dailymotion'],
  255. }, {
  256. 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
  257. 'only_matching': True,
  258. }]
  259. def _real_extract(self, url):
  260. mobj = re.match(self._VALID_URL, url)
  261. page_title = mobj.group('title')
  262. webpage = self._download_webpage(url, page_title)
  263. dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
  264. if dmcloud_url:
  265. return self.url_result(dmcloud_url, DailymotionCloudIE.ie_key())
  266. dailymotion_urls = DailymotionIE._extract_urls(webpage)
  267. if dailymotion_urls:
  268. return self.playlist_result([
  269. self.url_result(dailymotion_url, DailymotionIE.ie_key())
  270. for dailymotion_url in dailymotion_urls])
  271. video_id, catalogue = self._search_regex(
  272. (r'id-video=([^@]+@[^"]+)',
  273. r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"'),
  274. webpage, 'video id').split('@')
  275. return self._extract_video(video_id, catalogue)
  276. class GenerationQuoiIE(InfoExtractor):
  277. IE_NAME = 'france2.fr:generation-quoi'
  278. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
  279. _TEST = {
  280. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  281. 'info_dict': {
  282. 'id': 'k7FJX8VBcvvLmX4wA5Q',
  283. 'ext': 'mp4',
  284. 'title': 'Génération Quoi - Garde à Vous',
  285. 'uploader': 'Génération Quoi',
  286. },
  287. 'params': {
  288. # It uses Dailymotion
  289. 'skip_download': True,
  290. },
  291. }
  292. def _real_extract(self, url):
  293. display_id = self._match_id(url)
  294. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
  295. info_json = self._download_webpage(info_url, display_id)
  296. info = json.loads(info_json)
  297. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  298. ie='Dailymotion')
  299. class CultureboxIE(FranceTVBaseInfoExtractor):
  300. IE_NAME = 'culturebox.francetvinfo.fr'
  301. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  302. _TEST = {
  303. 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
  304. 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
  305. 'info_dict': {
  306. 'id': 'EV_50111',
  307. 'ext': 'flv',
  308. 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
  309. 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
  310. 'upload_date': '20150320',
  311. 'timestamp': 1426892400,
  312. 'duration': 2760.9,
  313. },
  314. }
  315. def _real_extract(self, url):
  316. mobj = re.match(self._VALID_URL, url)
  317. name = mobj.group('name')
  318. webpage = self._download_webpage(url, name)
  319. if ">Ce live n'est plus disponible en replay<" in webpage:
  320. raise ExtractorError('Video %s is not available' % name, expected=True)
  321. video_id, catalogue = self._search_regex(
  322. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  323. return self._extract_video(video_id, catalogue)