]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mildom.py
2 from __future__
import unicode_literals
5 from datetime
import datetime
10 from .common
import InfoExtractor
17 from ..compat
import (
22 class MildomBaseIE(InfoExtractor
):
24 _DISPATCHER_CONFIG
= None
26 def _call_api(self
, url
, video_id
, query
={}, note
='Downloading JSON metadata', init
=False):
27 url
= update_url_query(url
, self
._common
_queries
(query
, init
=init
))
28 return self
._download
_json
(url
, video_id
, note
=note
)['body']
30 def _common_queries(self
, query
={}, init
=False):
31 dc
= self
._fetch
_dispatcher
_config
()
33 'timestamp': self
.iso_timestamp(),
34 '__guest_id': '' if init
else self
.guest_id(),
35 '__location': dc
['location'],
36 '__country': dc
['country'],
37 '__cluster': dc
['cluster'],
39 '__la': self
.lang_code(),
47 def _fetch_dispatcher_config(self
):
48 if not self
._DISPATCHER
_CONFIG
:
49 tmp
= self
._download
_json
(
50 'https://disp.mildom.com/serverListV2', 'initialization',
51 note
='Downloading dispatcher_config', data
=json
.dumps({
53 'data': base64
.b64encode(json
.dumps({
62 'rtm': self
.iso_timestamp(),
63 'ua': std_headers
['User-Agent'],
64 }).encode('utf8')).decode('utf8').replace('\n', ''),
66 self
._DISPATCHER
_CONFIG
= self
._parse
_json
(base64
.b64decode(tmp
['data']), 'initialization')
67 return self
._DISPATCHER
_CONFIG
71 'new Date().toISOString()'
72 return datetime
.utcnow().isoformat()[0:-3] + 'Z'
78 self
._GUEST
_ID
= try_get(
80 lambda x
: x
._call
_api
(
81 'https://cloudac.mildom.com/nonolive/gappserv/guest/h5init', 'initialization',
82 note
='Downloading guest token', init
=True)['guest_id'] or None,
83 lambda x
: x
._get
_cookies
('https://www.mildom.com').get('gid').value
,
84 lambda x
: x
._get
_cookies
('https://m.mildom.com').get('gid').value
,
93 class MildomIE(MildomBaseIE
):
95 IE_DESC
= 'Record ongoing live by specific user in Mildom'
96 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/(?P<id>\d+)'
98 def _real_extract(self
, url
):
99 video_id
= self
._match
_id
(url
)
100 url
= 'https://www.mildom.com/%s' % video_id
102 webpage
= self
._download
_webpage
(url
, video_id
)
104 enterstudio
= self
._call
_api
(
105 'https://cloudac.mildom.com/nonolive/gappserv/live/enterstudio', video_id
,
106 note
='Downloading live metadata', query
={'user_id': video_id}
)
107 result_video_id
= enterstudio
.get('log_id', video_id
)
111 lambda x
: self
._html
_search
_meta
('twitter:description', webpage
),
112 lambda x
: x
['anchor_intro'],
114 description
= try_get(
116 lambda x
: x
['intro'],
117 lambda x
: x
['live_intro'],
121 lambda x
: self
._html
_search
_meta
('twitter:title', webpage
),
122 lambda x
: x
['loginname'],
125 servers
= self
._call
_api
(
126 'https://cloudac.mildom.com/nonolive/gappserv/live/liveserver', result_video_id
,
127 note
='Downloading live server list', query
={
129 'live_server_type': 'hls',
132 stream_query
= self
._common
_queries
({
133 'streamReqId': random_uuidv4(),
136 m3u8_url
= update_url_query(servers
['stream_server'] + '/%s_master.m3u8' % video_id
, stream_query
)
137 formats
= self
._extract
_m
3u8_formats
(m3u8_url
, result_video_id
, 'mp4', headers
={
138 'Referer': 'https://www.mildom.com/',
139 'Origin': 'https://www.mildom.com',
140 }, note
='Downloading m3u8 information')
142 del stream_query
['streamReqId'], stream_query
['timestamp']
144 fmt
.setdefault('http_headers', {})['Referer'] = 'https://www.mildom.com/'
146 self
._sort
_formats
(formats
)
149 'id': result_video_id
,
151 'description': description
,
152 'uploader': uploader
,
153 'uploader_id': video_id
,
159 class MildomVodIE(MildomBaseIE
):
160 IE_NAME
= 'mildom:vod'
161 IE_DESC
= 'Download a VOD in Mildom'
162 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/playback/(?P<user_id>\d+)/(?P<id>(?P=user_id)-[a-zA-Z0-9]+)'
164 def _real_extract(self
, url
):
165 m
= re
.match(self
._VALID
_URL
, url
)
166 user_id
, video_id
= m
.group('user_id'), m
.group('id')
167 url
= 'https://www.mildom.com/playback/%s/%s' % (user_id
, video_id
)
169 webpage
= self
._download
_webpage
(url
, video_id
)
171 autoplay
= self
._call
_api
(
172 'https://cloudac.mildom.com/nonolive/videocontent/playback/getPlaybackDetail', video_id
,
173 note
='Downloading playback metadata', query
={
179 lambda x
: self
._html
_search
_meta
('og:description', webpage
),
180 lambda x
: x
['title'],
182 description
= try_get(
184 lambda x
: x
['video_intro'],
188 lambda x
: x
['author_info']['login_name'],
192 'url': autoplay
['audio_url'],
193 'format_id': 'audio',
194 'protocol': 'm3u8_native',
199 for fmt
in autoplay
['video_link']:
201 'format_id': 'video-%s' % fmt
['name'],
203 'protocol': 'm3u8_native',
204 'width': fmt
['level'] * autoplay
['video_width'] // autoplay
['video_height'],
205 'height': fmt
['level'],
211 self
._sort
_formats
(formats
)
216 'description': description
,
217 'uploader': uploader
,
218 'uploader_id': user_id
,
223 class MildomUserVodIE(MildomBaseIE
):
224 IE_NAME
= 'mildom:user:vod'
225 IE_DESC
= 'Download all VODs from specific user in Mildom'
226 _VALID_URL
= r
'https?://(?:(?:www|m)\.)mildom\.com/profile/(?P<id>\d+)'
228 'url': 'https://www.mildom.com/profile/10093333',
231 'title': 'Uploads from ねこばたけ',
233 'playlist_mincount': 351,
236 def _entries(self
, user_id
):
237 for page
in itertools
.count(1):
238 reply
= self
._call
_api
(
239 'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
240 user_id
, note
='Downloading page %d' % page
, query
={
248 yield self
.url_result('https://www.mildom.com/playback/%s/%s' % (user_id
, x
['v_id']))
250 def _real_extract(self
, url
):
251 user_id
= self
._match
_id
(url
)
252 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
)
254 profile
= self
._call
_api
(
255 'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id
,
256 query
={'user_id': user_id}
, note
='Downloading user profile')['user_info']
258 return self
.playlist_result(
259 self
._entries
(user_id
), user_id
, 'Uploads from %s' % profile
['loginname'])