]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/yandexmusic.py
f4c0f5702e59bea80046438606dd9a28271d8a30
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_str
15 class YandexMusicBaseIE(InfoExtractor
):
16 def _get_track_url(self
, storage_dir
, track_id
):
17 data
= self
._download
_json
(
18 'http://music.yandex.ru/api/v1.5/handlers/api-jsonp.jsx?action=getTrackSrc&p=download-info/%s'
20 track_id
, 'Downloading track location JSON')
22 key
= hashlib
.md5(('XGRlBW9FXlekgbPrRHuSiA' + data
['path'][1:] + data
['s']).encode('utf-8')).hexdigest()
23 storage
= storage_dir
.split('.')
25 return ('http://%s/get-mp3/%s/%s?track-id=%s&from=service-10-track&similarities-experiment=default'
26 % (data
['host'], key
, data
['ts'] + data
['path'], storage
[1]))
28 def _get_track_info(self
, track
):
32 'url': self
._get
_track
_url
(track
['storageDir'], track
['id']),
33 'title': '%s - %s' % (track
['artists'][0]['name'], track
['title']),
34 'filesize': int_or_none(track
.get('fileSize')),
35 'duration': float_or_none(track
.get('durationMs'), 1000),
39 class YandexMusicTrackIE(YandexMusicBaseIE
):
40 IE_NAME
= 'yandexmusic:track'
41 IE_DESC
= 'Яндекс.Музыка - Трек'
42 _VALID_URL
= r
'https?://music\.yandex\.(?:ru|kz|ua|by)/album/(?P<album_id>\d+)/track/(?P<id>\d+)'
45 'url': 'http://music.yandex.ru/album/540508/track/4878838',
46 'md5': 'f496818aa2f60b6c0062980d2e00dc20',
50 'title': 'Carlo Ambrosio - Gypsy Eyes 1',
56 def _real_extract(self
, url
):
57 mobj
= re
.match(self
._VALID
_URL
, url
)
58 album_id
, track_id
= mobj
.group('album_id'), mobj
.group('id')
60 track
= self
._download
_json
(
61 'http://music.yandex.ru/handlers/track.jsx?track=%s:%s' % (track_id
, album_id
),
62 track_id
, 'Downloading track JSON')['track']
64 return self
._get
_track
_info
(track
)
67 class YandexMusicAlbumIE(YandexMusicBaseIE
):
68 IE_NAME
= 'yandexmusic:album'
69 IE_DESC
= 'Яндекс.Музыка - Альбом'
70 _VALID_URL
= r
'https?://music\.yandex\.(?:ru|kz|ua|by)/album/(?P<id>\d+)/?(\?|$)'
73 'url': 'http://music.yandex.ru/album/540508',
76 'title': 'Carlo Ambrosio - Gypsy Soul (2009)',
81 def _real_extract(self
, url
):
82 album_id
= self
._match
_id
(url
)
84 album
= self
._download
_json
(
85 'http://music.yandex.ru/handlers/album.jsx?album=%s' % album_id
,
86 album_id
, 'Downloading album JSON')
88 entries
= [self
._get
_track
_info
(track
) for track
in album
['volumes'][0]]
90 title
= '%s - %s' % (album
['artists'][0]['name'], album
['title'])
91 year
= album
.get('year')
93 title
+= ' (%s)' % year
95 return self
.playlist_result(entries
, compat_str(album
['id']), title
)
98 class YandexMusicPlaylistIE(YandexMusicBaseIE
):
99 IE_NAME
= 'yandexmusic:playlist'
100 IE_DESC
= 'Яндекс.Музыка - Плейлист'
101 _VALID_URL
= r
'https?://music\.yandex\.(?:ru|kz|ua|by)/users/[^/]+/playlists/(?P<id>\d+)'
104 'url': 'http://music.yandex.ru/users/music.partners/playlists/1245',
107 'title': 'Что слушают Enter Shikari',
108 'description': 'md5:3b9f27b0efbe53f2ee1e844d07155cc9',
113 def _real_extract(self
, url
):
114 playlist_id
= self
._match
_id
(url
)
116 webpage
= self
._download
_webpage
(url
, playlist_id
)
118 playlist
= self
._parse
_json
(
120 r
'var\s+Mu\s*=\s*({.+?});\s*</script>', webpage
, 'player'),
121 playlist_id
)['pageData']['playlist']
123 entries
= [self
._get
_track
_info
(track
) for track
in playlist
['tracks']]
125 return self
.playlist_result(
126 entries
, compat_str(playlist_id
),
127 playlist
['title'], playlist
.get('description'))