1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
| import wx
import os
import threading
import phub
class VideoDownloaderApp(wx.Frame):
def __init__(self, *args, **kwargs):
super(VideoDownloaderApp, self).__init__(*args, **kwargs)
self.SetTitle("Pornhub 视频下载器")
self.SetSize((400, 250))
self.SetBackgroundColour(wx.Colour(240, 240, 240))
self.url_label = wx.StaticText(self, label="视频 URL:")
self.url_text = wx.TextCtrl(self)
self.dir_label = wx.StaticText(self, label="下载目录:")
self.dir_text = wx.TextCtrl(self, style=wx.TE_READONLY)
self.select_dir_button = wx.Button(self, label="选择下载目录")
self.download_button = wx.Button(self, label="开始下载")
self.progress = wx.Gauge(self, range=100)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self._setup_layout()
self.Bind(wx.EVT_BUTTON, self.on_select_directory, self.select_dir_button)
self.Bind(wx.EVT_BUTTON, self.on_download, self.download_button)
# 记住上次选择的目录
self.last_dir = os.path.expanduser("~")
# For simplicity, you can adjust as needed
self.SetSizer(self.sizer)
def _setup_layout(self):
self.sizer.Add(self.url_label, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.url_text, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.dir_label, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.dir_text, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.select_dir_button, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.download_button, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.progress, 0, wx.ALL | wx.EXPAND, 5)
def on_select_directory(self, event):
with wx.DirDialog(self, "选择下载目录", self.last_dir, style=wx.DD_DEFAULT_STYLE) as dlg:
if dlg.ShowModal() == wx.ID_OK:
self.last_dir = dlg.GetPath()
self.dir_text.SetValue(self.last_dir)
def on_download(self, event):
url = self.url_text.GetValue().strip()
if not url:
wx.MessageBox("请输入有效的URL", "错误", wx.OK | wx.ICON_ERROR)
return
threading.Thread(target=self.start_download, args=(url,)).start()
def start_download(self, url):
self.progress.SetValue(0)
id = url.split("viewkey=")[-1] # 提取ID
downloader = phub.Client()
try:
video = downloader.get(url)
video.download(os.path.join(self.last_dir, f"{id}.mp4"))
for i in range(1, 101):
self.progress.SetValue(i) # 在实际下载中,应更新进度条此处仅为示例
wx.MilliSleep(50) # 模拟下载进度
wx.CallAfter(self.show_message, "下载完成!")
except Exception as e:
wx.CallAfter(self.show_message, "下载失败: " + str(e))
def show_message(self, message):
wx.MessageBox(message, "提示", wx.OK | wx.ICON_INFORMATION)
if __name__ == "__main__":
app = wx.App(False)
frame = VideoDownloaderApp(None)
frame.Show()
app.MainLoop()
|