mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
feat: 支持以发布时间作为文件修改时间
1. 新增 write_mtime 配置参数 2. 更新项目英语翻译
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from pathlib import Path
|
||||
from re import compile, sub
|
||||
from shutil import move, rmtree
|
||||
|
||||
from os import utime
|
||||
from httpx import (
|
||||
AsyncClient,
|
||||
AsyncHTTPTransport,
|
||||
@@ -65,6 +65,7 @@ class Manager:
|
||||
download_record: bool,
|
||||
folder_mode: bool,
|
||||
author_archive: bool,
|
||||
write_mtime: bool,
|
||||
_print: bool,
|
||||
):
|
||||
self.root = root
|
||||
@@ -117,6 +118,7 @@ class Manager:
|
||||
self.video_download = self.check_bool(video_download, True)
|
||||
self.live_download = self.check_bool(live_download, True)
|
||||
self.author_archive = self.check_bool(author_archive, False)
|
||||
self.write_mtime = self.check_bool(write_mtime, False)
|
||||
|
||||
def __check_path(self, path: str) -> Path:
|
||||
if not path:
|
||||
@@ -164,9 +166,21 @@ class Manager:
|
||||
def archive(root: Path, name: str, folder_mode: bool) -> Path:
|
||||
return root.joinpath(name) if folder_mode else root
|
||||
|
||||
@staticmethod
|
||||
def move(temp: Path, path: Path):
|
||||
@classmethod
|
||||
def move(
|
||||
cls,
|
||||
temp: Path,
|
||||
path: Path,
|
||||
mtime: int = None,
|
||||
rewrite: bool = False,
|
||||
):
|
||||
move(temp.resolve(), path.resolve())
|
||||
if rewrite and mtime:
|
||||
cls.update_mtime(path.resolve(), mtime)
|
||||
|
||||
@staticmethod
|
||||
def update_mtime(file: Path, mtime: int):
|
||||
utime(file, (mtime, mtime))
|
||||
|
||||
def __clean(self):
|
||||
rmtree(self.temp.resolve())
|
||||
|
||||
@@ -27,6 +27,7 @@ class Settings:
|
||||
"folder_mode": False,
|
||||
"download_record": True,
|
||||
"author_archive": False,
|
||||
"write_mtime": False,
|
||||
"language": "zh_CN",
|
||||
}
|
||||
encode = "UTF-8-SIG" if system() == "Windows" else "UTF-8"
|
||||
|
||||
@@ -2,7 +2,7 @@ from pathlib import Path
|
||||
|
||||
VERSION_MAJOR = 2
|
||||
VERSION_MINOR = 5
|
||||
VERSION_BETA = True
|
||||
VERSION_BETA = False
|
||||
__VERSION__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{'beta' if VERSION_BETA else 'stable'}"
|
||||
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
PROJECT = f"XHS-Downloader V{VERSION_MAJOR}.{VERSION_MINOR} {
|
||||
|
||||
Reference in New Issue
Block a user