3 from .common
import InfoExtractor
4 from ..compat
import compat_HTTPError
13 class EaglePlatformIE(InfoExtractor
):
16 eagleplatform:(?P<custom_host>[^/]+):|
17 https?://(?P<host>.+?\.media\.eagleplatform\.com)/index/player\?.*\brecord_id=
22 # http://lenta.ru/news/2015/03/06/navalny/
23 'url': 'http://lentaru.media.eagleplatform.com/index/player?player=new&record_id=227304&player_template_id=5201',
24 # Not checking MD5 as sometimes the direct HTTP link results in 404 and HLS is used
28 'title': 'Навальный вышел на свободу',
29 'description': 'md5:d97861ac9ae77377f3f20eaf9d04b4f5',
30 'thumbnail': r
're:^https?://.*\.jpg$',
36 # http://muz-tv.ru/play/7129/
37 # http://media.clipyou.ru/index/player?record_id=12820&width=730&height=415&autoplay=true
38 'url': 'eagleplatform:media.clipyou.ru:12820',
39 'md5': '358597369cf8ba56675c1df15e7af624',
43 'title': "'O Sole Mio",
44 'thumbnail': r
're:^https?://.*\.jpg$',
48 'skip': 'Georestricted',
50 # referrer protected video (https://tvrain.ru/lite/teleshow/kak_vse_nachinalos/namin-418921/)
51 'url': 'eagleplatform:tvrainru.media.eagleplatform.com:582306',
52 'only_matching': True,
56 def _extract_url(webpage
):
57 # Regular iframe embedding
59 r
'<iframe[^>]+src=(["\'])(?P
<url
>(?
:https?
:)?
//.+?\
.media\
.eagleplatform\
.com
/index
/player
\?.+?
)\
1',
62 return mobj.group('url
')
65 src=(?P<qjs>["\'])(?:https?:)?//(?P<host>(?:(?!(?P=qjs)).)+\.media\.eagleplatform\.com)/player/player\.js(?P=qjs)
68 # "Basic usage" embedding (see http://dultonmedia.github.io/eplayer/)
73 class=(?P<qclass>["\'])eagleplayer(?P=qclass)[^>]+
74 data-id=["\'](?P<id>\d+)
75 ''' % PLAYER_JS_RE, webpage)
77 return 'eagleplatform
:%(host)s:%(id)s' % mobj.groupdict()
78 # Generalization of "Javascript code usage", "Combined usage" and
79 # "Usage without attaching to DOM" embeddings (see
80 # http://dultonmedia.github.io/eplayer/)
90 \bid\s*:\s*["\']?(?P<id>\d+)
96 ''' % PLAYER_JS_RE, webpage)
98 return 'eagleplatform
:%(host)s:%(id)s' % mobj.groupdict()
101 def _handle_error(response):
102 status = int_or_none(response.get('status
', 200))
104 raise ExtractorError(' '.join(response['errors
']), expected=True)
106 def _download_json(self, url_or_request, video_id, *args, **kwargs):
108 response = super(EaglePlatformIE, self)._download_json(
109 url_or_request, video_id, *args, **kwargs)
110 except ExtractorError as ee:
111 if isinstance(ee.cause, compat_HTTPError):
112 response = self._parse_json(ee.cause.read().decode('utf
-8'), video_id)
113 self._handle_error(response)
117 def _get_video_url(self, url_or_request, video_id, note='Downloading JSON metadata
'):
118 return self._download_json(url_or_request, video_id, note)['data
'][0]
120 def _real_extract(self, url):
121 url, smuggled_data = unsmuggle_url(url, {})
123 mobj = self._match_valid_url(url)
124 host, video_id = mobj.group('custom_host
') or mobj.group('host
'), mobj.group('id')
131 referrer = smuggled_data.get('referrer
')
133 headers['Referer
'] = referrer
134 query['referrer
'] = referrer
136 player_data = self._download_json(
137 'http
://%s/api
/player_data
' % host, video_id,
138 headers=headers, query=query)
140 media = player_data['data
']['playlist
']['viewports
'][0]['medialist
'][0]
142 title = media['title
']
143 description = media.get('description
')
144 thumbnail = self._proto_relative_url(media.get('snapshot
'), 'http
:')
145 duration = int_or_none(media.get('duration
'))
146 view_count = int_or_none(media.get('views
'))
148 age_restriction = media.get('age_restriction
')
151 age_limit = 0 if age_restriction == 'allow_all
' else 18
153 secure_m3u8 = self._proto_relative_url(media['sources
']['secure_m3u8
']['auto
'], 'http
:')
157 m3u8_url = self._get_video_url(secure_m3u8, video_id, 'Downloading m3u8 JSON
')
158 m3u8_formats = self._extract_m3u8_formats(
159 m3u8_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
160 m3u8_id='hls
', fatal=False)
161 formats.extend(m3u8_formats)
163 m3u8_formats_dict = {}
164 for f in m3u8_formats:
165 if f.get('height
') is not None:
166 m3u8_formats_dict[f['height
']] = f
168 mp4_data = self._download_json(
169 # Secure mp4 URL is constructed according to Player.prototype.mp4 from
170 # http://lentaru.media.eagleplatform.com/player/player.js
171 re.sub(r'm3u8|hlsvod|hls|f4m
', 'mp4s
', secure_m3u8),
172 video_id, 'Downloading mp4 JSON
', fatal=False)
174 for format_id, format_url in mp4_data.get('data
', {}).items():
175 if not url_or_none(format_url):
177 height = int_or_none(format_id)
178 if height is not None and m3u8_formats_dict.get(height):
179 f = m3u8_formats_dict[height].copy()
181 'format_id
': f['format_id
'].replace('hls
', 'http
'),
186 'format_id
': 'http
-%s' % format_id,
187 'height
': int_or_none(format_id),
189 f['url
'] = format_url
192 self._sort_formats(formats)
197 'description
': description,
198 'thumbnail
': thumbnail,
199 'duration
': duration,
200 'view_count
': view_count,
201 'age_limit
': age_limit,