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 _download_webpage(self
, *args
, **kwargs
):
13 webpage
= super(XiamiBaseIE
, self
)._download
_webpage
(*args
, **kwargs
)
14 if '>Xiami is currently not available in your country.<' in webpage
:
15 self
.raise_geo_restricted('Xiami is currently not available in your country')
17 def _extract_track(self
, track
, track_id
=None):
18 title
= track
['title']
19 track_url
= self
._decrypt
(track
['location'])
22 lyrics_url
= track
.get('lyric_url') or track
.get('lyric')
23 if lyrics_url
and lyrics_url
.startswith('http'):
24 subtitles
['origin'] = [{'url': lyrics_url
}]
27 'id': track
.get('song_id') or track_id
,
30 'thumbnail': track
.get('pic') or track
.get('album_pic'),
31 'duration': int_or_none(track
.get('length')),
32 'creator': track
.get('artist', '').split(';')[0],
34 'album': track
.get('album_name'),
35 'artist': track
.get('artist'),
36 'subtitles': subtitles
,
39 def _extract_tracks(self
, item_id
, typ
=None):
40 playlist
= self
._download
_json
(
41 '%s/%s%s' % (self
._API
_BASE
_URL
, item_id
, '/type/%s' % typ
if typ
else ''), item_id
)
43 self
._extract
_track
(track
, item_id
)
44 for track
in playlist
['data']['trackList']]
50 short_lenth
= len(origin
) // n
51 long_num
= len(origin
) - short_lenth
* n
57 l
+= (origin
[0:length
], )
58 origin
= origin
[length
:]
60 for i
in range(0, short_lenth
+ 1):
64 return compat_urllib_parse_unquote(ans
).replace('^', '0')
67 class XiamiSongIE(XiamiBaseIE
):
68 IE_NAME
= 'xiami:song'
70 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/song/(?P<id>[0-9]+)'
72 'url': 'http://www.xiami.com/song/1775610518',
73 'md5': '521dd6bea40fd5c9c69f913c232cb57e',
78 'thumbnail': r
're:http://img\.xiami\.net/images/album/.*\.jpg',
90 'skip': 'Georestricted',
92 'url': 'http://www.xiami.com/song/1775256504',
93 'md5': '932a3abd45c6aa2b1fdbe028fcb4c4fc',
98 'thumbnail': r
're:http://img\.xiami\.net/images/album/.*\.jpg',
110 'skip': 'Georestricted',
113 def _real_extract(self
, url
):
114 return self
._extract
_tracks
(self
._match
_id
(url
))[0]
117 class XiamiPlaylistBaseIE(XiamiBaseIE
):
118 def _real_extract(self
, url
):
119 item_id
= self
._match
_id
(url
)
120 return self
.playlist_result(self
._extract
_tracks
(item_id
, self
._TYPE
), item_id
)
123 class XiamiAlbumIE(XiamiPlaylistBaseIE
):
124 IE_NAME
= 'xiami:album'
125 IE_DESC
= '虾米音乐 - 专辑'
126 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/album/(?P<id>[0-9]+)'
129 'url': 'http://www.xiami.com/album/2100300444',
133 'playlist_count': 10,
134 'skip': 'Georestricted',
136 'url': 'http://www.xiami.com/album/512288?spm=a1z1s.6843761.1110925389.6.hhE9p9',
137 'only_matching': True,
141 class XiamiArtistIE(XiamiPlaylistBaseIE
):
142 IE_NAME
= 'xiami:artist'
143 IE_DESC
= '虾米音乐 - 歌手'
144 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/artist/(?P<id>[0-9]+)'
147 'url': 'http://www.xiami.com/artist/2132?spm=0.0.0.0.dKaScp',
151 'playlist_count': 20,
152 'skip': 'Georestricted',
156 class XiamiCollectionIE(XiamiPlaylistBaseIE
):
157 IE_NAME
= 'xiami:collection'
158 IE_DESC
= '虾米音乐 - 精选集'
159 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/collect/(?P<id>[0-9]+)'
162 'url': 'http://www.xiami.com/collect/156527391?spm=a1z1s.2943601.6856193.12.4jpBnr',
166 'playlist_mincount': 29,
167 'skip': 'Georestricted',