From ede9a1fd356e2fb7e3ca16a93aef0c5179b32ba7 Mon Sep 17 00:00:00 2001 From: holwell <45387795+holwell@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E5=B7=B2=E4=B8=8A=E4=BC=A0=E6=AD=8C=E6=9B=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上传音乐前,检测是否已上传 --- main.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 74de983..2d4c7ed 100644 --- a/main.py +++ b/main.py @@ -66,6 +66,21 @@ def get_song_details(song_ids): print("响应内容无法解析为JSON:", response.text) return [] +# 判断歌曲是否已上传云盘 +def has_uploaded(song_id, cookie): + url = f"http://localhost:3000/user/cloud/detail?id={song_id}&cookie={cookie}" + response = requests.get(url) + try: + response_data = response.json() + if response_data.get('code') == 200 and len(response_data['data']) != 0: + return True + else: + print("获取云盘歌曲详情失败:", response_data.get("message")) + return False + except json.JSONDecodeError: + print("获取云盘歌曲信息失败,响应内容无法解析为JSON:", response.text) + return False + # 执行 import 请求 def import_song(song_info, cookie): song_id = song_info['id'] @@ -100,7 +115,12 @@ def process_songs(song_info_list, cookie): for song_info in song_info_list: song_id = song_info['id'] print(f"正在导入歌曲ID: {song_id}") - + + # 已上传则跳过 + if has_uploaded(song_id, cookie): + print('该歌曲已上传,跳过!') + continue + # 查询歌曲的详细信息 song_details = get_song_details([song_id]) if song_details: