2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_unquote
6 from ..utils import int_or_none
9 class XiamiBaseIE(InfoExtractor):
10 _API_BASE_URL = 'http://www.xiami.com/song/playlist/cat/json/id'
12 def _extract_track(self, track, track_id=None):
13 title = track['title']
14 track_url = self._decrypt(track['location'])
17 lyrics_url = track.get('lyric_url') or track.get('lyric')
18 if lyrics_url and lyrics_url.startswith('http'):
19 subtitles['origin'] = [{'url': lyrics_url}]
22 'id': track.get('song_id') or track_id,
25 'thumbnail': track.get('pic') or track.get('album_pic'),
26 'duration': int_or_none(track.get('length')),
27 'creator': track.get('artist', '').split(';')[0],
29 'album': track.get('album_name'),
30 'artist': track.get('artist'),
31 'subtitles': subtitles,
34 def _extract_tracks(self, item_id, typ=None):
35 playlist = self._download_json(
36 '%s/%s%s' % (self._API_BASE_URL, item_id, '/type/%s' % typ if typ else ''), item_id)
38 self._extract_track(track, item_id)
39 for track in playlist['data']['trackList']]
45 short_lenth = len(origin) // n
46 long_num = len(origin) - short_lenth * n
52 l += (origin[0:length], )
53 origin = origin[length:]
55 for i in range(0, short_lenth + 1):
59 return compat_urllib_parse_unquote(ans).replace('^', '0')
62 class XiamiSongIE(XiamiBaseIE):
63 IE_NAME = 'xiami:song'
65 _VALID_URL = r'https?://(?:www\.)?xiami\.com/song/(?P<id>[0-9]+)'
67 'url': 'http://www.xiami.com/song/1775610518',
68 'md5': '521dd6bea40fd5c9c69f913c232cb57e',
73 'thumbnail': r're:http://img\.xiami\.net/images/album/.*\.jpg',
86 'url': 'http://www.xiami.com/song/1775256504',
87 'md5': '932a3abd45c6aa2b1fdbe028fcb4c4fc',
92 'thumbnail': r're:http://img\.xiami\.net/images/album/.*\.jpg',
106 def _real_extract(self, url):
107 return self._extract_tracks(self._match_id(url))[0]
110 class XiamiPlaylistBaseIE(XiamiBaseIE):
111 def _real_extract(self, url):
112 item_id = self._match_id(url)
113 return self.playlist_result(self._extract_tracks(item_id, self._TYPE), item_id)
116 class XiamiAlbumIE(XiamiPlaylistBaseIE):
117 IE_NAME = 'xiami:album'
118 IE_DESC = '虾米音乐 - 专辑'
119 _VALID_URL = r'https?://(?:www\.)?xiami\.com/album/(?P<id>[0-9]+)'
122 'url': 'http://www.xiami.com/album/2100300444',
126 'playlist_count': 10,
128 'url': 'http://www.xiami.com/album/512288?spm=a1z1s.6843761.1110925389.6.hhE9p9',
129 'only_matching': True,
133 class XiamiArtistIE(XiamiPlaylistBaseIE):
134 IE_NAME = 'xiami:artist'
135 IE_DESC = '虾米音乐 - 歌手'
136 _VALID_URL = r'https?://(?:www\.)?xiami\.com/artist/(?P<id>[0-9]+)'
139 'url': 'http://www.xiami.com/artist/2132?spm=0.0.0.0.dKaScp',
143 'playlist_count': 20,
147 class XiamiCollectionIE(XiamiPlaylistBaseIE):
148 IE_NAME = 'xiami:collection'
149 IE_DESC = '虾米音乐 - 精选集'
150 _VALID_URL = r'https?://(?:www\.)?xiami\.com/collect/(?P<id>[0-9]+)'
153 'url': 'http://www.xiami.com/collect/156527391?spm=a1z1s.2943601.6856193.12.4jpBnr',
157 'playlist_mincount': 29,