mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
新增配置文件
This commit is contained in:
parent
dd3a8d373d
commit
c9aa2d3d1a
5
main.py
5
main.py
@ -1,8 +1,9 @@
|
||||
from source import Settings
|
||||
from source import XHS
|
||||
|
||||
|
||||
def example():
|
||||
"""使用示例"""
|
||||
"""代码示例"""
|
||||
# 测试链接
|
||||
error_demo = "https://www.xiaohongshu.com/explore/"
|
||||
image_demo = "https://www.xiaohongshu.com/explore/64d1b406000000000103ee8d"
|
||||
@ -29,7 +30,7 @@ def example():
|
||||
|
||||
|
||||
def main():
|
||||
xhs = XHS()
|
||||
xhs = XHS(**Settings().run()) # 配置文件生效
|
||||
while True:
|
||||
if url := input("请输入小红书作品链接:"):
|
||||
xhs.extract(url, download=True)
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from json import dump
|
||||
from json import load
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@ -6,8 +8,19 @@ class Settings:
|
||||
default = {
|
||||
"path": "./",
|
||||
"folder": "Download",
|
||||
"user-agent": None,
|
||||
"proxies": None,
|
||||
"timeout": 10,
|
||||
"chunk": 256 * 1024,
|
||||
}
|
||||
|
||||
def run(self):
|
||||
return self.read() if self.path.is_file() else self.create()
|
||||
|
||||
def read(self):
|
||||
with self.path.open("r", encoding="utf-8") as f:
|
||||
return load(f)
|
||||
|
||||
def create(self):
|
||||
with self.path.open("w", encoding="utf-8") as f:
|
||||
dump(self.default, f, indent=2)
|
||||
return self.default
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user