From b9dd05652df71e1ec3cd79e4c390c3aae1e6827b Mon Sep 17 00:00:00 2001 From: JoeamAmier Date: Thu, 23 Nov 2023 23:09:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=BB=E5=8F=96=E5=89=AA?= =?UTF-8?q?=E8=B4=B4=E6=9D=BF=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Settings.py | 10 +++++++--- source/__init__.py | 9 +++++++-- static/XHS-Downloader.tcss | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/Settings.py b/source/Settings.py index 89a520f..0576559 100644 --- a/source/Settings.py +++ b/source/Settings.py @@ -19,18 +19,22 @@ class Settings: def run(self): return self.read() if self.file.is_file() else self.create() - def read(self): + def read(self) -> dict: with self.file.open("r", encoding="utf-8") as f: return load(f) - def create(self): + def create(self) -> dict: with self.file.open("w", encoding="utf-8") as f: dump(self.default, f, indent=2) return self.default + def update(self, data: dict): + with self.file.open("w", encoding="utf-8") as f: + dump(data, f, indent=2, ensure_ascii=False) + class Batch: - file = Path("./xhs.txt") + file = Path("../xhs.txt") def read_txt(self) -> list: if self.file.is_file(): diff --git a/source/__init__.py b/source/__init__.py index 2ec1098..64206fb 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -1,6 +1,7 @@ from pathlib import Path from re import compile +from pyperclip import paste from textual.app import App from textual.app import ComposeResult from textual.binding import Binding @@ -102,9 +103,10 @@ class XHS: class XHSDownloader(App): - VERSION = 1.5 + VERSION = 1.6 Beta = True - CSS_PATH = "static/XHS-Downloader.tcss" + CSS_PATH = Path(__file__).resolve().parent.parent.joinpath( + "static/XHS-Downloader.tcss") BINDINGS = [ Binding(key="q", action="quit", description="退出程序"), ("d", "toggle_dark", "切换主题"), @@ -118,6 +120,7 @@ class XHSDownloader(App): Input(placeholder="URL"), HorizontalScroll(Button("下载无水印图片/视频", id="solo"), Button("读取 xhs.txt 文件并批量下载作品", id="batch"), + Button("读取剪贴板", id="paste"), Button("清空输入框", id="reset"), )) yield Log(auto_scroll=True) yield Footer() @@ -132,6 +135,8 @@ class XHSDownloader(App): self.batch() elif event.button.id == "reset": self.query_one(Input).value = "" + elif event.button.id == "paste": + self.query_one(Input).value = paste() def solo(self): url = self.query_one(Input).value diff --git a/static/XHS-Downloader.tcss b/static/XHS-Downloader.tcss index 7c23680..e8ac86e 100644 --- a/static/XHS-Downloader.tcss +++ b/static/XHS-Downloader.tcss @@ -16,6 +16,9 @@ Button#solo { Button#batch { tint: green 35%; } +Button#paste { + tint: green 35%; +} Button#reset { tint: red 35%; }