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.

331 lines
12 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. return {
  74. 'id': video_id,
  75. 'title': info['titre'],
  76. 'description': clean_html(info['synopsis']),
  77. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
  78. 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
  79. 'timestamp': int_or_none(info['diffusion']['timestamp']),
  80. 'formats': formats,
  81. }
  82. class PluzzIE(FranceTVBaseInfoExtractor):
  83. IE_NAME = 'pluzz.francetv.fr'
  84. _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
  85. # Can't use tests, videos expire in 7 days
  86. def _real_extract(self, url):
  87. title = re.match(self._VALID_URL, url).group(1)
  88. webpage = self._download_webpage(url, title)
  89. video_id = self._search_regex(
  90. r'data-diffusion="(\d+)"', webpage, 'ID')
  91. return self._extract_video(video_id, 'Pluzz')
  92. class FranceTvInfoIE(FranceTVBaseInfoExtractor):
  93. IE_NAME = 'francetvinfo.fr'
  94. _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
  95. _TESTS = [{
  96. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  97. 'info_dict': {
  98. 'id': '84981923',
  99. 'ext': 'flv',
  100. 'title': 'Soir 3',
  101. 'upload_date': '20130826',
  102. 'timestamp': 1377548400,
  103. },
  104. }, {
  105. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  106. 'info_dict': {
  107. 'id': 'EV_20019',
  108. 'ext': 'mp4',
  109. 'title': 'Débat des candidats à la Commission européenne',
  110. 'description': 'Débat des candidats à la Commission européenne',
  111. },
  112. 'params': {
  113. 'skip_download': 'HLS (reqires ffmpeg)'
  114. },
  115. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  116. }, {
  117. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  118. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  119. 'info_dict': {
  120. 'id': '556e03339473995ee145930c',
  121. 'ext': 'mp4',
  122. 'title': 'Les entreprises familiales : le secret de la réussite',
  123. 'thumbnail': 're:^https?://.*\.jpe?g$',
  124. }
  125. }]
  126. def _real_extract(self, url):
  127. mobj = re.match(self._VALID_URL, url)
  128. page_title = mobj.group('title')
  129. webpage = self._download_webpage(url, page_title)
  130. dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
  131. if dmcloud_url:
  132. return self.url_result(dmcloud_url, 'DailymotionCloud')
  133. video_id, catalogue = self._search_regex(
  134. r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
  135. return self._extract_video(video_id, catalogue)
  136. class FranceTVIE(FranceTVBaseInfoExtractor):
  137. IE_NAME = 'francetv'
  138. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  139. _VALID_URL = r'''(?x)
  140. https?://
  141. (?:
  142. (?:www\.)?france[2345o]\.fr/
  143. (?:
  144. emissions/[^/]+/(?:videos|diffusions)|
  145. emission/[^/]+|
  146. videos|
  147. jt
  148. )
  149. /|
  150. embed\.francetv\.fr/\?ue=
  151. )
  152. (?P<id>[^/?]+)
  153. '''
  154. _TESTS = [
  155. # france2
  156. {
  157. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  158. 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
  159. 'info_dict': {
  160. 'id': '109169362',
  161. 'ext': 'flv',
  162. 'title': '13h15, le dimanche...',
  163. 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
  164. 'upload_date': '20140914',
  165. 'timestamp': 1410693600,
  166. },
  167. },
  168. # france3
  169. {
  170. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  171. 'md5': '679bb8f8921f8623bd658fa2f8364da0',
  172. 'info_dict': {
  173. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  174. 'ext': 'mp4',
  175. 'title': 'Le scandale du prix des médicaments',
  176. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  177. 'upload_date': '20131113',
  178. 'timestamp': 1384380000,
  179. },
  180. },
  181. # france4
  182. {
  183. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  184. 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
  185. 'info_dict': {
  186. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  187. 'ext': 'mp4',
  188. 'title': 'Hero Corp Making of - Extrait 1',
  189. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  190. 'upload_date': '20131106',
  191. 'timestamp': 1383766500,
  192. },
  193. },
  194. # france5
  195. {
  196. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
  197. 'md5': '78f0f4064f9074438e660785bbf2c5d9',
  198. 'info_dict': {
  199. 'id': '108961659',
  200. 'ext': 'flv',
  201. 'title': 'C à dire ?!',
  202. 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
  203. 'upload_date': '20140915',
  204. 'timestamp': 1410795000,
  205. },
  206. },
  207. # franceo
  208. {
  209. 'url': 'http://www.franceo.fr/jt/info-soir/18-07-2015',
  210. 'md5': '47d5816d3b24351cdce512ad7ab31da8',
  211. 'info_dict': {
  212. 'id': '125377621',
  213. 'ext': 'flv',
  214. 'title': 'Infô soir',
  215. 'description': 'md5:01b8c6915a3d93d8bbbd692651714309',
  216. 'upload_date': '20150718',
  217. 'timestamp': 1437241200,
  218. 'duration': 414,
  219. },
  220. },
  221. {
  222. # francetv embed
  223. 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87',
  224. 'info_dict': {
  225. 'id': 'EV_30231',
  226. 'ext': 'flv',
  227. 'title': 'Alcaline, le concert avec Calogero',
  228. 'description': 'md5:61f08036dcc8f47e9cfc33aed08ffaff',
  229. 'upload_date': '20150226',
  230. 'timestamp': 1424989860,
  231. 'duration': 5400,
  232. },
  233. },
  234. {
  235. 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05',
  236. 'only_matching': True,
  237. },
  238. {
  239. 'url': 'http://www.franceo.fr/videos/125377617',
  240. 'only_matching': True,
  241. }
  242. ]
  243. def _real_extract(self, url):
  244. video_id = self._match_id(url)
  245. webpage = self._download_webpage(url, video_id)
  246. video_id, catalogue = self._html_search_regex(
  247. r'href="http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  248. webpage, 'video ID').split('@')
  249. return self._extract_video(video_id, catalogue)
  250. class GenerationQuoiIE(InfoExtractor):
  251. IE_NAME = 'france2.fr:generation-quoi'
  252. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
  253. _TEST = {
  254. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  255. 'info_dict': {
  256. 'id': 'k7FJX8VBcvvLmX4wA5Q',
  257. 'ext': 'mp4',
  258. 'title': 'Génération Quoi - Garde à Vous',
  259. 'uploader': 'Génération Quoi',
  260. },
  261. 'params': {
  262. # It uses Dailymotion
  263. 'skip_download': True,
  264. },
  265. }
  266. def _real_extract(self, url):
  267. display_id = self._match_id(url)
  268. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
  269. info_json = self._download_webpage(info_url, display_id)
  270. info = json.loads(info_json)
  271. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  272. ie='Dailymotion')
  273. class CultureboxIE(FranceTVBaseInfoExtractor):
  274. IE_NAME = 'culturebox.francetvinfo.fr'
  275. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  276. _TEST = {
  277. 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
  278. 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
  279. 'info_dict': {
  280. 'id': 'EV_50111',
  281. 'ext': 'flv',
  282. 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
  283. 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
  284. 'upload_date': '20150320',
  285. 'timestamp': 1426892400,
  286. 'duration': 2760.9,
  287. },
  288. }
  289. def _real_extract(self, url):
  290. mobj = re.match(self._VALID_URL, url)
  291. name = mobj.group('name')
  292. webpage = self._download_webpage(url, name)
  293. if ">Ce live n'est plus disponible en replay<" in webpage:
  294. raise ExtractorError('Video %s is not available' % name, expected=True)
  295. video_id, catalogue = self._search_regex(
  296. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  297. return self._extract_video(video_id, catalogue)