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')
18 def _extract_track(self
, track
, track_id
=None):
19 title
= track
['title']
20 track_url
= self
._decrypt
(track
['location'])
23 lyrics_url
= track
.get('lyric_url') or track
.get('lyric')
24 if lyrics_url
and lyrics_url
.startswith('http'):
25 subtitles
['origin'] = [{'url': lyrics_url}
]
28 'id': track
.get('song_id') or track_id
,
31 'thumbnail': track
.get('pic') or track
.get('album_pic'),
32 'duration': int_or_none(track
.get('length')),
33 'creator': track
.get('artist', '').split(';')[0],
35 'album': track
.get('album_name'),
36 'artist': track
.get('artist'),
37 'subtitles': subtitles
,
40 def _extract_tracks(self
, item_id
, typ
=None):
41 playlist
= self
._download
_json
(
42 '%s/%s%s' % (self
._API
_BASE
_URL
, item_id
, '/type/%s' % typ
if typ
else ''), item_id
)
44 self
._extract
_track
(track
, item_id
)
45 for track
in playlist
['data']['trackList']]
51 short_lenth
= len(origin
) // n
52 long_num
= len(origin
) - short_lenth
* n
58 l
+= (origin
[0:length
], )
59 origin
= origin
[length
:]
61 for i
in range(0, short_lenth
+ 1):
65 return compat_urllib_parse_unquote(ans
).replace('^', '0')
68 class XiamiSongIE(XiamiBaseIE
):
69 IE_NAME
= 'xiami:song'
71 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/song/(?P<id>[0-9]+)'
73 'url': 'http://www.xiami.com/song/1775610518',
74 'md5': '521dd6bea40fd5c9c69f913c232cb57e',
79 'thumbnail': r
're:http://img\.xiami\.net/images/album/.*\.jpg',
91 'skip': 'Georestricted',
93 'url': 'http://www.xiami.com/song/1775256504',
94 'md5': '932a3abd45c6aa2b1fdbe028fcb4c4fc',
99 'thumbnail': r
're:http://img\.xiami\.net/images/album/.*\.jpg',
111 'skip': 'Georestricted',
114 def _real_extract(self
, url
):
115 return self
._extract
_tracks
(self
._match
_id
(url
))[0]
118 class XiamiPlaylistBaseIE(XiamiBaseIE
):
119 def _real_extract(self
, url
):
120 item_id
= self
._match
_id
(url
)
121 return self
.playlist_result(self
._extract
_tracks
(item_id
, self
._TYPE
), item_id
)
124 class XiamiAlbumIE(XiamiPlaylistBaseIE
):
125 IE_NAME
= 'xiami:album'
126 IE_DESC
= '虾米音乐 - 专辑'
127 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/album/(?P<id>[0-9]+)'
130 'url': 'http://www.xiami.com/album/2100300444',
134 'playlist_count': 10,
135 'skip': 'Georestricted',
137 'url': 'http://www.xiami.com/album/512288?spm=a1z1s.6843761.1110925389.6.hhE9p9',
138 'only_matching': True,
142 class XiamiArtistIE(XiamiPlaylistBaseIE
):
143 IE_NAME
= 'xiami:artist'
144 IE_DESC
= '虾米音乐 - 歌手'
145 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/artist/(?P<id>[0-9]+)'
148 'url': 'http://www.xiami.com/artist/2132?spm=0.0.0.0.dKaScp',
152 'playlist_count': 20,
153 'skip': 'Georestricted',
157 class XiamiCollectionIE(XiamiPlaylistBaseIE
):
158 IE_NAME
= 'xiami:collection'
159 IE_DESC
= '虾米音乐 - 精选集'
160 _VALID_URL
= r
'https?://(?:www\.)?xiami\.com/collect/(?P<id>[0-9]+)'
163 'url': 'http://www.xiami.com/collect/156527391?spm=a1z1s.2943601.6856193.12.4jpBnr',
167 'playlist_mincount': 29,
168 'skip': 'Georestricted',