2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_HTTPError
14 class EaglePlatformIE(InfoExtractor):
17 eagleplatform:(?P<custom_host>[^/]+):|
18 https?://(?P<host>.+?\.media\.eagleplatform\.com)/index/player\?.*\brecord_id=
23 # http://lenta.ru/news/2015/03/06/navalny/
24 'url': 'http://lentaru.media.eagleplatform.com/index/player?player=new&record_id=227304&player_template_id=5201',
25 'md5': '70f5187fb620f2c1d503b3b22fd4efe3',
29 'title': 'Навальный вышел на свободу',
30 'description': 'md5:d97861ac9ae77377f3f20eaf9d04b4f5',
31 'thumbnail': 're:^https?://.*\.jpg$',
37 # http://muz-tv.ru/play/7129/
38 # http://media.clipyou.ru/index/player?record_id=12820&width=730&height=415&autoplay=true
39 'url': 'eagleplatform:media.clipyou.ru:12820',
40 'md5': '90b26344ba442c8e44aa4cf8f301164a',
44 'title': "'O Sole Mio",
45 'thumbnail': 're:^https?://.*\.jpg$',
49 'skip': 'Georestricted',
53 def _handle_error(response):
54 status = int_or_none(response.get('status', 200))
56 raise ExtractorError(' '.join(response['errors']), expected=True)
58 def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata'):
60 response = super(EaglePlatformIE, self)._download_json(url_or_request, video_id, note)
61 except ExtractorError as ee:
62 if isinstance(ee.cause, compat_HTTPError):
63 response = self._parse_json(ee.cause.read().decode('utf-8'), video_id)
64 self._handle_error(response)
68 def _get_video_url(self, url_or_request, video_id, note='Downloading JSON metadata'):
69 return self._download_json(url_or_request, video_id, note)['data'][0]
71 def _real_extract(self, url):
72 mobj = re.match(self._VALID_URL, url)
73 host, video_id = mobj.group('custom_host') or mobj.group('host'), mobj.group('id')
75 player_data = self._download_json(
76 'http://%s/api/player_data?id=%s' % (host, video_id), video_id)
78 media = player_data['data']['playlist']['viewports'][0]['medialist'][0]
80 title = media['title']
81 description = media.get('description')
82 thumbnail = self._proto_relative_url(media.get('snapshot'), 'http:')
83 duration = int_or_none(media.get('duration'))
84 view_count = int_or_none(media.get('views'))
86 age_restriction = media.get('age_restriction')
89 age_limit = 0 if age_restriction == 'allow_all' else 18
91 secure_m3u8 = self._proto_relative_url(media['sources']['secure_m3u8']['auto'], 'http:')
93 m3u8_url = self._get_video_url(secure_m3u8, video_id, 'Downloading m3u8 JSON')
94 formats = self._extract_m3u8_formats(
96 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
98 mp4_url = self._get_video_url(
99 # Secure mp4 URL is constructed according to Player.prototype.mp4 from
100 # http://lentaru.media.eagleplatform.com/player/player.js
101 re.sub(r'm3u8|hlsvod|hls|f4m', 'mp4', secure_m3u8),
102 video_id, 'Downloading mp4 JSON')
103 formats.append({'url': mp4_url, 'format_id': 'mp4'})
105 self._sort_formats(formats)
110 'description': description,
111 'thumbnail': thumbnail,
112 'duration': duration,
113 'view_count': view_count,
114 'age_limit': age_limit,