Skip to content

Instantly share code, notes, and snippets.

@lybc
Last active September 8, 2019 05:52
Show Gist options
  • Select an option

  • Save lybc/8affe24852e4e4ead167123b1feffa71 to your computer and use it in GitHub Desktop.

Select an option

Save lybc/8affe24852e4e4ead167123b1feffa71 to your computer and use it in GitHub Desktop.
下载网易云音乐 #Python
import requests
import os
host = 'http://wyy.lybc.site'
play_list_id = input("请输入歌单id: ")
play_list_detail = requests.get(host + '/playlist/detail?id=' + play_list_id).json()
print('获取歌单成功!歌单名称:{}, 共有歌曲 {} 首!'.format(
play_list_detail['playlist']['name'],
len(play_list_detail['playlist']['tracks'])
))
print('下载中...')
for music in play_list_detail['playlist']['tracks']:
music_url = host + '/song/url?id=' + str(music['id'])
music_detail = requests.get(music_url).json()
if music_detail['code'] and music_detail['code'] == 200:
print('获取歌曲信息成功,正在下载[{}]...'.format(music['name']))
music_resource = music_detail['data'][0]
if music_resource['url']:
raw_file = requests.get(music_resource['url'])
file_ext_name = os.path.splitext(music_resource['url'])[-1][1:]
with open("{}/{}.{}".format(os.path.dirname(os.path.abspath(__file__)), music['name'], file_ext_name), 'wb') as mp3:
mp3.write(raw_file.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment