mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from json import dump
|
|
from json import load
|
|
from pathlib import Path
|
|
|
|
__all__ = ['Settings', 'Batch']
|
|
|
|
|
|
class Settings:
|
|
file = Path(__file__).resolve().parent.parent.joinpath("./settings.json")
|
|
default = {
|
|
"path": "",
|
|
"folder": "Download",
|
|
"cookie": "",
|
|
"proxies": None,
|
|
"timeout": 10,
|
|
"chunk": 256 * 1024,
|
|
}
|
|
|
|
def run(self):
|
|
return self.read() if self.file.is_file() else self.create()
|
|
|
|
def read(self) -> dict:
|
|
with self.file.open("r", encoding="utf-8") as f:
|
|
return load(f)
|
|
|
|
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")
|
|
|
|
def read_txt(self) -> list:
|
|
if self.file.is_file():
|
|
with self.file.open("r") as f:
|
|
return [i.rstrip('\n') for i in f.readlines()]
|
|
return []
|