francetv.py 14 KB

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