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.

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