5 from .common
import InfoExtractor
6 from ..compat
import compat_urllib_parse_unquote
16 class MailRuIE(InfoExtractor
):
18 IE_DESC
= 'Видео@Mail.Ru'
21 (?:(?:www|m|videoapi)\.)?my\.mail\.ru/+
23 video/.*\#video=/?(?P<idv1>(?:[^/]+/){3}\d+)|
24 (?:videos/embed/)?(?:(?P<idv2prefix>(?:[^/]+/+){2})(?:video/(?:embed/)?)?(?P<idv2suffix>[^/]+/\d+))(?:\.html)?|
25 (?:video/embed|\+/video/meta)/(?P<metaid>\d+)
30 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
31 'md5': 'dea205f03120046894db4ebb6159879a',
35 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
36 'timestamp': 1393235077,
37 'upload_date': '20140224',
38 'uploader': 'sonypicturesrus',
39 'uploader_id': 'sonypicturesrus@mail.ru',
42 'skip': 'Not accessible from Travis CI server',
45 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
46 'md5': '00a91a58c3402204dcced523777b475f',
48 'id': '46843144_1263',
50 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
51 'timestamp': 1397039888,
52 'upload_date': '20140409',
54 'uploader_id': 'hitech@corp.mail.ru',
57 'skip': 'Not accessible from Travis CI server',
60 # only available via metaUrl API
61 'url': 'http://my.mail.ru/mail/720pizle/video/_myvideo/502.html',
62 'md5': '3b26d2491c6949d031a32b96bd97c096',
67 'timestamp': 1449094163,
68 'upload_date': '20151202',
69 'uploader': '720pizle@mail.ru',
70 'uploader_id': '720pizle@mail.ru',
73 'skip': 'Not accessible from Travis CI server',
76 'url': 'http://m.my.mail.ru/mail/3sktvtr/video/_myvideo/138.html',
77 'only_matching': True,
80 'url': 'https://my.mail.ru/video/embed/7949340477499637815',
81 'only_matching': True,
84 'url': 'http://my.mail.ru/+/video/meta/7949340477499637815',
85 'only_matching': True,
88 'url': 'https://my.mail.ru//list/sinyutin10/video/_myvideo/4.html',
89 'only_matching': True,
92 'url': 'https://my.mail.ru//list//sinyutin10/video/_myvideo/4.html',
93 'only_matching': True,
96 'url': 'https://my.mail.ru/mail/cloud-strife/video/embed/Games/2009',
97 'only_matching': True,
100 'url': 'https://videoapi.my.mail.ru/videos/embed/mail/cloud-strife/Games/2009.html',
101 'only_matching': True,
105 def _real_extract(self
, url
):
106 mobj
= self
._match
_valid
_url
(url
)
107 meta_id
= mobj
.group('metaid')
111 meta_url
= 'https://my.mail.ru/+/video/meta/%s' % meta_id
113 video_id
= mobj
.group('idv1')
115 video_id
= mobj
.group('idv2prefix') + mobj
.group('idv2suffix')
116 webpage
= self
._download
_webpage
(url
, video_id
)
117 page_config
= self
._parse
_json
(self
._search
_regex
([
118 r
'(?s)<script[^>]+class="sp-video__page-config"[^>]*>(.+?)</script>',
119 r
'(?s)"video":\s*({.+?}),'],
120 webpage
, 'page config', default
='{}'), video_id
, fatal
=False)
122 meta_url
= page_config
.get('metaUrl') or page_config
.get('video', {}).get('metaUrl') or page_config
.get('metadataUrl')
128 # fix meta_url if missing the host address
129 if re
.match(r
'^\/\+\/', meta_url
):
130 meta_url
= urljoin('https://my.mail.ru', meta_url
)
133 video_data
= self
._download
_json
(
134 meta_url
, video_id
or meta_id
, 'Downloading video meta JSON',
137 # Fallback old approach
139 video_data
= self
._download
_json
(
140 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id
,
141 video_id
, 'Downloading video JSON')
145 video_key
= self
._get
_cookies
('https://my.mail.ru').get('video_key')
147 headers
['Cookie'] = 'video_key=%s' % video_key
.value
150 for f
in video_data
['videos']:
151 video_url
= f
.get('url')
154 format_id
= f
.get('key')
155 height
= int_or_none(self
._search
_regex
(
156 r
'^(\d+)[pP]$', format_id
, 'height', default
=None)) if format_id
else None
159 'format_id': format_id
,
161 'http_headers': headers
,
163 self
._sort
_formats
(formats
)
165 meta_data
= video_data
['meta']
166 title
= remove_end(meta_data
['title'], '.mp4')
168 author
= video_data
.get('author')
169 uploader
= author
.get('name')
170 uploader_id
= author
.get('id') or author
.get('email')
171 view_count
= int_or_none(video_data
.get('viewsCount') or video_data
.get('views_count'))
173 acc_id
= meta_data
.get('accId')
174 item_id
= meta_data
.get('itemId')
175 content_id
= '%s_%s' % (acc_id
, item_id
) if acc_id
and item_id
else video_id
177 thumbnail
= meta_data
.get('poster')
178 duration
= int_or_none(meta_data
.get('duration'))
179 timestamp
= int_or_none(meta_data
.get('timestamp'))
184 'thumbnail': thumbnail
,
185 'timestamp': timestamp
,
186 'uploader': uploader
,
187 'uploader_id': uploader_id
,
188 'duration': duration
,
189 'view_count': view_count
,
194 class MailRuMusicSearchBaseIE(InfoExtractor
):
195 def _search(self
, query
, url
, audio_id
, limit
=100, offset
=0):
196 search
= self
._download
_json
(
197 'https://my.mail.ru/cgi-bin/my/ajax', audio_id
,
198 'Downloading songs JSON page %d' % (offset
// limit
+ 1),
201 'X-Requested-With': 'XMLHttpRequest',
205 'func_name': 'music.search',
210 'arg_search_params': json
.dumps({
217 'arg_offset': offset
,
219 return next(e
for e
in search
if isinstance(e
, dict))
222 def _extract_track(t
, fatal
=True):
223 audio_url
= t
['URL'] if fatal
else t
.get('URL')
227 audio_id
= t
['File'] if fatal
else t
.get('File')
231 thumbnail
= t
.get('AlbumCoverURL') or t
.get('FiledAlbumCover')
232 uploader
= t
.get('OwnerName') or t
.get('OwnerName_Text_HTML')
233 uploader_id
= t
.get('UploaderID')
234 duration
= int_or_none(t
.get('DurationInSeconds')) or parse_duration(
235 t
.get('Duration') or t
.get('DurationStr'))
236 view_count
= int_or_none(t
.get('PlayCount') or t
.get('PlayCount_hr'))
238 track
= t
.get('Name') or t
.get('Name_Text_HTML')
239 artist
= t
.get('Author') or t
.get('Author_Text_HTML')
242 title
= '%s - %s' % (artist
, track
) if artist
else track
247 'extractor_key': MailRuMusicIE
.ie_key(),
250 'thumbnail': thumbnail
,
251 'uploader': uploader
,
252 'uploader_id': uploader_id
,
253 'duration': duration
,
254 'view_count': view_count
,
256 'abr': int_or_none(t
.get('BitRate')),
259 'album': t
.get('Album'),
264 class MailRuMusicIE(MailRuMusicSearchBaseIE
):
265 IE_NAME
= 'mailru:music'
266 IE_DESC
= 'Музыка@Mail.Ru'
267 _VALID_URL
= r
'https?://my\.mail\.ru/+music/+songs/+[^/?#&]+-(?P<id>[\da-f]+)'
269 'url': 'https://my.mail.ru/music/songs/%D0%BC8%D0%BB8%D1%82%D1%85-l-a-h-luciferian-aesthetics-of-herrschaft-single-2017-4e31f7125d0dfaef505d947642366893',
270 'md5': '0f8c22ef8c5d665b13ac709e63025610',
272 'id': '4e31f7125d0dfaef505d947642366893',
274 'title': 'L.A.H. (Luciferian Aesthetics of Herrschaft) single, 2017 - М8Л8ТХ',
275 'uploader': 'Игорь Мудрый',
276 'uploader_id': '1459196328',
281 'track': 'L.A.H. (Luciferian Aesthetics of Herrschaft) single, 2017',
286 def _real_extract(self
, url
):
287 audio_id
= self
._match
_id
(url
)
289 webpage
= self
._download
_webpage
(url
, audio_id
)
291 title
= self
._og
_search
_title
(webpage
)
292 music_data
= self
._search
(title
, url
, audio_id
)['MusicData']
293 t
= next(t
for t
in music_data
if t
.get('File') == audio_id
)
295 info
= self
._extract
_track
(t
)
296 info
['title'] = title
300 class MailRuMusicSearchIE(MailRuMusicSearchBaseIE
):
301 IE_NAME
= 'mailru:music:search'
302 IE_DESC
= 'Музыка@Mail.Ru'
303 _VALID_URL
= r
'https?://my\.mail\.ru/+music/+search/+(?P<id>[^/?#&]+)'
305 'url': 'https://my.mail.ru/music/search/black%20shadow',
307 'id': 'black shadow',
309 'playlist_mincount': 532,
312 def _real_extract(self
, url
):
313 query
= compat_urllib_parse_unquote(self
._match
_id
(url
))
320 for _
in itertools
.count(1):
321 search
= self
._search
(query
, url
, query
, LIMIT
, offset
)
323 music_data
= search
.get('MusicData')
324 if not music_data
or not isinstance(music_data
, list):
328 track
= self
._extract
_track
(t
, fatal
=False)
330 entries
.append(track
)
333 search
, lambda x
: x
['Results']['music']['Total'], int)
335 if total
is not None:
341 return self
.playlist_result(entries
, query
)