2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_HTTPError
16 class ImgGamingBaseIE(InfoExtractor
):
17 _API_BASE
= 'https://dce-frontoffice.imggaming.com/api/v2/'
18 _API_KEY
= '857a1e5d-e35e-4fdf-805b-a87b6f8364bf'
20 _MANIFEST_HEADERS
= {'Accept-Encoding': 'identity'}
22 _VALID_URL_TEMPL
= r
'https?://(?P<domain>%s)/(?P<type>live|playlist|video)/(?P<id>\d+)(?:\?.*?\bplaylistId=(?P<playlist_id>\d+))?'
24 def _real_initialize(self
):
26 'Realm': 'dce.' + self
._REALM
,
27 'x-api-key': self
._API
_KEY
,
30 email
, password
= self
._get
_login
_info
()
32 self
.raise_login_required()
34 p_headers
= self
._HEADERS
.copy()
35 p_headers
['Content-Type'] = 'application/json'
36 self
._HEADERS
['Authorization'] = 'Bearer ' + self
._download
_json
(
37 self
._API
_BASE
+ 'login',
38 None, 'Logging in', data
=json
.dumps({
41 }).encode(), headers
=p_headers
)['authorisationToken']
43 def _call_api(self
, path
, media_id
):
44 return self
._download
_json
(
45 self
._API
_BASE
+ path
+ media_id
, media_id
, headers
=self
._HEADERS
)
47 def _extract_dve_api_url(self
, media_id
, media_type
):
48 stream_path
= 'stream'
49 if media_type
== 'video':
50 stream_path
+= '/vod/'
52 stream_path
+= '?eventId='
54 return self
._call
_api
(
55 stream_path
, media_id
)['playerUrlCallback']
56 except ExtractorError
as e
:
57 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
59 self
._parse
_json
(e
.cause
.read().decode(), media_id
)['messages'][0],
63 def _real_extract(self
, url
):
64 domain
, media_type
, media_id
, playlist_id
= self
._match
_valid
_url
(url
).groups()
67 if self
._yes
_playlist
(playlist_id
, media_id
):
68 media_type
, media_id
= 'playlist', playlist_id
70 if media_type
== 'playlist':
71 playlist
= self
._call
_api
('vod/playlist/', media_id
)
73 for video
in try_get(playlist
, lambda x
: x
['videos']['vods']) or []:
74 video_id
= str_or_none(video
.get('id'))
77 entries
.append(self
.url_result(
78 'https://%s/video/%s' % (domain
, video_id
),
79 self
.ie_key(), video_id
))
80 return self
.playlist_result(
81 entries
, media_id
, playlist
.get('title'),
82 playlist
.get('description'))
84 dve_api_url
= self
._extract
_dve
_api
_url
(media_id
, media_type
)
85 video_data
= self
._download
_json
(dve_api_url
, media_id
)
86 is_live
= media_type
== 'live'
88 title
= self
._call
_api
('event/', media_id
)['title']
90 title
= video_data
['name']
93 for proto
in ('hls', 'dash'):
94 media_url
= video_data
.get(proto
+ 'Url') or try_get(video_data
, lambda x
: x
[proto
]['url'])
98 m3u8_formats
= self
._extract
_m
3u8_formats
(
99 media_url
, media_id
, 'mp4', live
=is_live
,
100 m3u8_id
='hls', fatal
=False, headers
=self
._MANIFEST
_HEADERS
)
101 for f
in m3u8_formats
:
102 f
.setdefault('http_headers', {}).update(self
._MANIFEST
_HEADERS
)
105 formats
.extend(self
._extract
_mpd
_formats
(
106 media_url
, media_id
, mpd_id
='dash', fatal
=False,
107 headers
=self
._MANIFEST
_HEADERS
))
108 self
._sort
_formats
(formats
)
111 for subtitle
in video_data
.get('subtitles', []):
112 subtitle_url
= subtitle
.get('url')
115 subtitles
.setdefault(subtitle
.get('lang', 'en_US'), []).append({
123 'thumbnail': video_data
.get('thumbnailUrl'),
124 'description': video_data
.get('description'),
125 'duration': int_or_none(video_data
.get('duration')),
126 'tags': video_data
.get('tags'),
128 'subtitles': subtitles
,