]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mildom.py
2 from __future__
import unicode_literals
5 from datetime
import datetime
9 from .common
import InfoExtractor
16 from ..compat
import (
21 class MildomBaseIE(InfoExtractor
):
23 _DISPATCHER_CONFIG
= None
25 def _call_api(self
, url
, video_id
, query
={}, note
='Downloading JSON metadata', init
=False):
26 url
= update_url_query(url
, self
._common
_queries
(query
, init
=init
))
27 return self
._download
_json
(url
, video_id
, note
=note
)['body']
29 def _common_queries(self
, query
={}, init
=False):
30 dc
= self
._fetch
_dispatcher
_config
()
32 'timestamp': self
.iso_timestamp(),
33 '__guest_id': '' if init
else self
.guest_id(),
34 '__location': dc
['location'],
35 '__country': dc
['country'],
36 '__cluster': dc
['cluster'],
38 '__la': self
.lang_code(),
46 def _fetch_dispatcher_config(self
):
47 if not self
._DISPATCHER
_CONFIG
:
48 tmp
= self
._download
_json
(
49 'https://disp.mildom.com/serverListV2', 'initialization',
50 note
='Downloading dispatcher_config', data
=json
.dumps({
52 'data': base64
.b64encode(json
.dumps({
61 'rtm': self
.iso_timestamp(),
62 'ua': std_headers
['User-Agent'],
63 }).encode('utf8')).decode('utf8').replace('\n', ''),
65 self
._DISPATCHER
_CONFIG
= self
._parse
_json
(base64
.b64decode(tmp
['data']), 'initialization')
66 return self
._DISPATCHER
_CONFIG
70 'new Date().toISOString()'
71 return datetime
.utcnow().isoformat()[0:-3] + 'Z'
77 self
._GUEST
_ID
= try_get(
79 lambda x
: x
._call
_api
(
80 'https://cloudac.mildom.com/nonolive/gappserv/guest/h5init', 'initialization',
81 note
='Downloading guest token', init
=True)['guest_id'] or None,
82 lambda x
: x
._get
_cookies
('https://www.mildom.com').get('gid').value
,
83 lambda x
: x
._get
_cookies
('https://m.mildom.com').get('gid').value
,
92 class MildomIE(MildomBaseIE
):
94 IE_DESC
= 'Record ongoing live by specific user in Mildom'
95 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/(?P<id>\d+)'
97 def _real_extract(self
, url
):
98 video_id
= self
._match
_id
(url
)
99 url
= 'https://www.mildom.com/%s' % video_id
101 webpage
= self
._download
_webpage
(url
, video_id
)
103 enterstudio
= self
._call
_api
(
104 'https://cloudac.mildom.com/nonolive/gappserv/live/enterstudio', video_id
,
105 note
='Downloading live metadata', query
={'user_id': video_id}
)
106 result_video_id
= enterstudio
.get('log_id', video_id
)
110 lambda x
: self
._html
_search
_meta
('twitter:description', webpage
),
111 lambda x
: x
['anchor_intro'],
113 description
= try_get(
115 lambda x
: x
['intro'],
116 lambda x
: x
['live_intro'],
120 lambda x
: self
._html
_search
_meta
('twitter:title', webpage
),
121 lambda x
: x
['loginname'],
124 servers
= self
._call
_api
(
125 'https://cloudac.mildom.com/nonolive/gappserv/live/liveserver', result_video_id
,
126 note
='Downloading live server list', query
={
128 'live_server_type': 'hls',
131 stream_query
= self
._common
_queries
({
132 'streamReqId': random_uuidv4(),
135 m3u8_url
= update_url_query(servers
['stream_server'] + '/%s_master.m3u8' % video_id
, stream_query
)
136 formats
= self
._extract
_m
3u8_formats
(m3u8_url
, result_video_id
, 'mp4', headers
={
137 'Referer': 'https://www.mildom.com/',
138 'Origin': 'https://www.mildom.com',
139 }, note
='Downloading m3u8 information')
141 del stream_query
['streamReqId'], stream_query
['timestamp']
143 fmt
.setdefault('http_headers', {})['Referer'] = 'https://www.mildom.com/'
145 self
._sort
_formats
(formats
)
148 'id': result_video_id
,
150 'description': description
,
151 'uploader': uploader
,
152 'uploader_id': video_id
,
158 class MildomVodIE(MildomBaseIE
):
159 IE_NAME
= 'mildom:vod'
160 IE_DESC
= 'Download a VOD in Mildom'
161 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/playback/(?P<user_id>\d+)/(?P<id>(?P=user_id)-[a-zA-Z0-9]+)'
163 def _real_extract(self
, url
):
164 m
= self
._match
_valid
_url
(url
)
165 user_id
, video_id
= m
.group('user_id'), m
.group('id')
166 url
= 'https://www.mildom.com/playback/%s/%s' % (user_id
, video_id
)
168 webpage
= self
._download
_webpage
(url
, video_id
)
170 autoplay
= self
._call
_api
(
171 'https://cloudac.mildom.com/nonolive/videocontent/playback/getPlaybackDetail', video_id
,
172 note
='Downloading playback metadata', query
={
178 lambda x
: self
._html
_search
_meta
('og:description', webpage
),
179 lambda x
: x
['title'],
181 description
= try_get(
183 lambda x
: x
['video_intro'],
187 lambda x
: x
['author_info']['login_name'],
191 'url': autoplay
['audio_url'],
192 'format_id': 'audio',
193 'protocol': 'm3u8_native',
198 for fmt
in autoplay
['video_link']:
200 'format_id': 'video-%s' % fmt
['name'],
202 'protocol': 'm3u8_native',
203 'width': fmt
['level'] * autoplay
['video_width'] // autoplay
['video_height'],
204 'height': fmt
['level'],
210 self
._sort
_formats
(formats
)
215 'description': description
,
216 'uploader': uploader
,
217 'uploader_id': user_id
,
222 class MildomUserVodIE(MildomBaseIE
):
223 IE_NAME
= 'mildom:user:vod'
224 IE_DESC
= 'Download all VODs from specific user in Mildom'
225 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/profile/(?P<id>\d+)'
227 'url': 'https://www.mildom.com/profile/10093333',
230 'title': 'Uploads from ねこばたけ',
232 'playlist_mincount': 351,
235 def _entries(self
, user_id
):
236 for page
in itertools
.count(1):
237 reply
= self
._call
_api
(
238 'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
239 user_id
, note
='Downloading page %d' % page
, query
={
247 yield self
.url_result('https://www.mildom.com/playback/%s/%s' % (user_id
, x
['v_id']))
249 def _real_extract(self
, url
):
250 user_id
= self
._match
_id
(url
)
251 self
.to_screen('This will download all VODs belonging to user. To download ongoing live video, use "https://www.mildom.com/%s" instead' % user_id
)
253 profile
= self
._call
_api
(
254 'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id
,
255 query
={'user_id': user_id}
, note
='Downloading user profile')['user_info']
257 return self
.playlist_result(
258 self
._entries
(user_id
), user_id
, 'Uploads from %s' % profile
['loginname'])