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.

411 lines
16 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):
  20. info = self._download_json(
  21. 'http://webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=%s&catalogue=%s'
  22. % (video_id, catalogue),
  23. video_id, 'Downloading video JSON')
  24. if info.get('status') == 'NOK':
  25. raise ExtractorError(
  26. '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True)
  27. allowed_countries = info['videos'][0].get('geoblocage')
  28. if allowed_countries:
  29. georestricted = True
  30. geo_info = self._download_json(
  31. 'http://geo.francetv.fr/ws/edgescape.json', video_id,
  32. 'Downloading geo restriction info')
  33. country = geo_info['reponse']['geo_info']['country_code']
  34. if country not in allowed_countries:
  35. raise ExtractorError(
  36. 'The video is not available from your location',
  37. expected=True)
  38. else:
  39. georestricted = False
  40. formats = []
  41. for video in info['videos']:
  42. if video['statut'] != 'ONLINE':
  43. continue
  44. video_url = video['url']
  45. if not video_url:
  46. continue
  47. format_id = video['format']
  48. ext = determine_ext(video_url)
  49. if ext == 'f4m':
  50. if georestricted:
  51. # See https://github.com/rg3/youtube-dl/issues/3963
  52. # m3u8 urls work fine
  53. continue
  54. f4m_url = self._download_webpage(
  55. 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url,
  56. video_id, 'Downloading f4m manifest token', fatal=False)
  57. if f4m_url:
  58. formats.extend(self._extract_f4m_formats(
  59. f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44',
  60. video_id, f4m_id=format_id, fatal=False))
  61. elif ext == 'm3u8':
  62. formats.extend(self._extract_m3u8_formats(
  63. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  64. m3u8_id=format_id, fatal=False))
  65. elif video_url.startswith('rtmp'):
  66. formats.append({
  67. 'url': video_url,
  68. 'format_id': 'rtmp-%s' % format_id,
  69. 'ext': 'flv',
  70. })
  71. else:
  72. if self._is_valid_url(video_url, video_id, format_id):
  73. formats.append({
  74. 'url': video_url,
  75. 'format_id': format_id,
  76. })
  77. self._sort_formats(formats)
  78. title = info['titre']
  79. subtitle = info.get('sous_titre')
  80. if subtitle:
  81. title += ' - %s' % subtitle
  82. title = title.strip()
  83. subtitles = {}
  84. subtitles_list = [{
  85. 'url': subformat['url'],
  86. 'ext': subformat.get('format'),
  87. } for subformat in info.get('subtitles', []) if subformat.get('url')]
  88. if subtitles_list:
  89. subtitles['fr'] = subtitles_list
  90. return {
  91. 'id': video_id,
  92. 'title': title,
  93. 'description': clean_html(info['synopsis']),
  94. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
  95. 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
  96. 'timestamp': int_or_none(info['diffusion']['timestamp']),
  97. 'formats': formats,
  98. 'subtitles': subtitles,
  99. }
  100. class PluzzIE(FranceTVBaseInfoExtractor):
  101. IE_NAME = 'pluzz.francetv.fr'
  102. _VALID_URL = r'https?://(?:m\.)?pluzz\.francetv\.fr/videos/(?P<id>.+?)\.html'
  103. # Can't use tests, videos expire in 7 days
  104. def _real_extract(self, url):
  105. display_id = self._match_id(url)
  106. webpage = self._download_webpage(url, display_id)
  107. video_id = self._html_search_meta(
  108. 'id_video', webpage, 'video id', default=None)
  109. if not video_id:
  110. video_id = self._search_regex(
  111. r'data-diffusion=["\'](\d+)', webpage, 'video id')
  112. return self._extract_video(video_id, 'Pluzz')
  113. class FranceTvInfoIE(FranceTVBaseInfoExtractor):
  114. IE_NAME = 'francetvinfo.fr'
  115. _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<title>[^/?#&.]+)'
  116. _TESTS = [{
  117. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  118. 'info_dict': {
  119. 'id': '84981923',
  120. 'ext': 'mp4',
  121. 'title': 'Soir 3',
  122. 'upload_date': '20130826',
  123. 'timestamp': 1377548400,
  124. 'subtitles': {
  125. 'fr': 'mincount:2',
  126. },
  127. },
  128. 'params': {
  129. # m3u8 downloads
  130. 'skip_download': True,
  131. },
  132. }, {
  133. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  134. 'info_dict': {
  135. 'id': 'EV_20019',
  136. 'ext': 'mp4',
  137. 'title': 'Débat des candidats à la Commission européenne',
  138. 'description': 'Débat des candidats à la Commission européenne',
  139. },
  140. 'params': {
  141. 'skip_download': 'HLS (reqires ffmpeg)'
  142. },
  143. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  144. }, {
  145. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  146. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  147. 'info_dict': {
  148. 'id': 'NI_173343',
  149. 'ext': 'mp4',
  150. 'title': 'Les entreprises familiales : le secret de la réussite',
  151. 'thumbnail': r're:^https?://.*\.jpe?g$',
  152. 'timestamp': 1433273139,
  153. 'upload_date': '20150602',
  154. },
  155. 'params': {
  156. # m3u8 downloads
  157. 'skip_download': True,
  158. },
  159. }, {
  160. 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
  161. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  162. 'info_dict': {
  163. 'id': 'NI_657393',
  164. 'ext': 'mp4',
  165. 'title': 'Olivier Monthus, réalisateur de "Bretagne, le choix de l’Armor"',
  166. 'description': 'md5:a3264114c9d29aeca11ced113c37b16c',
  167. 'thumbnail': r're:^https?://.*\.jpe?g$',
  168. 'timestamp': 1458300695,
  169. 'upload_date': '20160318',
  170. },
  171. 'params': {
  172. 'skip_download': True,
  173. },
  174. }, {
  175. # Dailymotion embed
  176. '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',
  177. 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
  178. 'info_dict': {
  179. 'id': 'x4iiko0',
  180. 'ext': 'mp4',
  181. 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
  182. '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',
  183. 'timestamp': 1467011958,
  184. 'upload_date': '20160627',
  185. 'uploader': 'France Inter',
  186. 'uploader_id': 'x2q2ez',
  187. },
  188. 'add_ie': ['Dailymotion'],
  189. }, {
  190. 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
  191. 'only_matching': True,
  192. }]
  193. def _real_extract(self, url):
  194. mobj = re.match(self._VALID_URL, url)
  195. page_title = mobj.group('title')
  196. webpage = self._download_webpage(url, page_title)
  197. dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
  198. if dmcloud_url:
  199. return self.url_result(dmcloud_url, DailymotionCloudIE.ie_key())
  200. dailymotion_urls = DailymotionIE._extract_urls(webpage)
  201. if dailymotion_urls:
  202. return self.playlist_result([
  203. self.url_result(dailymotion_url, DailymotionIE.ie_key())
  204. for dailymotion_url in dailymotion_urls])
  205. video_id, catalogue = self._search_regex(
  206. (r'id-video=([^@]+@[^"]+)',
  207. r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"'),
  208. webpage, 'video id').split('@')
  209. return self._extract_video(video_id, catalogue)
  210. class FranceTVIE(FranceTVBaseInfoExtractor):
  211. IE_NAME = 'francetv'
  212. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  213. _VALID_URL = r'''(?x)
  214. https?://
  215. (?:
  216. (?:www\.)?france[2345o]\.fr/
  217. (?:
  218. emissions/[^/]+/(?:videos|diffusions)|
  219. emission/[^/]+|
  220. videos|
  221. jt
  222. )
  223. /|
  224. embed\.francetv\.fr/\?ue=
  225. )
  226. (?P<id>[^/?]+)
  227. '''
  228. _TESTS = [
  229. # france2
  230. {
  231. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  232. 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
  233. 'info_dict': {
  234. 'id': '109169362',
  235. 'ext': 'flv',
  236. 'title': '13h15, le dimanche...',
  237. 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
  238. 'upload_date': '20140914',
  239. 'timestamp': 1410693600,
  240. },
  241. },
  242. # france3
  243. {
  244. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  245. 'md5': '679bb8f8921f8623bd658fa2f8364da0',
  246. 'info_dict': {
  247. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  248. 'ext': 'mp4',
  249. 'title': 'Le scandale du prix des médicaments',
  250. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  251. 'upload_date': '20131113',
  252. 'timestamp': 1384380000,
  253. },
  254. },
  255. # france4
  256. {
  257. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  258. 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
  259. 'info_dict': {
  260. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  261. 'ext': 'mp4',
  262. 'title': 'Hero Corp Making of - Extrait 1',
  263. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  264. 'upload_date': '20131106',
  265. 'timestamp': 1383766500,
  266. },
  267. },
  268. # france5
  269. {
  270. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/quels_sont_les_enjeux_de_cette_rentree_politique__31-08-2015_908948?onglet=tous&page=1',
  271. 'md5': 'f6c577df3806e26471b3d21631241fd0',
  272. 'info_dict': {
  273. 'id': '123327454',
  274. 'ext': 'flv',
  275. 'title': 'C à dire ?! - Quels sont les enjeux de cette rentrée politique ?',
  276. 'description': 'md5:4a0d5cb5dce89d353522a84462bae5a4',
  277. 'upload_date': '20150831',
  278. 'timestamp': 1441035120,
  279. },
  280. },
  281. # franceo
  282. {
  283. 'url': 'http://www.franceo.fr/jt/info-soir/18-07-2015',
  284. 'md5': '47d5816d3b24351cdce512ad7ab31da8',
  285. 'info_dict': {
  286. 'id': '125377621',
  287. 'ext': 'flv',
  288. 'title': 'Infô soir',
  289. 'description': 'md5:01b8c6915a3d93d8bbbd692651714309',
  290. 'upload_date': '20150718',
  291. 'timestamp': 1437241200,
  292. 'duration': 414,
  293. },
  294. },
  295. {
  296. # francetv embed
  297. 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87',
  298. 'info_dict': {
  299. 'id': 'EV_30231',
  300. 'ext': 'flv',
  301. 'title': 'Alcaline, le concert avec Calogero',
  302. 'description': 'md5:61f08036dcc8f47e9cfc33aed08ffaff',
  303. 'upload_date': '20150226',
  304. 'timestamp': 1424989860,
  305. 'duration': 5400,
  306. },
  307. },
  308. {
  309. 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05',
  310. 'only_matching': True,
  311. },
  312. {
  313. 'url': 'http://www.franceo.fr/videos/125377617',
  314. 'only_matching': True,
  315. }
  316. ]
  317. def _real_extract(self, url):
  318. video_id = self._match_id(url)
  319. webpage = self._download_webpage(url, video_id)
  320. video_id, catalogue = self._html_search_regex(
  321. r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  322. webpage, 'video ID').split('@')
  323. return self._extract_video(video_id, catalogue)
  324. class GenerationQuoiIE(InfoExtractor):
  325. IE_NAME = 'france2.fr:generation-quoi'
  326. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
  327. _TEST = {
  328. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  329. 'info_dict': {
  330. 'id': 'k7FJX8VBcvvLmX4wA5Q',
  331. 'ext': 'mp4',
  332. 'title': 'Génération Quoi - Garde à Vous',
  333. 'uploader': 'Génération Quoi',
  334. },
  335. 'params': {
  336. # It uses Dailymotion
  337. 'skip_download': True,
  338. },
  339. }
  340. def _real_extract(self, url):
  341. display_id = self._match_id(url)
  342. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
  343. info_json = self._download_webpage(info_url, display_id)
  344. info = json.loads(info_json)
  345. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  346. ie='Dailymotion')
  347. class CultureboxIE(FranceTVBaseInfoExtractor):
  348. IE_NAME = 'culturebox.francetvinfo.fr'
  349. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  350. _TEST = {
  351. 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
  352. 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
  353. 'info_dict': {
  354. 'id': 'EV_50111',
  355. 'ext': 'flv',
  356. 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
  357. 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
  358. 'upload_date': '20150320',
  359. 'timestamp': 1426892400,
  360. 'duration': 2760.9,
  361. },
  362. }
  363. def _real_extract(self, url):
  364. mobj = re.match(self._VALID_URL, url)
  365. name = mobj.group('name')
  366. webpage = self._download_webpage(url, name)
  367. if ">Ce live n'est plus disponible en replay<" in webpage:
  368. raise ExtractorError('Video %s is not available' % name, expected=True)
  369. video_id, catalogue = self._search_regex(
  370. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  371. return self._extract_video(video_id, catalogue)