From 76392863ad8746121fd869b826c7d805bfc4aab7 Mon Sep 17 00:00:00 2001 From: NFL_jiancx <1678594309@qq.com> Date: Sat, 20 Dec 2025 20:31:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(download):=20=E4=BF=AE=E5=A4=8D=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的total_ordering导入 - 添加全局headers变量声明 - 在requests.get中添加headers参数 - 更新应用版本号从4.3.4到4.3.5 - 添加HTTP请求头信息以改善兼容性 --- NFLmusic.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NFLmusic.py b/NFLmusic.py index ff3523a..97ed640 100644 --- a/NFLmusic.py +++ b/NFLmusic.py @@ -1,5 +1,4 @@ import time -from functools import total_ordering from tkinter import * import threading import pygame @@ -126,7 +125,7 @@ def download_check(*value): def download_music(song_name, choose): - global progressbar, downloading + global progressbar, downloading, headers def update_progressbar(): while True: @@ -228,7 +227,7 @@ def download_music(song_name, choose): lrc = "" lrc = lrc.replace("\\n", "\n") print("请求api:", url) - response = requests.get(music_url, stream=True) + response = requests.get(music_url, stream=True, headers=headers) print("下载直链:", music_url) formated = music_url.split("?")[0].rsplit(".", 1)[1] if formated not in ["m4a", "mp3", "ogg", "flac"]: @@ -1328,7 +1327,7 @@ def search_local_song(): time.sleep(1) -version = "4.3.4" +version = "4.3.5" poem = "" appdata = os.getenv("APPDATA") make_resource() @@ -1433,6 +1432,14 @@ playingmode_dict = { 1: "rand", 2: "sequ" } +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', +} if path == "./music": if os.path.exists("./music"):