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.

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