Conversation
DeepSource reviewed changes in the commit range For detailed review results, please see the PR on DeepSource ↗ PR Report CardCode Review Summary
How are these analyzer statuses calculated?Administrators can configure which issue categories are reported and cause analysis to be marked as failed when detected. This helps prevent bad and insecure code from being introduced in the codebase. If you're an administrator, you can modify this in the repository's settings. |
| proxy_url = "https://proxy.scdn.io/api/get_proxy.php" | ||
| proxy_params = { | ||
| 'protocol': 'https', | ||
| 'count': 20 #为了成功率 拼了。 |
There was a problem hiding this comment.
| 'count': 20 #为了成功率 拼了。 | |
| 'count': 20, |
| if result_container.get('success'): | ||
| return |
There was a problem hiding this comment.
这里可能存在竞态问题。
这意味着如果协程 A 在完成这里的 if 检查后,如果刚好又有另外一个协程 B 设置了 success 为真,那么此时就会出现 A 仍然在继续进行请求,但实际上 success 已经为真的情况。
| # 构建搜索 URL | ||
| search_url = f"https://www.midishow.com/search/result?q={music_name}" | ||
|
|
||
| # 6666 老实了 IP 被封了 让我使用代理 |
There was a problem hiding this comment.
| # 6666 老实了 IP 被封了 让我使用代理 |
| try: | ||
| loop = asyncio.get_event_loop() | ||
| except RuntimeError: | ||
| # 在非主线程中创建新的事件循环 | ||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| result = loop.run_until_complete(DJTable.test_proxies_async(proxies_list, search_url, headers)) |
There was a problem hiding this comment.
最好改用 asyncio.run(DJTable.test_proxies_async(proxies_list, search_url, headers))。
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
|
|
||
| # 构建搜索 URL | ||
| search_url = f"https://www.midishow.com/search/result?q={music_name}" |
There was a problem hiding this comment.
最好通过某种方式告知用户一件事:你的插件使用了来自于这个网站的 midi。
| api_url = "https://midi.fxdby.net/api/download_midi" | ||
| payload = {'url': selected_link} |
There was a problem hiding this comment.
看起来这个 API 会报 502。
from bs4 import BeautifulSoup
import requests
def search_music(music_name):
"""搜索音乐并返回结果"""
search_url = f"https://www.midishow.com/search/result?q={music_name}"
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": "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Cache-Control": "max-age=0",
}
resp = requests.get(search_url, headers=headers, verify=False, timeout=5)
soup = BeautifulSoup(resp.text, "html.parser")
music_items = soup.find_all(
"a", class_="d-block border-bottom pb-5 mb-5 position-relative"
)
return music_items
def download_midi(item):
"""下载 MIDI 文件"""
try:
selected_link = item.get("href") if hasattr(item, "get") else None
api_url = "https://midi.fxdby.net/api/download_midi"
payload = {"url": selected_link}
# 下载时无需 header
api_response = requests.post(api_url, json=payload, verify=False, timeout=10)
api_response.raise_for_status()
# 解析响应
api_data = api_response.json()
return api_data
except Exception:
return None
item = search_music("舌尖上的中国")[0]
data = download_midi(item)
print(data)| with open(midi_file_path, 'wb') as f: | ||
| f.write(base64.b64decode(midi_file)) |
There was a problem hiding this comment.
插件不应该使用 with open 来读写文件。
插件应当使用已有实现来操作文件。
| self.musics_list.append((title, player)) | ||
| player.show("§e点歌§f>> §a点歌成功, 消耗1点音乐点") | ||
| self.game_ctrl.sendwocmd( | ||
| f"/scoreboard players remove {player.getSelector()} song_point 1" |
There was a problem hiding this comment.
欲执行的命令无需以斜杠开头。
另外,getSelector 已经弃用,请改用建议的实现。
def getSelector(self):
"""
Deprecated: 请改为使用 `safe_name` 属性。
获取包含玩家名的选择器
等价于 `@a[name="{player.name}"]`
Returns:
str: 选择器
"""
return f'@a[name="{self.name}"]'|
另外你的插件没有通过 |
No description provided.