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.

354 lines
13 KiB

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