Python获取QQ音乐歌单歌曲

时间:2024-07-05 15:33:32

准备工作

歌单分享的url地址

比如: https://i.y.qq.com/n2/m/share/details/taoge.html?hosteuin=oKvzoK4l7evk7n**&id=9102222552&appversion=130605&ADTAG=wxfshare&appshare=iphone_wx

代码实现

def mu(share_url):
    share_url = share_url.split('id=')[1].split('&')[0]
    print('share id: ', share_url)

    url = f'https://i.y.qq.com/n2/m/share/details/interactive_playlist.html?ADTAG=ryqq.playlist&id={share_url}'
    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
    }
    r = requests.get(url, headers=headers)
    res = r.content.decode('utf-8')

    res = res.split('firstPageData =')[1].split('"keywords":[')[0][:-1] + '}}'.strip()
    res = res.replace('false', '"false"').replace('null', '"null"')
    res = json.loads(res)

    print('title: ', res['taogeData']['title'])
    print('pic: ', res['taogeData']['picurl'])
    print('song list: ', [{'song title: ': i['title'], 'singer: ': i['singer'][0]['name']} for i in res['taogeData']['songlist']])

识别结果