3 from .common
import InfoExtractor
4 from ..compat
import compat_HTTPError
13 class ImgGamingBaseIE(InfoExtractor
):
14 _API_BASE
= 'https://dce-frontoffice.imggaming.com/api/v2/'
15 _API_KEY
= '857a1e5d-e35e-4fdf-805b-a87b6f8364bf'
17 _MANIFEST_HEADERS
= {'Accept-Encoding': 'identity'}
19 _VALID_URL_TEMPL
= r
'https?://(?P<domain>%s)/(?P<type>live|playlist|video)/(?P<id>\d+)(?:\?.*?\bplaylistId=(?P<playlist_id>\d+))?'
21 def _initialize_pre_login(self
):
23 'Realm': 'dce.' + self
._REALM
,
24 'x-api-key': self
._API
_KEY
,
27 def _perform_login(self
, username
, password
):
28 p_headers
= self
._HEADERS
.copy()
29 p_headers
['Content-Type'] = 'application/json'
30 self
._HEADERS
['Authorization'] = 'Bearer ' + self
._download
_json
(
31 self
._API
_BASE
+ 'login',
32 None, 'Logging in', data
=json
.dumps({
35 }).encode(), headers
=p_headers
)['authorisationToken']
37 def _real_initialize(self
):
38 if not self
._HEADERS
.get('Authorization'):
39 self
.raise_login_required(method
='password')
41 def _call_api(self
, path
, media_id
):
42 return self
._download
_json
(
43 self
._API
_BASE
+ path
+ media_id
, media_id
, headers
=self
._HEADERS
)
45 def _extract_dve_api_url(self
, media_id
, media_type
):
46 stream_path
= 'stream'
47 if media_type
== 'video':
48 stream_path
+= '/vod/'
50 stream_path
+= '?eventId='
52 return self
._call
_api
(
53 stream_path
, media_id
)['playerUrlCallback']
54 except ExtractorError
as e
:
55 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
57 self
._parse
_json
(e
.cause
.read().decode(), media_id
)['messages'][0],
61 def _real_extract(self
, url
):
62 domain
, media_type
, media_id
, playlist_id
= self
._match
_valid
_url
(url
).groups()
65 if self
._yes
_playlist
(playlist_id
, media_id
):
66 media_type
, media_id
= 'playlist', playlist_id
68 if media_type
== 'playlist':
69 playlist
= self
._call
_api
('vod/playlist/', media_id
)
71 for video
in try_get(playlist
, lambda x
: x
['videos']['vods']) or []:
72 video_id
= str_or_none(video
.get('id'))
75 entries
.append(self
.url_result(
76 'https://%s/video/%s' % (domain
, video_id
),
77 self
.ie_key(), video_id
))
78 return self
.playlist_result(
79 entries
, media_id
, playlist
.get('title'),
80 playlist
.get('description'))
82 dve_api_url
= self
._extract
_dve
_api
_url
(media_id
, media_type
)
83 video_data
= self
._download
_json
(dve_api_url
, media_id
)
84 is_live
= media_type
== 'live'
86 title
= self
._call
_api
('event/', media_id
)['title']
88 title
= video_data
['name']
91 for proto
in ('hls', 'dash'):
92 media_url
= video_data
.get(proto
+ 'Url') or try_get(video_data
, lambda x
: x
[proto
]['url'])
96 m3u8_formats
= self
._extract
_m
3u8_formats
(
97 media_url
, media_id
, 'mp4', live
=is_live
,
98 m3u8_id
='hls', fatal
=False, headers
=self
._MANIFEST
_HEADERS
)
99 for f
in m3u8_formats
:
100 f
.setdefault('http_headers', {}).update(self
._MANIFEST
_HEADERS
)
103 formats
.extend(self
._extract
_mpd
_formats
(
104 media_url
, media_id
, mpd_id
='dash', fatal
=False,
105 headers
=self
._MANIFEST
_HEADERS
))
106 self
._sort
_formats
(formats
)
109 for subtitle
in video_data
.get('subtitles', []):
110 subtitle_url
= subtitle
.get('url')
113 subtitles
.setdefault(subtitle
.get('lang', 'en_US'), []).append({
121 'thumbnail': video_data
.get('thumbnailUrl'),
122 'description': video_data
.get('description'),
123 'duration': int_or_none(video_data
.get('duration')),
124 'tags': video_data
.get('tags'),
126 'subtitles': subtitles
,