Skip to content

Comments

点歌台 添加网络源搜索支持#165

Open
Zhonger-Yuansi wants to merge 3 commits intoToolDelta-Basic:mainfrom
Zhonger-Yuansi:main
Open

点歌台 添加网络源搜索支持#165
Zhonger-Yuansi wants to merge 3 commits intoToolDelta-Basic:mainfrom
Zhonger-Yuansi:main

Conversation

@Zhonger-Yuansi
Copy link
Contributor

No description provided.

@deepsource-io
Copy link
Contributor

deepsource-io bot commented Feb 17, 2026

DeepSource Code Review

DeepSource reviewed changes in the commit range d3d3f3e..2234b82 on this pull request. Below is the summary for the review, and you can see the individual issues we found as review comments.

For detailed review results, please see the PR on DeepSource ↗

PR Report Card

Security × 3 issues Overall PR Quality   

Focus Area: Hygiene

Guidance
Remove unnecessary "else" and "elif" after "return" in 点歌台/__init__.py.
Reliability × 0 issues
Complexity × 3 issues
Hygiene × 106 issues

Code Review Summary

Analyzer Status Summary Details
Python 114 new issues detected. 38 existing issues fixed. Review ↗
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 #为了成功率 拼了。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'count': 20 #为了成功率 拼了。
'count': 20,

Comment on lines +94 to 95
if result_container.get('success'):
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可能存在竞态问题。
这意味着如果协程 A 在完成这里的 if 检查后,如果刚好又有另外一个协程 B 设置了 success 为真,那么此时就会出现 A 仍然在继续进行请求,但实际上 success 已经为真的情况。

# 构建搜索 URL
search_url = f"https://www.midishow.com/search/result?q={music_name}"

# 6666 老实了 IP 被封了 让我使用代理
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 6666 老实了 IP 被封了 让我使用代理

Comment on lines +161 to +167
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好改用 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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好通过某种方式告知用户一件事:你的插件使用了来自于这个网站的 midi

Comment on lines +281 to +282
api_url = "https://midi.fxdby.net/api/download_midi"
payload = {'url': selected_link}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来这个 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)

Comment on lines +318 to +319
with open(midi_file_path, 'wb') as f:
f.write(base64.b64decode(midi_file))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

插件不应该使用 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

欲执行的命令无需以斜杠开头。
另外,getSelector 已经弃用,请改用建议的实现。

def getSelector(self):
    """
    Deprecated: 请改为使用 `safe_name` 属性。

    获取包含玩家名的选择器
    等价于 `@a[name="{player.name}"]`
    Returns:
        str: 选择器
    """
    return f'@a[name="{self.name}"]'

@Happy2018new
Copy link
Member

另外你的插件没有通过 pip 插件安装 bs4 库,这将导致用户运行该插件时产生报错(找不到模块 bs4)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants