Skip to content

Commit

Permalink
修复文件路径问题 & 下载状态异常发出警告
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperScript-PRC committed Feb 14, 2024
1 parent 3c406c2 commit 564371a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 7 additions & 7 deletions plugin_market/SuperSoundMixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __mixer__(
self.SuperSoundMixer_threadings_num += 1
self.SuperSoundMixer_ThreadMusic.append(sound_name)
with open(
"插件配置文件\\SuperSoundMixer\\SoundCmds\\%s.txt" % sound_name,
"插件配置文件/SuperSoundMixer/SoundCmds/%s.txt" % sound_name,
"r",
encoding="utf-8",
) as music_txt:
Expand Down Expand Up @@ -130,9 +130,9 @@ def __mixer__(


def updateMidifile():
for i in os.listdir("插件配置文件\\SuperSoundMixer"):
for i in os.listdir("插件配置文件/SuperSoundMixer"):
if i.endswith(".mid"):
midi_input = "插件配置文件\\SuperSoundMixer\\" + i
midi_input = "插件配置文件/SuperSoundMixer/" + i
canvas = Canvas()
p = canvas
artist = MidiDo(canvas=canvas, y=p.y + 10)
Expand All @@ -143,7 +143,7 @@ def updateMidifile():
),
)
with open(
"插件配置文件\\SuperSoundMixer\\SoundCmds\\%s.txt"
"插件配置文件/SuperSoundMixer/SoundCmds/%s.txt"
% i.replace(".mid", ""),
"w",
encoding="utf-8",
Expand All @@ -153,7 +153,7 @@ def updateMidifile():
"""({}, "{}", {}, {})""".format(tip, _ins, note, vol) + "\n"
)
musicfile.close()
os.remove("插件配置文件\\SuperSoundMixer\\" + i)
os.remove("插件配置文件/SuperSoundMixer/" + i)


updateMidifile()
Expand Down Expand Up @@ -184,7 +184,7 @@ async def _(playername, msg):
del exception
try:
if os.path.exists(
"插件配置文件\\SuperSoundMixer\\SoundCmds\\%s.txt"
"插件配置文件/SuperSoundMixer/SoundCmds/%s.txt"
% get_sound_data["name"]
):
try:
Expand All @@ -210,7 +210,7 @@ async def _(playername, msg):
# 音乐文件名(无mid后缀) 播放的对象 乐器 忽略高音 速度
else:
if os.path.exists(
"插件配置文件\\SuperSoundMixer\\%s.mid" % get_sound_data[2]
"插件配置文件/SuperSoundMixer/%s.mid" % get_sound_data[2]
):
updateMidifile()
tellrawText("@a", "§cSuperSoundMixer§f>> §6文件正在初始化")
Expand Down
9 changes: 6 additions & 3 deletions tooldelta/urlmethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def download_file(f_url: str, f_dir: str, ignore_warnings=False):
if filesize < 256 and "404" in res.text:
raise requests.RequestException("下载失败: 返回 404")
elif filesize < 256 and not ignore_warnings:
Print.print_war(f"下载 {f_url} 的文件警告: 文件大小异常, 不到 0.256KB")
Print.print_war(f"下载 {f_url} 的文件警告: 文件大小异常, 不到 0.25KB")

nowsize = 0
succ = False
lastime = time.time()
useSpeed = 0

with open(f_dir + ".tmp", "wb") as dwnf:
for chk in res.iter_content(chunk_size=8192):
for chk in res.iter_content(chunk_size = 8192):
nowtime = time.time()

if nowtime != lastime:
Expand All @@ -44,12 +44,15 @@ def download_file(f_url: str, f_dir: str, ignore_warnings=False):
"§f" + " " * _tmp + "§b" + " " * (20 - _tmp) + "§r ", 7
)
Print.print_with_info(
f"{bar} {round(nowsize / 1024, 2)}KB / {round(filesize / 1024, 2)}KB ({_pretty_kb(useSpeed)}B/s) ",
f"{bar} {_pretty_kb(nowsize)}B / {_pretty_kb(filesize)}B ({_pretty_kb(useSpeed)}B/s) ",
"§a 下载 §r",
end="\r",
need_log=False,
)

if nowsize / filesize > 1:
Print.print_war(f"下载: 实际大小已超出文件大小 {round(nowsize / filesize, 2)} 倍")

succ = True

if succ:
Expand Down

0 comments on commit 564371a

Please sign in to comment.