mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
更新 TUI 界面
This commit is contained in:
30
main.py
30
main.py
@@ -7,6 +7,7 @@ from textual.widgets import Footer
|
|||||||
from textual.widgets import Header
|
from textual.widgets import Header
|
||||||
from textual.widgets import Input
|
from textual.widgets import Input
|
||||||
from textual.widgets import Label
|
from textual.widgets import Label
|
||||||
|
from textual.widgets import Log
|
||||||
from textual.widgets import Pretty
|
from textual.widgets import Pretty
|
||||||
|
|
||||||
from source import Batch
|
from source import Batch
|
||||||
@@ -14,9 +15,6 @@ from source import Settings
|
|||||||
from source import XHS
|
from source import XHS
|
||||||
|
|
||||||
|
|
||||||
# from textual.widgets import Log
|
|
||||||
|
|
||||||
|
|
||||||
def example():
|
def example():
|
||||||
"""通过代码设置参数,适合二次开发"""
|
"""通过代码设置参数,适合二次开发"""
|
||||||
# 测试链接
|
# 测试链接
|
||||||
@@ -67,37 +65,45 @@ class XHSDownloader(App):
|
|||||||
Binding(key="q", action="quit", description="退出程序"),
|
Binding(key="q", action="quit", description="退出程序"),
|
||||||
("d", "toggle_dark", "切换主题"),
|
("d", "toggle_dark", "切换主题"),
|
||||||
]
|
]
|
||||||
xhs = XHS(**Settings().run())
|
APP = XHS(**Settings().run())
|
||||||
|
Batch = Batch()
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Header()
|
||||||
yield Label("请输入小红书图文/视频作品链接:")
|
yield Label("请输入小红书图文/视频作品链接:")
|
||||||
yield Input(id="url", placeholder="URL")
|
yield Input(placeholder="URL")
|
||||||
yield HorizontalScroll(Button("下载无水印图片/视频", id="solo", variant="success"),
|
yield HorizontalScroll(Button("下载无水印图片/视频", id="solo", variant="success"),
|
||||||
Button("读取文件并开始批量下载作品", id="batch", variant="success"),
|
Button("读取文件并开始批量下载作品", id="batch", variant="success"),
|
||||||
Button("清空输入", id="reset", variant="error"), )
|
Button("清空输入框", id="reset", variant="error"), )
|
||||||
# yield Log(auto_scroll=True)
|
yield Log(auto_scroll=True)
|
||||||
yield Pretty({"采集结果": "未采集到任何数据!"})
|
yield Pretty(
|
||||||
|
{"运行结果": "输入小红书图文/视频作品链接,点击“下载无水印图片/视频”按钮即可获取作品数据并下载作品文件!"})
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
self.title = "小红书作品采集工具"
|
self.title = "小红书作品采集工具"
|
||||||
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
if event.button.id in ("solo", "batch"):
|
if event.button.id == "solo":
|
||||||
self.solo()
|
self.solo()
|
||||||
elif event.button.id == "batch":
|
elif event.button.id == "batch":
|
||||||
self.batch()
|
self.batch()
|
||||||
elif event.button.id == "reset":
|
elif event.button.id == "reset":
|
||||||
self.query_one("#url").value = ""
|
self.query_one(Input).value = ""
|
||||||
|
|
||||||
def solo(self):
|
def solo(self):
|
||||||
result = self.xhs.extract(self.query_one("#url").value, download=True)
|
url = self.query_one(Input).value
|
||||||
|
result = self.APP.extract(url, download=True)
|
||||||
# self.query_one(Log).write_line()
|
# self.query_one(Log).write_line()
|
||||||
self.query_one(Pretty).update(result)
|
self.query_one(Pretty).update(result)
|
||||||
|
|
||||||
def batch(self):
|
def batch(self):
|
||||||
pass
|
urls = self.Batch.read_txt()
|
||||||
|
if not urls:
|
||||||
|
self.query_one(Log).write_line("未检测到 xhs.txt 文件 或者 该文件为空!")
|
||||||
|
for url in urls:
|
||||||
|
self.query_one(Log).write_line(f"当前作品链接: {url}")
|
||||||
|
self.APP.extract(url)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user