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.

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