mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-06 20:42:52 +08:00
- 新增快手下载器,支持快手视频下载 - 添加下载配置页面,可设置各平台Cookies - 优化后端接口,增加获取和更新Cookies的功能 - 前端新增Downloader组件和相关表单组件 - 更新路由配置,增加下载配置相关路由
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import json
|
|
from pathlib import Path
|
|
from typing import Optional, Dict
|
|
|
|
|
|
class CookieConfigManager:
|
|
def __init__(self, filepath: str = "config/downloader.json"):
|
|
self.path = Path(filepath)
|
|
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
if not self.path.exists():
|
|
self._write({})
|
|
|
|
def _read(self) -> Dict[str, Dict[str, str]]:
|
|
try:
|
|
with self.path.open("r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
except Exception:
|
|
return {}
|
|
|
|
def _write(self, data: Dict[str, Dict[str, str]]):
|
|
with self.path.open("w", encoding="utf-8") as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
|
|
def get(self, platform: str) -> Optional[str]:
|
|
data = self._read()
|
|
return data.get(platform, {}).get("cookie")
|
|
|
|
def set(self, platform: str, cookie: str):
|
|
data = self._read()
|
|
data[platform] = {"cookie": cookie}
|
|
self._write(data)
|
|
|
|
def delete(self, platform: str):
|
|
data = self._read()
|
|
if platform in data:
|
|
del data[platform]
|
|
self._write(data)
|
|
|
|
def list_all(self) -> Dict[str, str]:
|
|
data = self._read()
|
|
return {k: v.get("cookie", "") for k, v in data.items()}
|
|
|
|
def exists(self, platform: str) -> bool:
|
|
return self.get(platform) is not None |