- 替换 os 模块为 requests 库 - 添加音频文件 URL 和请求头配置 - 实现获取文件总长度的功能 - 移除本地音频文件路径和系统调用 - 添加网络请求相关依赖和参数设置
16 lines
656 B
Python
16 lines
656 B
Python
import requests
|
|
|
|
url = "https://er-sycdn.kuwo.cn/5a1fdd7e1178a867af57c6b0ba576889/69468dc3/resource/30106/trackmedia/F000000bYDlc2XxKLs.flac"
|
|
|
|
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) |