-
- _XML_BASE_URL = 'http://www.xiami.com/song/playlist/id'
- _NS_MAP = {'xm': 'http://xspf.org/ns/0/'}
-
- def _extract_track(self, track):
- artist = xpath_text(track, xpath_with_ns('xm:artist', self._NS_MAP), default='')
- artist = artist.split(';')
-
- ret = {
- 'id': xpath_text(track, xpath_with_ns('xm:song_id', self._NS_MAP)),
- 'title': xpath_text(track, xpath_with_ns('xm:title', self._NS_MAP)),
- 'album': xpath_text(track, xpath_with_ns('xm:album_name', self._NS_MAP)),
- 'artist': ';'.join(artist) if artist else None,
- 'creator': artist[0] if artist else None,
- 'url': self._decrypt(xpath_text(track, xpath_with_ns('xm:location', self._NS_MAP))),
- 'thumbnail': xpath_text(track, xpath_with_ns('xm:pic', self._NS_MAP), default=None),
- 'duration': int_or_none(xpath_text(track, xpath_with_ns('xm:length', self._NS_MAP))),
+ _API_BASE_URL = 'http://www.xiami.com/song/playlist/cat/json/id'
+
+ def _download_webpage_handle(self, *args, **kwargs):
+ webpage = super(XiamiBaseIE, self)._download_webpage_handle(*args, **kwargs)
+ if '>Xiami is currently not available in your country.<' in webpage:
+ self.raise_geo_restricted('Xiami is currently not available in your country')
+ return webpage
+
+ def _extract_track(self, track, track_id=None):
+ track_name = track.get('songName') or track.get('name') or track['subName']
+ artist = track.get('artist') or track.get('artist_name') or track.get('singers')
+ title = '%s - %s' % (artist, track_name) if artist else track_name
+ track_url = self._decrypt(track['location'])
+
+ subtitles = {}
+ lyrics_url = track.get('lyric_url') or track.get('lyric')
+ if lyrics_url and lyrics_url.startswith('http'):
+ subtitles['origin'] = [{'url': lyrics_url}]
+
+ return {
+ 'id': track.get('song_id') or track_id,
+ 'url': track_url,
+ 'title': title,
+ 'thumbnail': track.get('pic') or track.get('album_pic'),
+ 'duration': int_or_none(track.get('length')),
+ 'creator': track.get('artist', '').split(';')[0],
+ 'track': track_name,
+ 'track_number': int_or_none(track.get('track')),
+ 'album': track.get('album_name') or track.get('title'),
+ 'artist': artist,
+ 'subtitles': subtitles,