def httpRequest(self, *args, **kwargs): data = kwargs.get('data') if data: kwargs['data'] = encrypted_request(data) html = super(NetEaseWebApi, self).httpRequest(*args, **kwargs) try: return json.loads(html.text) except: return {'code': 0}
def singsUrl(self, ids: list): """ 2017/7/14更新。 返回歌曲的URL。 """ data = encrypted_request({'csrf_token': '', 'ids': ids, 'br': 999000}) url = "http://music.163.com/weapi/song/enhance/player/url" html = self.httpRequest(url, method='POST', data=data) return html['data']
def httpRequest(self, *args, **kwargs): data = kwargs.get('data') if data: kwargs['data'] = encrypted_request(data) logger.info("进行网易云Url请求, args: {0}, kwargs: {1}".format(args, kwargs)) html = super(NetEaseWebApi, self).httpRequest(*args, **kwargs) with ignored(): return json.loads(html.text) logger.info("url: {0} 请求失败. Header: {1}".format( args[0], kwargs.get('headers'))) return False
def search(self, s, offset=0, limit=100, stype=1): """ 搜索. type类型: 单曲(1), 专辑(10), 歌手(100), 歌单(1000), 用户(1002) 2017/7/15更新API. """ # url = 'http://music.163.com/api/search/get/web' url = 'http://music.163.com/weapi/cloudsearch/get/web' data = encrypted_request({ 's': s, 'offset': str(offset), 'limit': str(limit), 'type': str(stype) }) html = self.httpRequest(url, method='POST', data=data) try: return html['result'] except: return {'songCount': 0, 'songs': []}