"""
# 下载歌曲的代码
path = 'https://webfs.yun.kugou.com/201908192103/34f30c50f3dddf902489d8329b5a8256/G072/M03/1B/04/iA0DAFc4Oq2ASH8UACk2YICuxZ0695.mp3'
import requests
response = requests.get(path)
mp3_ = response.content
with open('C:\\Users\\侯文涵\\Desktop\\music',mode='wb') as f:
f.write(mp3_)
"""
# 获取歌曲URL
import multiprocessing
import json
import requests
import os
def A():
with open('C:\\Users\\侯文涵\\Desktop\\python\\Day05\\top_500.txt',mode='r') as f:
res = f.readlines()[0].strip('\n').split('}')
song = []
for json_ in res[:-1]:
_json = json_ + '}'
_json = json.loads(_json)
song_play_url = _json['song_play_url']
song_name = _json ['song_name']
if song_play_url is not None:
song.append(song_play_url)
for i in song[0 : 23]:
path = i
response = requests.get(path)
mp3_ = response.content
with open('C:\\Users\\侯文涵\\Desktop\\music\\'+ song_name + '.mp3',mode='wb') as f:
f.write(mp3_)
def B():
with open('C:\\Users\\侯文涵\\Desktop\\python\\Day05\\top_500.txt',mode='r') as f:
res = f.readlines()[0].strip('\n').split('}')
song = []
for json_ in res[:-1]:
_json = json_ + '}'
_json = json.loads(_json)
song_play_url = _json['song_play_url']
song_name = _json ['song_name']
if song_play_url is not None:
song.append(song_play_url)
for i in song[23 : 47]:
path = i
response = requests.get(path)
mp3_ = response.content
with open('C:\\Users\\侯文涵\\Desktop\\music\\'+ song_name + '.mp3',mode='wb') as f:
f.write(mp3_)
if __name__ == "__main__":
s1 = multiprocessing.Process(target=A)
s2 = multiprocessing.Process(target=A)
s1.start()
s2.start()
s1.join()
s2.join()
print('ok')
HomeWorkDay05---歌曲下载
最新推荐文章于 2022-11-29 22:13:52 发布