[Python] 纯文本查看 复制代码def migu_search(keyword, page=1):
params = {
'feature': '1111000000',
'isCopyright': 1,
'isCorrect': 1,
'pageIndex': page,
'pageSize': 20,
'searchSwitch':'{"song":1,"album":0,"singer":0,"tagSong":1,"mvSong":0,"songlist":0,"bestShow":1,"lyricSong":0,"concert":0,"periodical":0,"ticket":0,"bit24":0,"verticalVideoTone":0}',
'sort': 0,
'text': keyword,
'uiVersion': 'I_music_3.0.2',
}
response = Api.request('http://jadeite.migu.cn:7090/music_search/v2/search/searchAll', "GET", params)
res_data = response.get('songResultData', {}).get("resultList", [])
print(json.dumps(res_data))
result = []
for items in res_data:
for item in items:
singers = ','.join([s.get("name", "") for s in item.get('singers')])
song = {
'song_name': item.get('name'),
'singers': singers
}
rate_list = item.get('rateFormats', [])
urls = {}
for x in rate_list:
if len(x.get('url', "")) > 0:
urls[x.get('formatType')] = x.get('url').replace('ftp://218.200.160.122:21', 'http://freetyst.nf.migu.cn')
else:
format_type = x.get('formatType')
if format_type == 'SQ':
urls['SQ-flac'] = x.get('androidUrl').replace('ftp://218.200.160.122:21', 'http://freetyst.nf.migu.cn')
urls['SQ-m4a'] = x.get('iosUrl').replace('ftp://218.200.160.122:21', 'http://freetyst.nf.migu.cn')
song['urls'] = urls
result.append(song)
return result
if __name__ == '__main__':
r = migu_search("周杰伦", 1)
print(json.dumps(r, indent=4))