francetv.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. parse_duration,
  15. determine_ext,
  16. )
  17. from .dailymotion import DailymotionCloudIE
  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. f4m_url = self._download_webpage(
  55. 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url,
  56. video_id, 'Downloading f4m manifest token', fatal=False)
  57. if f4m_url:
  58. formats.extend(self._extract_f4m_formats(
  59. f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44', 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': int_or_none(info.get('real_duration')) 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. 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
  121. 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
  122. 'info_dict': {
  123. 'id': '556e03339473995ee145930c',
  124. 'ext': 'mp4',
  125. 'title': 'Les entreprises familiales : le secret de la réussite',
  126. 'thumbnail': 're:^https?://.*\.jpe?g$',
  127. }
  128. }]
  129. def _real_extract(self, url):
  130. mobj = re.match(self._VALID_URL, url)
  131. page_title = mobj.group('title')
  132. webpage = self._download_webpage(url, page_title)
  133. dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
  134. if dmcloud_url:
  135. return self.url_result(dmcloud_url, 'DailymotionCloud')
  136. video_id, catalogue = self._search_regex(
  137. r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
  138. return self._extract_video(video_id, catalogue)
  139. class FranceTVIE(FranceTVBaseInfoExtractor):
  140. IE_NAME = 'francetv'
  141. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  142. _VALID_URL = r'''(?x)
  143. https?://
  144. (?:
  145. (?:www\.)?france[2345o]\.fr/
  146. (?:
  147. emissions/[^/]+/(?:videos|diffusions)?|
  148. videos|
  149. jt
  150. )
  151. /|
  152. embed\.francetv\.fr/\?ue=
  153. )
  154. (?P<id>[^/?]+)
  155. '''
  156. _TESTS = [
  157. # france2
  158. {
  159. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  160. 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
  161. 'info_dict': {
  162. 'id': '109169362',
  163. 'ext': 'flv',
  164. 'title': '13h15, le dimanche...',
  165. 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
  166. 'upload_date': '20140914',
  167. 'timestamp': 1410693600,
  168. },
  169. },
  170. # france3
  171. {
  172. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  173. 'md5': '679bb8f8921f8623bd658fa2f8364da0',
  174. 'info_dict': {
  175. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  176. 'ext': 'mp4',
  177. 'title': 'Le scandale du prix des médicaments',
  178. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  179. 'upload_date': '20131113',
  180. 'timestamp': 1384380000,
  181. },
  182. },
  183. # france4
  184. {
  185. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  186. 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
  187. 'info_dict': {
  188. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  189. 'ext': 'mp4',
  190. 'title': 'Hero Corp Making of - Extrait 1',
  191. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  192. 'upload_date': '20131106',
  193. 'timestamp': 1383766500,
  194. },
  195. },
  196. # france5
  197. {
  198. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
  199. 'md5': '78f0f4064f9074438e660785bbf2c5d9',
  200. 'info_dict': {
  201. 'id': '108961659',
  202. 'ext': 'flv',
  203. 'title': 'C à dire ?!',
  204. 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
  205. 'upload_date': '20140915',
  206. 'timestamp': 1410795000,
  207. },
  208. },
  209. # franceo
  210. {
  211. 'url': 'http://www.franceo.fr/jt/info-soir/18-07-2015',
  212. 'md5': '47d5816d3b24351cdce512ad7ab31da8',
  213. 'info_dict': {
  214. 'id': '125377621',
  215. 'ext': 'flv',
  216. 'title': 'Infô soir',
  217. 'description': 'md5:01b8c6915a3d93d8bbbd692651714309',
  218. 'upload_date': '20150718',
  219. 'timestamp': 1437241200,
  220. 'duration': 414,
  221. },
  222. },
  223. {
  224. # francetv embed
  225. 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87',
  226. 'info_dict': {
  227. 'id': 'EV_30231',
  228. 'ext': 'flv',
  229. 'title': 'Alcaline, le concert avec Calogero',
  230. 'description': 'md5:61f08036dcc8f47e9cfc33aed08ffaff',
  231. 'upload_date': '20150226',
  232. 'timestamp': 1424989860,
  233. 'duration': 5400,
  234. },
  235. },
  236. {
  237. 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05',
  238. 'only_matching': True,
  239. },
  240. {
  241. 'url': 'http://www.franceo.fr/videos/125377617',
  242. 'only_matching': True,
  243. }
  244. ]
  245. def _real_extract(self, url):
  246. video_id = self._match_id(url)
  247. webpage = self._download_webpage(url, video_id)
  248. video_id, catalogue = self._html_search_regex(
  249. r'href="http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
  250. webpage, 'video ID').split('@')
  251. return self._extract_video(video_id, catalogue)
  252. class GenerationQuoiIE(InfoExtractor):
  253. IE_NAME = 'france2.fr:generation-quoi'
  254. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
  255. _TEST = {
  256. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  257. 'info_dict': {
  258. 'id': 'k7FJX8VBcvvLmX4wA5Q',
  259. 'ext': 'mp4',
  260. 'title': 'Génération Quoi - Garde à Vous',
  261. 'uploader': 'Génération Quoi',
  262. },
  263. 'params': {
  264. # It uses Dailymotion
  265. 'skip_download': True,
  266. },
  267. }
  268. def _real_extract(self, url):
  269. display_id = self._match_id(url)
  270. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
  271. info_json = self._download_webpage(info_url, display_id)
  272. info = json.loads(info_json)
  273. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  274. ie='Dailymotion')
  275. class CultureboxIE(FranceTVBaseInfoExtractor):
  276. IE_NAME = 'culturebox.francetvinfo.fr'
  277. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  278. _TEST = {
  279. 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
  280. 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
  281. 'info_dict': {
  282. 'id': 'EV_50111',
  283. 'ext': 'flv',
  284. 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
  285. 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
  286. 'upload_date': '20150320',
  287. 'timestamp': 1426892400,
  288. 'duration': 2760.9,
  289. },
  290. }
  291. def _real_extract(self, url):
  292. mobj = re.match(self._VALID_URL, url)
  293. name = mobj.group('name')
  294. webpage = self._download_webpage(url, name)
  295. if ">Ce live n'est plus disponible en replay<" in webpage:
  296. raise ExtractorError('Video %s is not available' % name, expected=True)
  297. video_id, catalogue = self._search_regex(
  298. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  299. return self._extract_video(video_id, catalogue)