smfetch 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smfetch-1.0.1/.gitignore +126 -0
- smfetch-1.0.1/Makefile +24 -0
- smfetch-1.0.1/PKG-INFO +50 -0
- smfetch-1.0.1/README.md +37 -0
- smfetch-1.0.1/pyproject.toml +37 -0
- smfetch-1.0.1/smfetch/__init__.py +0 -0
- smfetch-1.0.1/smfetch/app.py +260 -0
- smfetch-1.0.1/smfetch/config.py +115 -0
- smfetch-1.0.1/smfetch/jobs.py +105 -0
- smfetch-1.0.1/smfetch/smonline.py +191 -0
- smfetch-1.0.1/smfetch/static/index.html +1185 -0
- smfetch-1.0.1/smfetch/zenius.py +296 -0
- smfetch-1.0.1/uv.lock +922 -0
smfetch-1.0.1/.gitignore
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Unit test / coverage reports
|
|
35
|
+
htmlcov/
|
|
36
|
+
.tox/
|
|
37
|
+
.nox/
|
|
38
|
+
.coverage
|
|
39
|
+
.coverage.*
|
|
40
|
+
.cache
|
|
41
|
+
nosetests.xml
|
|
42
|
+
coverage.xml
|
|
43
|
+
*.cover
|
|
44
|
+
*.py,cover
|
|
45
|
+
.hypothesis/
|
|
46
|
+
.pytest_cache/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Virtual environments
|
|
50
|
+
venv/
|
|
51
|
+
ENV/
|
|
52
|
+
env/
|
|
53
|
+
.venv
|
|
54
|
+
env.bak/
|
|
55
|
+
venv.bak/
|
|
56
|
+
|
|
57
|
+
# IDEs and editors
|
|
58
|
+
.idea/
|
|
59
|
+
.vscode/
|
|
60
|
+
*.swp
|
|
61
|
+
*.swo
|
|
62
|
+
*~
|
|
63
|
+
.DS_Store
|
|
64
|
+
.project
|
|
65
|
+
.pydevproject
|
|
66
|
+
.settings/
|
|
67
|
+
*.sublime-project
|
|
68
|
+
*.sublime-workspace
|
|
69
|
+
|
|
70
|
+
# Jupyter Notebook
|
|
71
|
+
.ipynb_checkpoints
|
|
72
|
+
|
|
73
|
+
# pyenv
|
|
74
|
+
.python-version
|
|
75
|
+
|
|
76
|
+
# pipenv
|
|
77
|
+
Pipfile.lock
|
|
78
|
+
|
|
79
|
+
# poetry
|
|
80
|
+
poetry.lock
|
|
81
|
+
|
|
82
|
+
# pdm
|
|
83
|
+
.pdm.toml
|
|
84
|
+
|
|
85
|
+
# PEP 582
|
|
86
|
+
__pypackages__/
|
|
87
|
+
|
|
88
|
+
# Celery stuff
|
|
89
|
+
celerybeat-schedule
|
|
90
|
+
celerybeat.pid
|
|
91
|
+
|
|
92
|
+
# SageMath parsed files
|
|
93
|
+
*.sage.py
|
|
94
|
+
|
|
95
|
+
# Environments
|
|
96
|
+
.venv
|
|
97
|
+
env/
|
|
98
|
+
venv/
|
|
99
|
+
ENV/
|
|
100
|
+
env.bak/
|
|
101
|
+
venv.bak/
|
|
102
|
+
|
|
103
|
+
# Spyder project settings
|
|
104
|
+
.spyderproject
|
|
105
|
+
.spyproject
|
|
106
|
+
|
|
107
|
+
# Rope project settings
|
|
108
|
+
.ropeproject
|
|
109
|
+
|
|
110
|
+
# mkdocs documentation
|
|
111
|
+
/site
|
|
112
|
+
|
|
113
|
+
# mypy
|
|
114
|
+
.mypy_cache/
|
|
115
|
+
.dmypy.json
|
|
116
|
+
dmypy.json
|
|
117
|
+
|
|
118
|
+
# Pyre type checker
|
|
119
|
+
.pyre/
|
|
120
|
+
|
|
121
|
+
# Logs
|
|
122
|
+
*.log
|
|
123
|
+
|
|
124
|
+
# OS generated files
|
|
125
|
+
Thumbs.db
|
|
126
|
+
.DS_Store
|
smfetch-1.0.1/Makefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
UV ?= uv
|
|
2
|
+
PROJECT_DIR ?= .
|
|
3
|
+
|
|
4
|
+
.PHONY: run check format install clean
|
|
5
|
+
|
|
6
|
+
run:
|
|
7
|
+
$(UV) run smfetch
|
|
8
|
+
|
|
9
|
+
format:
|
|
10
|
+
$(UV) run ruff format $(PROJECT_DIR)
|
|
11
|
+
|
|
12
|
+
check:
|
|
13
|
+
$(UV) run ruff check --fix --select I,F,UP,B $(PROJECT_DIR)
|
|
14
|
+
$(UV) run ty check $(PROJECT_DIR)
|
|
15
|
+
|
|
16
|
+
install: clean format check
|
|
17
|
+
$(UV) sync
|
|
18
|
+
|
|
19
|
+
clean:
|
|
20
|
+
find $(PROJECT_DIR) -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
21
|
+
find $(PROJECT_DIR) -type f -name "*.py[co]" -delete 2>/dev/null || true
|
|
22
|
+
rm -rf $(PROJECT_DIR)/.ruff_cache $(PROJECT_DIR)/.ty_cache $(PROJECT_DIR)/.mypy_cache $(PROJECT_DIR)/.pyright $(PROJECT_DIR)/.eggs 2>/dev/null || true
|
|
23
|
+
rm -rf $(PROJECT_DIR)/dist $(PROJECT_DIR)/build $(PROJECT_DIR)/*.egg-info 2>/dev/null || true
|
|
24
|
+
rm -rf $(PROJECT_DIR)/.pytest_cache $(PROJECT_DIR)/.coverage* $(PROJECT_DIR)/htmlcov 2>/dev/null || true
|
smfetch-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smfetch
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Web interface for downloading simfiles from Zenius and StepManiaOnline
|
|
5
|
+
Author-email: Raeed Ahmed <code@raeed.me>
|
|
6
|
+
Requires-Python: <4,>=3.10
|
|
7
|
+
Requires-Dist: beautifulsoup4<5,>=4.12.3
|
|
8
|
+
Requires-Dist: fastapi>=0.115.0
|
|
9
|
+
Requires-Dist: loguru<0.8,>=0.7.2
|
|
10
|
+
Requires-Dist: requests<3,>=2.31.0
|
|
11
|
+
Requires-Dist: uvicorn[standard]>=0.30.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# smfetch
|
|
15
|
+
|
|
16
|
+
Web interface for downloading simfiles from [Zenius-i-Vanisher](https://zenius-i-vanisher.com) and [StepManiaOnline](https://stepmaniaonline.net).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
usage: smfetch [-h] [-p PORT]
|
|
22
|
+
|
|
23
|
+
smfetch web interface
|
|
24
|
+
|
|
25
|
+
options:
|
|
26
|
+
-h, --help show this help message and exit
|
|
27
|
+
-p, --port PORT port for the web interface (default: 8095)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Starts a web interface at `http://localhost:<port>`.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
### Zenius-i-Vanisher
|
|
35
|
+
- **Song search** — search by song name and/or artist, select and download individual charts
|
|
36
|
+
- **Pack search** — filter official or user packs, download selected packs
|
|
37
|
+
- **Download bundles** — one-click download of arcade, spinoff, or all official packs
|
|
38
|
+
|
|
39
|
+
### StepManiaOnline
|
|
40
|
+
- **Title search** — search packs that contain chart with song title
|
|
41
|
+
- **Artist search** — search packs that contain chart with song artist
|
|
42
|
+
- **Pack search** — filter packs by pack name
|
|
43
|
+
|
|
44
|
+
## Storage Defaults
|
|
45
|
+
|
|
46
|
+
| | Config | Songs | Logs |
|
|
47
|
+
|---|---|---|---|
|
|
48
|
+
| **Linux** | `~/.config/smfetch/` | `~/.local/share/smfetch/` | `~/.local/state/smfetch/logs/` |
|
|
49
|
+
| **macOS** | `~/Library/Application Support/smfetch/` | `~/Music/StepMania Songs/` | `~/Library/Logs/smfetch/` |
|
|
50
|
+
| **Windows** | `%APPDATA%/smfetch/` | `~/Music/StepMania Songs/` | `%LOCALAPPDATA%/smfetch/logs/` |
|
smfetch-1.0.1/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# smfetch
|
|
2
|
+
|
|
3
|
+
Web interface for downloading simfiles from [Zenius-i-Vanisher](https://zenius-i-vanisher.com) and [StepManiaOnline](https://stepmaniaonline.net).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
usage: smfetch [-h] [-p PORT]
|
|
9
|
+
|
|
10
|
+
smfetch web interface
|
|
11
|
+
|
|
12
|
+
options:
|
|
13
|
+
-h, --help show this help message and exit
|
|
14
|
+
-p, --port PORT port for the web interface (default: 8095)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Starts a web interface at `http://localhost:<port>`.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
### Zenius-i-Vanisher
|
|
22
|
+
- **Song search** — search by song name and/or artist, select and download individual charts
|
|
23
|
+
- **Pack search** — filter official or user packs, download selected packs
|
|
24
|
+
- **Download bundles** — one-click download of arcade, spinoff, or all official packs
|
|
25
|
+
|
|
26
|
+
### StepManiaOnline
|
|
27
|
+
- **Title search** — search packs that contain chart with song title
|
|
28
|
+
- **Artist search** — search packs that contain chart with song artist
|
|
29
|
+
- **Pack search** — filter packs by pack name
|
|
30
|
+
|
|
31
|
+
## Storage Defaults
|
|
32
|
+
|
|
33
|
+
| | Config | Songs | Logs |
|
|
34
|
+
|---|---|---|---|
|
|
35
|
+
| **Linux** | `~/.config/smfetch/` | `~/.local/share/smfetch/` | `~/.local/state/smfetch/logs/` |
|
|
36
|
+
| **macOS** | `~/Library/Application Support/smfetch/` | `~/Music/StepMania Songs/` | `~/Library/Logs/smfetch/` |
|
|
37
|
+
| **Windows** | `%APPDATA%/smfetch/` | `~/Music/StepMania Songs/` | `%LOCALAPPDATA%/smfetch/logs/` |
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "smfetch"
|
|
3
|
+
version = "1.0.1"
|
|
4
|
+
description = "Web interface for downloading simfiles from Zenius and StepManiaOnline"
|
|
5
|
+
authors = [{ name = "Raeed Ahmed", email = "code@raeed.me" }]
|
|
6
|
+
requires-python = ">=3.10,<4"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"beautifulsoup4>=4.12.3,<5",
|
|
10
|
+
"requests>=2.31.0,<3",
|
|
11
|
+
"loguru>=0.7.2,<0.8",
|
|
12
|
+
"fastapi>=0.115.0",
|
|
13
|
+
"uvicorn[standard]>=0.30.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
smfetch = "smfetch.app:main"
|
|
18
|
+
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
dev = [
|
|
21
|
+
"ruff>=0.9.0",
|
|
22
|
+
"types-requests>=2.32.0.20240622,<3",
|
|
23
|
+
"types-beautifulsoup4>=4.12.0.20240511,<5",
|
|
24
|
+
"ty>=0.0.19",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[tool.mypy]
|
|
32
|
+
strict = true
|
|
33
|
+
warn_return_any = true
|
|
34
|
+
warn_unused_configs = true
|
|
35
|
+
|
|
36
|
+
[tool.ruff]
|
|
37
|
+
line-length = 100
|
|
File without changes
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"""FastAPI web application for smfetch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from collections.abc import AsyncIterator
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import uvicorn
|
|
12
|
+
from fastapi import FastAPI, Query
|
|
13
|
+
from fastapi.responses import FileResponse, HTMLResponse
|
|
14
|
+
from fastapi.staticfiles import StaticFiles
|
|
15
|
+
from loguru import logger
|
|
16
|
+
from pydantic import BaseModel
|
|
17
|
+
|
|
18
|
+
from smfetch import smonline as smo
|
|
19
|
+
from smfetch import zenius as zen
|
|
20
|
+
from smfetch.config import config
|
|
21
|
+
from smfetch.jobs import jobs
|
|
22
|
+
|
|
23
|
+
STATIC_DIR = Path(__file__).parent / "static"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# --- Pydantic request models ---
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ConfigUpdate(BaseModel):
|
|
30
|
+
songs_dir: str | None = None
|
|
31
|
+
log_dir: str | None = None
|
|
32
|
+
config_dir: str | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ZenSongDownload(BaseModel):
|
|
36
|
+
song_name: str
|
|
37
|
+
song_page: str
|
|
38
|
+
pack_name: str
|
|
39
|
+
pack_page: str
|
|
40
|
+
group: str = ""
|
|
41
|
+
sp: str = ""
|
|
42
|
+
dp: str = ""
|
|
43
|
+
artist: str = ""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ZenCategoryDownload(BaseModel):
|
|
47
|
+
id: str
|
|
48
|
+
title: str = ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ZenGroupDownload(BaseModel):
|
|
52
|
+
group: str
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class SmoDownload(BaseModel):
|
|
56
|
+
pack_title: str
|
|
57
|
+
download: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# --- App lifespan ---
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@asynccontextmanager
|
|
64
|
+
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
65
|
+
logger.remove()
|
|
66
|
+
logger.add(str(config.log_file), retention="7 days", rotation="10 MB")
|
|
67
|
+
logger.info("smfetch starting up")
|
|
68
|
+
smo.pack_cache.build_async()
|
|
69
|
+
yield
|
|
70
|
+
logger.info("smfetch shutting down")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
app = FastAPI(title="smfetch", version="1.0.0", lifespan=lifespan)
|
|
74
|
+
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# --- UI ---
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@app.get("/", response_class=HTMLResponse)
|
|
81
|
+
async def index() -> FileResponse:
|
|
82
|
+
return FileResponse(STATIC_DIR / "index.html")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# --- Config ---
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@app.get("/api/config")
|
|
89
|
+
async def get_config() -> dict[str, str]:
|
|
90
|
+
return {
|
|
91
|
+
"songs_dir": config.songs_dir,
|
|
92
|
+
"log_dir": config.log_dir,
|
|
93
|
+
"config_dir": config.config_dir,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@app.put("/api/config")
|
|
98
|
+
async def update_config(body: ConfigUpdate) -> dict[str, str]:
|
|
99
|
+
if body.songs_dir is not None:
|
|
100
|
+
config.songs_dir = body.songs_dir
|
|
101
|
+
if body.log_dir is not None:
|
|
102
|
+
config.log_dir = body.log_dir
|
|
103
|
+
if body.config_dir is not None:
|
|
104
|
+
config.config_dir = body.config_dir
|
|
105
|
+
config.ensure_dirs()
|
|
106
|
+
config.save()
|
|
107
|
+
return await get_config()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# --- Jobs ---
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@app.get("/api/jobs")
|
|
114
|
+
async def list_jobs() -> dict[str, Any]:
|
|
115
|
+
return {
|
|
116
|
+
"jobs": jobs.list_jobs(),
|
|
117
|
+
"active_count": jobs.active_count(),
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@app.post("/api/jobs/clear")
|
|
122
|
+
async def clear_jobs() -> dict[str, int]:
|
|
123
|
+
return {"cleared": jobs.clear_completed()}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# --- Zenius endpoints ---
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@app.get("/api/zenius/search")
|
|
130
|
+
async def zenius_search(
|
|
131
|
+
title: str = Query(default=""),
|
|
132
|
+
artist: str = Query(default=""),
|
|
133
|
+
) -> list[dict[str, Any]]:
|
|
134
|
+
results = zen.search_songs(title, artist)
|
|
135
|
+
return [r.to_dict() for r in results]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@app.get("/api/zenius/categories")
|
|
139
|
+
async def zenius_categories(
|
|
140
|
+
group: str = Query(..., description="ARCADE, SPINOFF, OFFICIAL, or USER"),
|
|
141
|
+
) -> list[dict[str, str]]:
|
|
142
|
+
try:
|
|
143
|
+
g = zen.Group[group.upper()]
|
|
144
|
+
except KeyError:
|
|
145
|
+
return []
|
|
146
|
+
return zen.fetch_categories(g)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@app.post("/api/zenius/download/song")
|
|
150
|
+
async def zenius_download_song(body: ZenSongDownload) -> dict[str, str]:
|
|
151
|
+
result = zen.SearchResult(
|
|
152
|
+
song_name=body.song_name,
|
|
153
|
+
song_page=body.song_page,
|
|
154
|
+
pack_name=body.pack_name,
|
|
155
|
+
pack_page=body.pack_page,
|
|
156
|
+
group=body.group,
|
|
157
|
+
difficulties=zen.Levels(body.sp, body.dp),
|
|
158
|
+
artist=body.artist,
|
|
159
|
+
)
|
|
160
|
+
job_id = jobs.submit(
|
|
161
|
+
f"Zenius: {result.song_name} by {result.artist}",
|
|
162
|
+
zen.download_song,
|
|
163
|
+
result,
|
|
164
|
+
)
|
|
165
|
+
return {"job_id": job_id}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@app.post("/api/zenius/download/category")
|
|
169
|
+
async def zenius_download_category(body: ZenCategoryDownload) -> dict[str, str]:
|
|
170
|
+
title = body.title or f"Category {body.id}"
|
|
171
|
+
job_id = jobs.submit(
|
|
172
|
+
f"Zenius pack: {title}",
|
|
173
|
+
zen.download_category,
|
|
174
|
+
body.id,
|
|
175
|
+
)
|
|
176
|
+
return {"job_id": job_id}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@app.post("/api/zenius/download/group")
|
|
180
|
+
async def zenius_download_group(body: ZenGroupDownload) -> dict[str, str]:
|
|
181
|
+
try:
|
|
182
|
+
group = zen.Group[body.group.upper()]
|
|
183
|
+
except KeyError:
|
|
184
|
+
return {"error": f"Invalid group: {body.group}"}
|
|
185
|
+
job_id = jobs.submit(
|
|
186
|
+
f"Zenius bundle: {group.name}",
|
|
187
|
+
zen.download_group,
|
|
188
|
+
group,
|
|
189
|
+
)
|
|
190
|
+
return {"job_id": job_id}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# --- SMOnline endpoints ---
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@app.get("/api/smonline/search")
|
|
197
|
+
async def smonline_search(
|
|
198
|
+
category: str = Query(..., description="title or artist"),
|
|
199
|
+
query: str = Query(...),
|
|
200
|
+
) -> list[dict[str, Any]]:
|
|
201
|
+
if category not in ("title", "artist"):
|
|
202
|
+
return []
|
|
203
|
+
entries = smo.search_songs(category, query)
|
|
204
|
+
return [e.to_dict() for e in entries]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@app.get("/api/smonline/packs")
|
|
208
|
+
async def smonline_packs() -> dict[str, Any]:
|
|
209
|
+
return {
|
|
210
|
+
"ready": smo.pack_cache.is_ready,
|
|
211
|
+
"building": smo.pack_cache.is_building,
|
|
212
|
+
"packs": [e.to_dict() for e in smo.pack_cache.entries],
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@app.post("/api/smonline/packs/refresh")
|
|
217
|
+
async def smonline_refresh_cache() -> dict[str, str]:
|
|
218
|
+
smo.pack_cache.build_async()
|
|
219
|
+
return {"status": "rebuilding"}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@app.post("/api/smonline/download")
|
|
223
|
+
async def smonline_download(body: SmoDownload) -> dict[str, str]:
|
|
224
|
+
job_id = jobs.submit(
|
|
225
|
+
f"SMOnline: {body.pack_title}",
|
|
226
|
+
smo.download_pack,
|
|
227
|
+
body.pack_title,
|
|
228
|
+
body.download,
|
|
229
|
+
)
|
|
230
|
+
return {"job_id": job_id}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# --- Entrypoint ---
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
DEFAULT_PORT = 8095
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def main() -> None:
|
|
240
|
+
parser = argparse.ArgumentParser(description="smfetch web interface")
|
|
241
|
+
parser.add_argument(
|
|
242
|
+
"-p",
|
|
243
|
+
"--port",
|
|
244
|
+
type=int,
|
|
245
|
+
default=DEFAULT_PORT,
|
|
246
|
+
help=f"port for the web interface (default: {DEFAULT_PORT})",
|
|
247
|
+
)
|
|
248
|
+
args = parser.parse_args()
|
|
249
|
+
|
|
250
|
+
print(f"Starting smfetch on http://localhost:{args.port}")
|
|
251
|
+
uvicorn.run(
|
|
252
|
+
"smfetch.app:app",
|
|
253
|
+
host="127.0.0.1",
|
|
254
|
+
port=args.port,
|
|
255
|
+
log_level="warning",
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
if __name__ == "__main__":
|
|
260
|
+
main()
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Cross-platform configuration with sensible defaults per OS.
|
|
2
|
+
|
|
3
|
+
Config file location:
|
|
4
|
+
- Windows: %APPDATA%/smfetch/config.json
|
|
5
|
+
- macOS: ~/Library/Application Support/smfetch/config.json
|
|
6
|
+
- Linux: $XDG_CONFIG_HOME/smfetch/config.json (default ~/.config/smfetch/)
|
|
7
|
+
|
|
8
|
+
Songs directory:
|
|
9
|
+
- Windows: %USERPROFILE%/Music/StepMania Songs
|
|
10
|
+
- macOS: ~/Music/StepMania Songs
|
|
11
|
+
- Linux: ~/.local/share/smfetch
|
|
12
|
+
|
|
13
|
+
Log directory:
|
|
14
|
+
- Windows: %LOCALAPPDATA%/smfetch/logs
|
|
15
|
+
- macOS: ~/Library/Logs/smfetch
|
|
16
|
+
- Linux: $XDG_STATE_HOME/smfetch/logs (default ~/.local/state/smfetch/logs)
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import platform
|
|
24
|
+
from dataclasses import asdict, dataclass, field
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
from loguru import logger
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _default_config_dir() -> Path:
|
|
31
|
+
system = platform.system()
|
|
32
|
+
if system == "Windows":
|
|
33
|
+
return Path(os.environ.get("APPDATA", Path.home() / "AppData" / "Roaming")) / "smfetch"
|
|
34
|
+
elif system == "Darwin":
|
|
35
|
+
return Path.home() / "Library" / "Application Support" / "smfetch"
|
|
36
|
+
else:
|
|
37
|
+
return Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "smfetch"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _default_songs_dir() -> Path:
|
|
41
|
+
system = platform.system()
|
|
42
|
+
if system in ("Windows", "Darwin"):
|
|
43
|
+
return Path.home() / "Music" / "StepMania Songs"
|
|
44
|
+
else:
|
|
45
|
+
return Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "smfetch"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _default_log_dir() -> Path:
|
|
49
|
+
system = platform.system()
|
|
50
|
+
if system == "Windows":
|
|
51
|
+
return (
|
|
52
|
+
Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
|
|
53
|
+
/ "smfetch"
|
|
54
|
+
/ "logs"
|
|
55
|
+
)
|
|
56
|
+
elif system == "Darwin":
|
|
57
|
+
return Path.home() / "Library" / "Logs" / "smfetch"
|
|
58
|
+
else:
|
|
59
|
+
return (
|
|
60
|
+
Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state"))
|
|
61
|
+
/ "smfetch"
|
|
62
|
+
/ "logs"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
CONFIG_PATH = _default_config_dir() / "config.json"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass
|
|
70
|
+
class AppConfig:
|
|
71
|
+
songs_dir: str = field(default_factory=lambda: str(_default_songs_dir()))
|
|
72
|
+
log_dir: str = field(default_factory=lambda: str(_default_log_dir()))
|
|
73
|
+
config_dir: str = field(default_factory=lambda: str(_default_config_dir()))
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def songs_path(self) -> Path:
|
|
77
|
+
return Path(self.songs_dir)
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def log_path(self) -> Path:
|
|
81
|
+
return Path(self.log_dir)
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def log_file(self) -> Path:
|
|
85
|
+
return self.log_path / "smfetch.log"
|
|
86
|
+
|
|
87
|
+
def ensure_dirs(self) -> None:
|
|
88
|
+
self.songs_path.mkdir(parents=True, exist_ok=True)
|
|
89
|
+
self.log_path.mkdir(parents=True, exist_ok=True)
|
|
90
|
+
Path(self.config_dir).mkdir(parents=True, exist_ok=True)
|
|
91
|
+
|
|
92
|
+
def save(self) -> None:
|
|
93
|
+
path = Path(self.config_dir) / "config.json"
|
|
94
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
95
|
+
path.write_text(json.dumps(asdict(self), indent=2))
|
|
96
|
+
logger.info(f"Config saved to {path}")
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def load(cls) -> AppConfig:
|
|
100
|
+
path = CONFIG_PATH
|
|
101
|
+
if path.exists():
|
|
102
|
+
try:
|
|
103
|
+
data = json.loads(path.read_text())
|
|
104
|
+
return cls(**{k: v for k, v in data.items() if k in cls.__dataclass_fields__})
|
|
105
|
+
except (json.JSONDecodeError, TypeError) as e:
|
|
106
|
+
logger.warning(f"Failed to load config from {path}: {e}")
|
|
107
|
+
config = cls()
|
|
108
|
+
config.ensure_dirs()
|
|
109
|
+
config.save()
|
|
110
|
+
return config
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# Singleton config loaded at import
|
|
114
|
+
config = AppConfig.load()
|
|
115
|
+
config.ensure_dirs()
|