From 723598bef8f726afdbb94dcfeb27fa010f26ab7a Mon Sep 17 00:00:00 2001 From: NFL_jiancx <1678594309@qq.com> Date: Thu, 1 May 2025 00:45:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(NFLmusic):=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E9=9F=B3=E4=B9=90=E5=B9=B3=E5=8F=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 QQ音乐、酷狗音乐、汽水音乐、小粉音乐平台支持 - 优化音乐搜索和播放功能,适配不同平台的 API - 增加歌词获取功能,支持多个平台的歌词格式 - 调整音乐列表显示,适应不同平台的数据结构 --- NFLmusic.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/NFLmusic.py b/NFLmusic.py index c89939f..59a7aae 100644 --- a/NFLmusic.py +++ b/NFLmusic.py @@ -163,9 +163,9 @@ def download_music(song_name, choose): singer = resp.json()["song_singer"] music_url = resp.json()["flac_url"] elif choice == "WANGYIYUN": - resp = requests.get(f"{url}/?name={song_name}&n={choose}&br={br}&limit=60") + resp = requests.get(f"{url}?gm={song_name}&n={choose}&br={br}&num=60&type=json") resp.close() - id = resp.json()["data"]["id"] + id = resp.json()["link"].rsplit("=", 1)[1] try: resp_lrc = requests.get(f"https://music.163.com/api/song/lyric?id={id}&lv=-1&kv=-1&tv=-1") resp_lrc.close() @@ -173,13 +173,61 @@ def download_music(song_name, choose): except Exception as e: print(f"download_wyy_lrc: {e}") lrc = "" - music_name = resp.json()["data"]["name"] - singer = resp.json()["data"]["singers"][0]["name"] + music_name = resp.json()["title"] + singer = resp.json()["singer"] + music_url = resp.json()["music_url"] + elif choice == "QQ": + resp = requests.get(f"{url}?msg={song_name}&n={choose}&num=60&type=json") + resp.close() + try: + lrc = resp.json()["data"]["lyric"] + except Exception as e: + print(f"download_qq_lrc: {e}") + lrc = "" + music_name = resp.json()["data"]["title"] + singer = resp.json()["data"]["singer"] + music_url = resp.json()["data"]["music_url"] + elif choice == "KUGOU": + resp = requests.get(f"{url}?gm={song_name}&n={choose}&num=60&type=json") + resp.close() + try: + lrc = resp.json()["lyrics"] + except Exception as e: + print(f"download_kugou_lrc: {e}") + lrc = "" + music_name = resp.json()["title"] + singer = resp.json()["singer"] + music_url = resp.json()["music_url"] + elif choice == "DOUYIN": + resp = requests.get(f"{url}?msg={song_name}&n={choose}&num=50&type=json") + resp.close() + try: + lrc = resp.json()["data"]["lrc"] + except Exception as e: + print(f"download_qishui_lrc: {e}") + lrc = "" + music_name = resp.json()["data"]["title"] + singer = resp.json()["data"]["singer"] music_url = resp.json()["data"]["url"] + elif choice == "XIAOFEN": + resp = requests.get(f"{url}?msg={song_name}&n={choose}&num=60&type=json") + resp.close() + try: + lrc = resp.json()["lrc"] + except Exception as e: + print(f"download_xiaofen_lrc: {e}") + lrc = "" + music_name = resp.json()["title"] + singer = resp.json()["singer"] + music_url = resp.json()["music_url"] else: lrc = "" + print("请求api:", url) response = requests.get(music_url, stream=True) + print("下载直链:", music_url) formated = music_url.split("?")[0].rsplit(".", 1)[1] + if formated not in ["m4a", "mp3", "ogg", "flac"]: + formated = "mp3" filename_without_endswith = f"{singer} - {music_name}" filename = f"{filename_without_endswith}.{formated}" filename = filename.replace("\\", "#").replace("/", "#") @@ -278,8 +326,16 @@ def get_data_without_blocking(song_name): songlist.delete(*songlist.get_children()) if choice == "KUWO": url1 = f"{url}?msg={song_name}&num=60&type=json" - else: - url1 = f"{url}/?name={song_name}&limit=60" + elif choice == "WANGYIYUN": + url1 = f"{url}?gm={song_name}&num=60&type=json" + elif choice == "QQ": + url1 = f"{url}?msg={song_name}&num=60&type=json" + elif choice == "KUGOU": + url1 = f"{url}?gm={song_name}&num=60&type=json" + elif choice == "DOUYIN": + url1 = f"{url}?msg={song_name}&num=50&type=json" + elif choice == "XIAOFEN": + url1 = f"{url}?msg={song_name}&num=60&type=json" resp = requests.get(url1) jsondata = resp.json()["data"] resp.close() @@ -290,8 +346,24 @@ def get_data_without_blocking(song_name): artist = jsondata[index]["singer"] album = jsondata[index]["song_rid"] elif choice == "WANGYIYUN": - full_name = jsondata[index]["name"] - artist = jsondata[index]["singers"][0]["name"] + full_name = jsondata[index]["title"] + artist = jsondata[index]["singer"] + album = jsondata[index]["songid"] + elif choice == "QQ": + full_name = jsondata[index]["title"] + artist = jsondata[index]["singer"] + album = "" + elif choice == "KUGOU": + full_name = jsondata[index]["title"] + artist = jsondata[index]["singer"] + album = "" + elif choice == "DOUYIN": + full_name = jsondata[index]["title"] + artist = jsondata[index]["singer"] + album = "" + elif choice == "XIAOFEN": + full_name = jsondata[index]["title"] + artist = jsondata[index]["singer"] album = "" songlist.insert("", "end", values=(full_name, artist, album)) except requests.exceptions.JSONDecodeError: @@ -1596,7 +1668,11 @@ themeLabel.place(x=10, y=25) # 基本设置 repo_dict = { "酷我音乐": "KUWO", - "网易云音乐": "WANGYIYUN" + "网易云音乐": "WANGYIYUN", + "QQ音乐": "QQ", + "酷狗音乐": "KUGOU", + "汽水音乐": "DOUYIN", + "小粉音乐": "XIAOFEN" } repo_dict_reverse = {} for repo in repo_dict: