feat(test): 实现音频文件下载功能
- 替换 os 模块为 requests 库 - 添加音频文件 URL 和请求头配置 - 实现获取文件总长度的功能 - 移除本地音频文件路径和系统调用 - 添加网络请求相关依赖和参数设置
This commit is contained in:
18
test.py
18
test.py
@ -1,4 +1,16 @@
|
|||||||
import os
|
import requests
|
||||||
|
|
||||||
audio_file = "C:/Users/Administrator/Music/国风堂#哦漏 - 知我.mp3"
|
url = "https://er-sycdn.kuwo.cn/5a1fdd7e1178a867af57c6b0ba576889/69468dc3/resource/30106/trackmedia/F000000bYDlc2XxKLs.flac"
|
||||||
os.startfile(audio_file)
|
|
||||||
|
headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||||
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.5',
|
||||||
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
|
}
|
||||||
|
|
||||||
|
total_length = int(requests.get(url, stream=True, headers=headers).headers.get('content-length'))
|
||||||
|
|
||||||
|
print(total_length)
|
||||||
Reference in New Issue
Block a user