francetv.py 13 KB

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