Beispiel #1
0
    def lyric(self, url):
        lyric = self.httpRequest(url, method='GET', headers=self.lyricHeader)

        with ignored():
            lyric = lyric.split('[offset:0]')[1]
            lyric = re.sub(r'<\d*?>', '', lyric)
            return lyric

        with ignored():
            loadingLyric = {}
            lyricTimes = []
            for i in lyric.split('\n'):
                oneLyric = re.findall(r'[0-9:\.]+', i)
                if not oneLyric or oneLyric == [':']:
                    continue
                else:
                    for x in oneLyric:
                        i = i.replace('[{}]'.format(x), '')
                    for x in oneLyric:
                        loadingLyric[x] = i
                    lyricTimes.extend(oneLyric)

            return '\n'.join([
                '[{time}]{content}'.format(time=x, content=loadingLyric.get(x))
                for x in sorted(lyricTimes)
            ])

        return False
Beispiel #2
0
    def playList(self, page=1):
        url = 'http://api.xiami.com/web?v=2.0&app_key=1&_ksTS=1459927525542_91' + \
            '&page={0}&limit=30&callback=jsonp92&r=collect/recommend'.format(page)

        response = self.httpRequest(url, method='GET')

        with ignored():
            response = json.loads(response[len('jsonp92('):-len(')')])
            return response['data']

        return False
Beispiel #3
0
    def httpRequest(self, *args, **kwargs):
        html = super(XiamiApi, self).httpRequest(*args, **kwargs)

        logger.info("进行xiami Url请求, args: {0}, kwargs: {1}".format(
            args, kwargs))

        with ignored():
            return html.text

        logger.info("url: {0} 请求失败. Header: {1}".format(
            args[0], kwargs.get('headers')))
        return ''
Beispiel #4
0
    def getPlaylist(self, ids):
        url = 'http://api.xiami.com/web?v=2.0&app_key=1&id={0}'.format(ids) + \
        '&_ksTS=1459928471147_121&callback=jsonp122&r=collect/detail'
        response = self.httpRequest(url, 'GET')

        with ignored():
            response = json.loads(response[len('jsonp122('):-len(')')])

            data = response['data']
            data['name'] = data['collect_name']
            data['creator'] = {'nickname': data['user_name']}
            data['description'] = ''
            data['trackCount'] = data['songs_count']
            songs = data['songs']
            for i in songs:
                i['name'] = i['song_name']
                i['artists'] = [{'name': i['singers']}]
                i['duration'] = int(i['length']) * 1000
                i['album'] = {'blurPicUrl': i['album_logo']}

            data['tracks'] = songs
            return response['data']

        return False