import
tkinter as tk
from
tkinter
import
scrolledtext, messagebox
import
requests
import
re
import
os
import
tempfile
def
sort_links():
links_text
=
text_area.get(
"1.0"
, tk.END)
links
=
re.sub(r
'提取码[::]\s?[a-zA-Z0-9]{4}\s*'
, '', links_text)
cleaned_links
=
re.sub(r
'(http)'
, r
'\n\1'
, links).strip()
if
cleaned_links:
lines
=
cleaned_links.split(
'\n'
)
new_lines
=
[]
for
line
in
lines:
if
not
line.endswith(
','
):
line
=
line
+
','
new_lines.append(line)
cleaned_links
=
'\n'
.join(new_lines)
text_area.delete(
"1.0"
, tk.END)
text_area.insert(tk.END, cleaned_links)
def
check_link():
links_text
=
text_area.get(
"1.0"
, tk.END)
links
=
[link.strip().rstrip(
','
)
for
link
in
links_text.split(
'\n'
)
if
link.strip()]
invalid_links
=
[]
headers
=
{
"User-Agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
for
index, link
in
enumerate
(links, start
=
1
):
status_label.config(text
=
f
"正在检测第 {index} 条链接: {link}"
)
root.update()
try
:
if
"pan.baidu.com"
in
link:
response
=
requests.get(link, headers
=
headers, allow_redirects
=
True
, timeout
=
10
)
if
response.status_code !
=
200
or
"链接不存在"
in
response.text:
invalid_links.append(link)
elif
"pan.quark.cn"
in
link:
response
=
requests.get(link, headers
=
headers, allow_redirects
=
True
, timeout
=
10
)
if
response.status_code !
=
200
or
"分享已取消"
in
response.text:
invalid_links.append(link)
else
:
invalid_links.append(link)
except
requests.RequestException:
invalid_links.append(link)
status_label.config(text
=
"检测完成"
)
if
invalid_links:
invalid_links_str
=
'\n'
.join(invalid_links)
temp_file
=
tempfile.NamedTemporaryFile(mode
=
'w'
, delete
=
False
, suffix
=
'.txt'
)
temp_file.write(invalid_links_str)
temp_file.close()
os.system(f
'notepad.exe {temp_file.name}'
)
else
:
messagebox.showinfo(
"检测结果"
,
"所有链接均有效!"
)
root
=
tk.Tk()
root.title(
"网盘链接检测工具"
)
text_area
=
scrolledtext.ScrolledText(root, width
=
50
, height
=
10
)
text_area.pack(pady
=
20
)
sort_button
=
tk.Button(root, text
=
"排序链接"
, command
=
sort_links)
sort_button.pack(pady
=
10
)
check_button
=
tk.Button(root, text
=
"检测链接"
, command
=
check_link)
check_button.pack(pady
=
10
)
status_label
=
tk.Label(root, text
=
"", anchor
=
tk.W)
status_label.pack(pady
=
10
, fill
=
tk.X)
root.mainloop()