-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
114 lines (101 loc) · 3.38 KB
/
settings.py
File metadata and controls
114 lines (101 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from pathlib import Path
import json
import os
from typing import Optional
def _get_settings_path() -> Path:
appdata = os.environ.get("APPDATA")
if appdata:
settings_dir = Path(appdata) / "AniChapters"
else:
settings_dir = Path.home() / ".anichapters"
settings_dir.mkdir(parents=True, exist_ok=True)
return settings_dir / "settings.json"
_SETTINGS_PATH = _get_settings_path()
# ── Presets ───────────────────────────────────────────────────────────────────
PRESETS: dict[str, dict[str, str]] = {
"Default": {
"cold_open": "Cold Open",
"opening": "Opening",
"episode": "Episode",
"ending": "Ending",
"after_credits":"After Credits",
"end": "End",
},
"Anime Style": {
"cold_open": "Prologue",
"opening": "♪ OP",
"episode": "Episode",
"ending": "♪ ED",
"after_credits":"Epilogue",
"end": "End",
},
"Minimal": {
"cold_open": "Intro",
"opening": "OP",
"episode": "EP",
"ending": "ED",
"after_credits":"Post",
"end": "End",
},
"Descriptive": {
"cold_open": "Pre-Opening",
"opening": "Opening Theme",
"episode": "Main Episode",
"ending": "Ending Theme",
"after_credits":"Post-Credits",
"end": "End",
},
"Japanese": {
"cold_open": "前口上",
"opening": "オープニング",
"episode": "本編",
"ending": "エンディング",
"after_credits":"エピローグ",
"end": "エンド",
},
"Custom": { # placeholder — user fills this
"cold_open": "Cold Open",
"opening": "Opening",
"episode": "Episode",
"ending": "Ending",
"after_credits":"After Credits",
"end": "End",
},
}
_DEFAULT_SETTINGS = {
"preset": "Default",
"custom_names": dict(PRESETS["Default"]),
"ui_state": {
"inplace": False,
},
}
def load_settings() -> dict:
"""Load settings from settings.json, or return defaults."""
try:
with open(_SETTINGS_PATH, encoding="utf-8") as f:
data = json.load(f)
# Merge with defaults to handle missing keys
merged = dict(_DEFAULT_SETTINGS)
merged.update(data)
return merged
except Exception:
return dict(_DEFAULT_SETTINGS)
def save_settings(settings: dict) -> None:
"""Persist settings to settings.json."""
try:
with open(_SETTINGS_PATH, "w", encoding="utf-8") as f:
json.dump(settings, f, indent=4, ensure_ascii=False)
except Exception:
pass
def get_chapter_names(settings: Optional[dict] = None) -> dict[str, str]:
"""
Return the active chapter name mapping.
If preset is 'Custom', returns custom_names.
Otherwise returns the named preset.
"""
if settings is None:
settings = load_settings()
preset = settings.get("preset", "Default")
if preset == "Custom":
return settings.get("custom_names", dict(PRESETS["Default"]))
return dict(PRESETS.get(preset, PRESETS["Default"]))