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.

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