def requests_url(self, ptype, **data): """ 这里包装了一个函数,发送post_data :param ptype: n 列表无歌曲,返回新列表 e 发送歌曲完毕 b 不再播放,返回新列表 s 下一首,返回新的列表 r 标记喜欢 u 取消标记喜欢 """ options = { 'type': ptype, 'pt': '3.1', 'channel': self._channel_id, 'pb': '128', 'from': 'mainsite', 'r': '' } if 'sid' in data: options['sid'] = data['sid'] url = 'http://douban.fm/j/mine/playlist' while 1: try: s = requests.get(url, params=options, cookies=self._cookies, headers=HEADERS) req_json = s.json() if req_json['r'] == 0: if 'song' not in req_json: break return req_json['song'][0] except Exception, err: raise APIError(err) break
def get_captcha_id(): try: r = requests.get('https://douban.fm/j/new_captcha', headers=HEADERS) r.raise_for_status() return r.text.strip('"') except Exception as e: raise APIError('get captcha id error: ' + str(e))
def requests_url(self, ptype, **data): """ 这里包装了一个函数,发送post_data :param ptype: n 列表无歌曲,返回新列表 e 发送歌曲完毕 b 不再播放,返回新列表 s 下一首,返回新的列表 r 标记喜欢 u 取消标记喜欢 """ options = { 'type': ptype, 'pt': '3.1', 'channel': self._channel_id, 'pb': '320', 'from': 'mainsite', 'r': '', 'kbps': '320', 'app_name': 'radio_website', 'client': 's:mainsite|y:3.0', 'version': '100' } if 'sid' in data: options['sid'] = data['sid'] url = 'https://douban.fm/j/v2/playlist' while True: try: s = requests.get(url, params=options, cookies=self._cookies, headers=HEADERS) req_json = s.json() if req_json['r'] == 0: if 'song' not in req_json or not req_json['song']: break return req_json['song'][0] except Exception as err: raise APIError(err) break return None
def get_captcha_id(): try: r = requests.get('http://douban.fm/j/new_captcha', headers=HEADERS) return r.text.strip('"') except Exception as e: raise APIError('get_captcha_id error ' + e)