smfetch 1.2.0__tar.gz → 1.3.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.
@@ -1,9 +1,10 @@
1
1
  UV ?= uv
2
2
  PROJECT_DIR ?= .
3
3
 
4
- .PHONY: run check format install clean publish sync-version
4
+ .PHONY: run check format test install clean publish
5
5
 
6
- VERSION_FILES = smfetch/app.py smfetch/static/index.html
6
+ # The app and UI both read the version from installed package metadata, so
7
+ # pyproject.toml is the only place it is written down.
7
8
 
8
9
  run:
9
10
  $(UV) run smfetch
@@ -15,8 +16,14 @@ check:
15
16
  $(UV) run ruff check --fix --select I,F,UP,B $(PROJECT_DIR)
16
17
  $(UV) run ty check $(PROJECT_DIR)
17
18
 
19
+ # Fully offline: the scrapers run against captured pages and the rest against a
20
+ # fake site, so this never touches the network or your real songs directory.
21
+ test:
22
+ $(UV) run pytest
23
+
18
24
  install: clean format check
19
25
  $(UV) sync
26
+ $(MAKE) test
20
27
 
21
28
  clean:
22
29
  find $(PROJECT_DIR) -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@@ -25,12 +32,6 @@ clean:
25
32
  rm -rf $(PROJECT_DIR)/dist $(PROJECT_DIR)/build $(PROJECT_DIR)/*.egg-info 2>/dev/null || true
26
33
  rm -rf $(PROJECT_DIR)/.pytest_cache $(PROJECT_DIR)/.coverage* $(PROJECT_DIR)/htmlcov 2>/dev/null || true
27
34
 
28
- sync-version:
29
- @VERSION=$$($(UV) version --short); \
30
- echo "Syncing version $$VERSION across source files..."; \
31
- sed -i -E 's/(FastAPI\([^)]*version=")[^"]*(")/\1'"$$VERSION"'\2/' smfetch/app.py; \
32
- sed -i -E 's|(<div class="logo">smfetch<span> v)[^<]*(</span>)|\1'"$$VERSION"'\2|' smfetch/static/index.html
33
-
34
35
  publish:
35
36
  @CURRENT_VERSION=$$($(UV) version --short); \
36
37
  echo "Current version: $$CURRENT_VERSION"; \
@@ -44,13 +45,12 @@ publish:
44
45
  echo "Using current version: $$CURRENT_VERSION"; \
45
46
  fi; \
46
47
  FINAL_VERSION=$$($(UV) version --short); \
47
- $(MAKE) sync-version; \
48
48
  $(MAKE) install; \
49
49
  $(UV) build; \
50
50
  $(UV) publish; \
51
- if [ -n "$$(git status --porcelain -- pyproject.toml uv.lock $(VERSION_FILES))" ]; then \
51
+ if [ -n "$$(git status --porcelain -- pyproject.toml uv.lock)" ]; then \
52
52
  echo "Committing version changes..."; \
53
- git add pyproject.toml uv.lock $(VERSION_FILES); \
53
+ git add pyproject.toml uv.lock; \
54
54
  git commit -m "Release $$FINAL_VERSION"; \
55
55
  echo "Pushing to remote..."; \
56
56
  git push origin HEAD; \
smfetch-1.3.1/PKG-INFO ADDED
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: smfetch
3
+ Version: 1.3.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
+ ### Update tracking
35
+
36
+ smfetch remembers which packs you have installed and when, then watches Zenius'
37
+ [latest official](https://zenius-i-vanisher.com/v5.2/simfiles.php?category=latest-official)
38
+ and [latest user](https://zenius-i-vanisher.com/v5.2/simfiles.php?category=latest-user)
39
+ listings for changes to those packs. When a chart is revised or added, it is
40
+ downloaded **individually into the pack it belongs to** — no re-downloading a
41
+ whole pack for one chart.
42
+
43
+ - **Review before applying.** Detections collect in the Updates view. You choose
44
+ what to pull and when; nothing downloads on its own.
45
+ - **One entry per chart.** If a chart changes several times between applies it
46
+ stays a single pending item that advances to the newest version, so applying
47
+ fetches the latest revision once. If a chart changes again *while* its
48
+ download is running it stays pending for the next pass, rather than being
49
+ silently marked current.
50
+ - **Adopting what you already have.** Scan the songs directory to find pack
51
+ folders smfetch did not install and link them to their Zenius category by name
52
+ match. Charts already on disk are treated as current, so only changes
53
+ published after linking are reported.
54
+ - **StepManiaOnline packs too.** The two sites carry many of the same packs, so
55
+ a pack downloaded from StepManiaOnline can be linked to its Zenius
56
+ counterpart and updated from there. Linking records the origin separately, so
57
+ the pack still shows where it came from. Song folders are matched by name
58
+ when linking — `attitude` on disk against `Attitude` on Zenius — so an update
59
+ replaces the song already installed instead of dropping a second copy beside
60
+ it. A chart the pack does not have yet arrives under its Zenius title.
61
+
62
+ Update checking joins on a Zenius pack, so a pack with no link is never
63
+ checked. The Installed Packs view marks those `unlinked` and offers to link
64
+ them.
65
+
66
+ Checks run on a configurable interval (6 hours by default) and on demand. The
67
+ user listing only reaches back about a week, so an interval of a day or less is
68
+ worthwhile if you follow user packs.
69
+
70
+ ### Zenius-i-Vanisher
71
+ - **Song search** — search by song name and/or artist, select and download individual charts
72
+ - **Pack search** — filter official or user packs, download selected packs
73
+ - **Bundles** — one-click download of arcade, spinoff, or all official packs
74
+
75
+ ### StepManiaOnline
76
+ - **Title search** — search packs that contain a chart with a song title
77
+ - **Artist search** — search packs that contain a chart by an artist
78
+ - **Pack search** — filter all packs by name
79
+
80
+ ## Interface
81
+
82
+ The UI is dependency-free HTML, CSS and JavaScript served straight from the
83
+ package — no build step, and no network fetches at runtime. It follows your
84
+ system light/dark preference and has a manual toggle.
85
+
86
+ | Key | Action |
87
+ |---|---|
88
+ | `/` | Focus the current view's search box |
89
+ | `J` | Toggle the downloads panel |
90
+ | `U` | Jump to Updates |
91
+ | `Esc` | Close any panel or dialog |
92
+
93
+ ## Storage Defaults
94
+
95
+ | | Config | Songs | Logs |
96
+ |---|---|---|---|
97
+ | **Linux** | `~/.config/smfetch/` | `~/.local/share/smfetch/` | `~/.local/state/smfetch/logs/` |
98
+ | **macOS** | `~/Library/Application Support/smfetch/` | `~/Music/StepMania Songs/` | `~/Library/Logs/smfetch/` |
99
+ | **Windows** | `%APPDATA%/smfetch/` | `~/Music/StepMania Songs/` | `%LOCALAPPDATA%/smfetch/logs/` |
100
+
101
+ Installed packs and pending updates live in `library.json` inside the config
102
+ directory. Deleting it only loses update history — nothing on disk is touched,
103
+ and a scan will re-adopt your packs.
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ make run # start the app
109
+ make format # ruff format
110
+ make check # ruff lint + ty
111
+ make test # pytest
112
+ make install # clean, format, check, sync, test
113
+ ```
114
+
115
+ The test suite is fully offline and takes well under a second. Scrapers run
116
+ against trimmed captures of real Zenius pages in `tests/fixtures/`, so changes
117
+ to the parsing are checked against the markup the site actually serves; the rest
118
+ runs against a scriptable fake site with Zenius' clock pinned, and any
119
+ unexpected request fails the test rather than reaching the network. Config,
120
+ songs and library state are redirected to a temporary directory, so running the
121
+ tests never touches your real collection.
122
+
123
+ ## Notes on upstream timestamps
124
+
125
+ Zenius reports ages relative to its own clock ("2.6 days ago") and exact times
126
+ only on an individual simfile's page. smfetch derives the site's clock offset
127
+ from a recent simfile so relative ages resolve to absolute times, screens the
128
+ listings cheaply with those, and confirms anything that looks changed against
129
+ the exact timestamp before recording it. Rounded ages carry real slop — a value
130
+ in weeks is only good to a few hours — so comparisons allow a tolerance scaled
131
+ to the unit, which is what keeps unchanged charts from reappearing as updates.
@@ -0,0 +1,118 @@
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
+ ### Update tracking
22
+
23
+ smfetch remembers which packs you have installed and when, then watches Zenius'
24
+ [latest official](https://zenius-i-vanisher.com/v5.2/simfiles.php?category=latest-official)
25
+ and [latest user](https://zenius-i-vanisher.com/v5.2/simfiles.php?category=latest-user)
26
+ listings for changes to those packs. When a chart is revised or added, it is
27
+ downloaded **individually into the pack it belongs to** — no re-downloading a
28
+ whole pack for one chart.
29
+
30
+ - **Review before applying.** Detections collect in the Updates view. You choose
31
+ what to pull and when; nothing downloads on its own.
32
+ - **One entry per chart.** If a chart changes several times between applies it
33
+ stays a single pending item that advances to the newest version, so applying
34
+ fetches the latest revision once. If a chart changes again *while* its
35
+ download is running it stays pending for the next pass, rather than being
36
+ silently marked current.
37
+ - **Adopting what you already have.** Scan the songs directory to find pack
38
+ folders smfetch did not install and link them to their Zenius category by name
39
+ match. Charts already on disk are treated as current, so only changes
40
+ published after linking are reported.
41
+ - **StepManiaOnline packs too.** The two sites carry many of the same packs, so
42
+ a pack downloaded from StepManiaOnline can be linked to its Zenius
43
+ counterpart and updated from there. Linking records the origin separately, so
44
+ the pack still shows where it came from. Song folders are matched by name
45
+ when linking — `attitude` on disk against `Attitude` on Zenius — so an update
46
+ replaces the song already installed instead of dropping a second copy beside
47
+ it. A chart the pack does not have yet arrives under its Zenius title.
48
+
49
+ Update checking joins on a Zenius pack, so a pack with no link is never
50
+ checked. The Installed Packs view marks those `unlinked` and offers to link
51
+ them.
52
+
53
+ Checks run on a configurable interval (6 hours by default) and on demand. The
54
+ user listing only reaches back about a week, so an interval of a day or less is
55
+ worthwhile if you follow user packs.
56
+
57
+ ### Zenius-i-Vanisher
58
+ - **Song search** — search by song name and/or artist, select and download individual charts
59
+ - **Pack search** — filter official or user packs, download selected packs
60
+ - **Bundles** — one-click download of arcade, spinoff, or all official packs
61
+
62
+ ### StepManiaOnline
63
+ - **Title search** — search packs that contain a chart with a song title
64
+ - **Artist search** — search packs that contain a chart by an artist
65
+ - **Pack search** — filter all packs by name
66
+
67
+ ## Interface
68
+
69
+ The UI is dependency-free HTML, CSS and JavaScript served straight from the
70
+ package — no build step, and no network fetches at runtime. It follows your
71
+ system light/dark preference and has a manual toggle.
72
+
73
+ | Key | Action |
74
+ |---|---|
75
+ | `/` | Focus the current view's search box |
76
+ | `J` | Toggle the downloads panel |
77
+ | `U` | Jump to Updates |
78
+ | `Esc` | Close any panel or dialog |
79
+
80
+ ## Storage Defaults
81
+
82
+ | | Config | Songs | Logs |
83
+ |---|---|---|---|
84
+ | **Linux** | `~/.config/smfetch/` | `~/.local/share/smfetch/` | `~/.local/state/smfetch/logs/` |
85
+ | **macOS** | `~/Library/Application Support/smfetch/` | `~/Music/StepMania Songs/` | `~/Library/Logs/smfetch/` |
86
+ | **Windows** | `%APPDATA%/smfetch/` | `~/Music/StepMania Songs/` | `%LOCALAPPDATA%/smfetch/logs/` |
87
+
88
+ Installed packs and pending updates live in `library.json` inside the config
89
+ directory. Deleting it only loses update history — nothing on disk is touched,
90
+ and a scan will re-adopt your packs.
91
+
92
+ ## Development
93
+
94
+ ```bash
95
+ make run # start the app
96
+ make format # ruff format
97
+ make check # ruff lint + ty
98
+ make test # pytest
99
+ make install # clean, format, check, sync, test
100
+ ```
101
+
102
+ The test suite is fully offline and takes well under a second. Scrapers run
103
+ against trimmed captures of real Zenius pages in `tests/fixtures/`, so changes
104
+ to the parsing are checked against the markup the site actually serves; the rest
105
+ runs against a scriptable fake site with Zenius' clock pinned, and any
106
+ unexpected request fails the test rather than reaching the network. Config,
107
+ songs and library state are redirected to a temporary directory, so running the
108
+ tests never touches your real collection.
109
+
110
+ ## Notes on upstream timestamps
111
+
112
+ Zenius reports ages relative to its own clock ("2.6 days ago") and exact times
113
+ only on an individual simfile's page. smfetch derives the site's clock offset
114
+ from a recent simfile so relative ages resolve to absolute times, screens the
115
+ listings cheaply with those, and confirms anything that looks changed against
116
+ the exact timestamp before recording it. Rounded ages carry real slop — a value
117
+ in weeks is only good to a few hours — so comparisons allow a tolerance scaled
118
+ to the unit, which is what keeps unchanged charts from reappearing as updates.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "smfetch"
3
- version = "1.2.0"
3
+ version = "1.3.1"
4
4
  description = "Web interface for downloading simfiles from Zenius and StepManiaOnline"
5
5
  authors = [{ name = "Raeed Ahmed", email = "code@raeed.me" }]
6
6
  requires-python = ">=3.10,<4"
@@ -22,6 +22,7 @@ dev = [
22
22
  "types-requests>=2.32.0.20240622,<3",
23
23
  "types-beautifulsoup4>=4.12.0.20240511,<5",
24
24
  "ty>=0.0.19",
25
+ "pytest>=8.0",
25
26
  ]
26
27
 
27
28
  [build-system]
@@ -35,3 +36,7 @@ warn_unused_configs = true
35
36
 
36
37
  [tool.ruff]
37
38
  line-length = 100
39
+
40
+ [tool.pytest.ini_options]
41
+ testpaths = ["tests"]
42
+ addopts = "-q --strict-markers"
@@ -5,23 +5,32 @@ from __future__ import annotations
5
5
  import argparse
6
6
  from collections.abc import AsyncIterator
7
7
  from contextlib import asynccontextmanager
8
+ from importlib.metadata import PackageNotFoundError
9
+ from importlib.metadata import version as package_version
8
10
  from pathlib import Path
9
11
  from typing import Any
10
12
 
11
13
  import uvicorn
12
- from fastapi import FastAPI, Query
14
+ from fastapi import FastAPI, HTTPException, Query
13
15
  from fastapi.responses import FileResponse, HTMLResponse
14
16
  from fastapi.staticfiles import StaticFiles
15
17
  from loguru import logger
16
18
  from pydantic import BaseModel
17
19
 
18
20
  from smfetch import smonline as smo
21
+ from smfetch import updates as upd
19
22
  from smfetch import zenius as zen
20
23
  from smfetch.config import config
21
24
  from smfetch.jobs import jobs
25
+ from smfetch.library import library
22
26
 
23
27
  STATIC_DIR = Path(__file__).parent / "static"
24
28
 
29
+ try:
30
+ VERSION = package_version("smfetch")
31
+ except PackageNotFoundError: # running from a source checkout
32
+ VERSION = "0.0.0+dev"
33
+
25
34
 
26
35
  # --- Pydantic request models ---
27
36
 
@@ -30,6 +39,8 @@ class ConfigUpdate(BaseModel):
30
39
  songs_dir: str | None = None
31
40
  log_dir: str | None = None
32
41
  config_dir: str | None = None
42
+ update_check_enabled: bool | None = None
43
+ update_interval_hours: float | None = None
33
44
 
34
45
 
35
46
  class ZenSongDownload(BaseModel):
@@ -43,11 +54,19 @@ class ZenSongDownload(BaseModel):
43
54
  artist: str = ""
44
55
 
45
56
 
57
+ class ZenSongBatch(BaseModel):
58
+ songs: list[ZenSongDownload]
59
+
60
+
46
61
  class ZenCategoryDownload(BaseModel):
47
62
  id: str
48
63
  title: str = ""
49
64
 
50
65
 
66
+ class ZenCategoryBatch(BaseModel):
67
+ categories: list[ZenCategoryDownload]
68
+
69
+
51
70
  class ZenGroupDownload(BaseModel):
52
71
  group: str
53
72
 
@@ -57,6 +76,24 @@ class SmoDownload(BaseModel):
57
76
  download: str
58
77
 
59
78
 
79
+ class SmoBatch(BaseModel):
80
+ packs: list[SmoDownload]
81
+
82
+
83
+ class AdoptRequest(BaseModel):
84
+ pack_dir: str
85
+ category_id: str
86
+ name: str = ""
87
+
88
+
89
+ class UntrackRequest(BaseModel):
90
+ pack_dir: str
91
+
92
+
93
+ class SimfileIds(BaseModel):
94
+ simfile_ids: list[str]
95
+
96
+
60
97
  # --- App lifespan ---
61
98
 
62
99
 
@@ -64,13 +101,15 @@ class SmoDownload(BaseModel):
64
101
  async def lifespan(app: FastAPI) -> AsyncIterator[None]:
65
102
  logger.remove()
66
103
  logger.add(str(config.log_file), retention="7 days", rotation="10 MB")
67
- logger.info("smfetch starting up")
104
+ logger.info(f"smfetch {VERSION} starting up")
68
105
  smo.pack_cache.build_async()
106
+ upd.scheduler.start()
69
107
  yield
108
+ upd.scheduler.stop()
70
109
  logger.info("smfetch shutting down")
71
110
 
72
111
 
73
- app = FastAPI(title="smfetch", version="1.2.0", lifespan=lifespan)
112
+ app = FastAPI(title="smfetch", version=VERSION, lifespan=lifespan)
74
113
  app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
75
114
 
76
115
 
@@ -85,26 +124,37 @@ async def index() -> FileResponse:
85
124
  # --- Config ---
86
125
 
87
126
 
88
- @app.get("/api/config")
89
- async def get_config() -> dict[str, str]:
127
+ def _config_payload() -> dict[str, Any]:
90
128
  return {
129
+ "version": VERSION,
91
130
  "songs_dir": config.songs_dir,
92
131
  "log_dir": config.log_dir,
93
132
  "config_dir": config.config_dir,
133
+ "update_check_enabled": config.update_check_enabled,
134
+ "update_interval_hours": config.update_interval_hours,
94
135
  }
95
136
 
96
137
 
138
+ @app.get("/api/config")
139
+ async def get_config() -> dict[str, Any]:
140
+ return _config_payload()
141
+
142
+
97
143
  @app.put("/api/config")
98
- async def update_config(body: ConfigUpdate) -> dict[str, str]:
144
+ async def update_config(body: ConfigUpdate) -> dict[str, Any]:
99
145
  if body.songs_dir is not None:
100
146
  config.songs_dir = body.songs_dir
101
147
  if body.log_dir is not None:
102
148
  config.log_dir = body.log_dir
103
149
  if body.config_dir is not None:
104
150
  config.config_dir = body.config_dir
151
+ if body.update_check_enabled is not None:
152
+ config.update_check_enabled = body.update_check_enabled
153
+ if body.update_interval_hours is not None:
154
+ config.update_interval_hours = max(0.25, body.update_interval_hours)
105
155
  config.ensure_dirs()
106
156
  config.save()
107
- return await get_config()
157
+ return _config_payload()
108
158
 
109
159
 
110
160
  # --- Jobs ---
@@ -146,8 +196,7 @@ async def zenius_categories(
146
196
  return zen.fetch_categories(g)
147
197
 
148
198
 
149
- @app.post("/api/zenius/download/song")
150
- async def zenius_download_song(body: ZenSongDownload) -> dict[str, str]:
199
+ def _submit_song(body: ZenSongDownload) -> str:
151
200
  result = zen.SearchResult(
152
201
  song_name=body.song_name,
153
202
  song_page=body.song_page,
@@ -157,41 +206,55 @@ async def zenius_download_song(body: ZenSongDownload) -> dict[str, str]:
157
206
  difficulties=zen.Levels(body.sp, body.dp),
158
207
  artist=body.artist,
159
208
  )
160
- job_id = jobs.submit(
209
+ return jobs.submit(
161
210
  f"Zenius: {result.song_name} by {result.artist}",
162
211
  zen.download_song,
163
212
  result,
164
213
  )
165
- return {"job_id": job_id}
166
214
 
167
215
 
168
- @app.post("/api/zenius/download/category")
169
- async def zenius_download_category(body: ZenCategoryDownload) -> dict[str, str]:
216
+ @app.post("/api/zenius/download/song")
217
+ async def zenius_download_song(body: ZenSongDownload) -> dict[str, str]:
218
+ return {"job_id": _submit_song(body)}
219
+
220
+
221
+ @app.post("/api/zenius/download/songs")
222
+ async def zenius_download_songs(body: ZenSongBatch) -> dict[str, list[str]]:
223
+ return {"job_ids": [_submit_song(song) for song in body.songs]}
224
+
225
+
226
+ def _submit_category(body: ZenCategoryDownload) -> str:
170
227
  title = body.title or f"Category {body.id}"
171
- job_id = jobs.submit(
228
+ return jobs.submit(
172
229
  f"Zenius pack: {title}",
173
230
  zen.download_category,
174
231
  body.id,
232
+ body.title,
175
233
  )
176
- return {"job_id": job_id}
234
+
235
+
236
+ @app.post("/api/zenius/download/category")
237
+ async def zenius_download_category(body: ZenCategoryDownload) -> dict[str, str]:
238
+ return {"job_id": _submit_category(body)}
239
+
240
+
241
+ @app.post("/api/zenius/download/categories")
242
+ async def zenius_download_categories(body: ZenCategoryBatch) -> dict[str, list[str]]:
243
+ return {"job_ids": [_submit_category(cat) for cat in body.categories]}
177
244
 
178
245
 
179
246
  @app.post("/api/zenius/download/group")
180
- async def zenius_download_group(body: ZenGroupDownload) -> dict[str, list[str]]:
247
+ async def zenius_download_group(body: ZenGroupDownload) -> dict[str, Any]:
181
248
  try:
182
249
  group = zen.Group[body.group.upper()]
183
250
  except KeyError:
184
- return {"error": [f"Invalid group: {body.group}"]}
251
+ raise HTTPException(status_code=400, detail=f"Invalid group: {body.group}") from None
185
252
  categories = zen.fetch_categories(group)
186
253
  job_ids = [
187
- jobs.submit(
188
- f"Zenius pack: {cat['title']}",
189
- zen.download_category,
190
- cat["id"],
191
- )
254
+ _submit_category(ZenCategoryDownload(id=cat["id"], title=cat["title"]))
192
255
  for cat in categories
193
256
  ]
194
- return {"job_ids": job_ids}
257
+ return {"job_ids": job_ids, "count": len(job_ids)}
195
258
 
196
259
 
197
260
  # --- SMOnline endpoints ---
@@ -223,15 +286,112 @@ async def smonline_refresh_cache() -> dict[str, str]:
223
286
  return {"status": "rebuilding"}
224
287
 
225
288
 
226
- @app.post("/api/smonline/download")
227
- async def smonline_download(body: SmoDownload) -> dict[str, str]:
228
- job_id = jobs.submit(
289
+ def _submit_smo(body: SmoDownload) -> str:
290
+ return jobs.submit(
229
291
  f"SMOnline: {body.pack_title}",
230
292
  smo.download_pack,
231
293
  body.pack_title,
232
294
  body.download,
233
295
  )
234
- return {"job_id": job_id}
296
+
297
+
298
+ @app.post("/api/smonline/download")
299
+ async def smonline_download(body: SmoDownload) -> dict[str, str]:
300
+ return {"job_id": _submit_smo(body)}
301
+
302
+
303
+ @app.post("/api/smonline/download/packs")
304
+ async def smonline_download_packs(body: SmoBatch) -> dict[str, list[str]]:
305
+ return {"job_ids": [_submit_smo(pack) for pack in body.packs]}
306
+
307
+
308
+ # --- Library ---
309
+
310
+
311
+ @app.get("/api/library")
312
+ async def get_library() -> dict[str, Any]:
313
+ packs = sorted(library.packs, key=lambda p: p.name.lower())
314
+ return {
315
+ "packs": [p.to_dict() for p in packs],
316
+ "last_check": library.last_check,
317
+ "songs_dir": config.songs_dir,
318
+ }
319
+
320
+
321
+ @app.get("/api/library/scan")
322
+ async def scan_library() -> dict[str, Any]:
323
+ return upd.scan_songs_dir()
324
+
325
+
326
+ @app.post("/api/library/adopt")
327
+ async def adopt_pack(body: AdoptRequest) -> dict[str, Any]:
328
+ try:
329
+ return upd.adopt(body.pack_dir, body.category_id, body.name)
330
+ except ValueError as e:
331
+ raise HTTPException(status_code=400, detail=str(e)) from None
332
+
333
+
334
+ @app.post("/api/library/untrack")
335
+ async def untrack_pack(body: UntrackRequest) -> dict[str, bool]:
336
+ return {"removed": library.untrack_pack(body.pack_dir)}
337
+
338
+
339
+ @app.get("/api/library/verify")
340
+ async def verify_pack(pack_dir: str = Query(...)) -> dict[str, Any]:
341
+ try:
342
+ return upd.verify_pack(pack_dir)
343
+ except ValueError as e:
344
+ raise HTTPException(status_code=404, detail=str(e)) from None
345
+
346
+
347
+ # --- Updates ---
348
+
349
+
350
+ @app.get("/api/updates")
351
+ async def get_updates() -> dict[str, Any]:
352
+ pending = sorted(library.pending, key=lambda p: p.source_updated_at, reverse=True)
353
+ summary = upd.scheduler.last_summary
354
+ return {
355
+ "pending": [p.to_dict() for p in pending],
356
+ "count": len(pending),
357
+ "checking": upd.scheduler.is_busy,
358
+ "scheduler_running": upd.scheduler.is_running,
359
+ "last_check": library.last_check,
360
+ "last_summary": summary.to_dict() if summary else None,
361
+ "enabled": config.update_check_enabled,
362
+ "interval_hours": config.update_interval_hours,
363
+ }
364
+
365
+
366
+ @app.post("/api/updates/check")
367
+ async def check_updates_now() -> dict[str, Any]:
368
+ if upd.scheduler.is_busy:
369
+ return {"status": "already-running"}
370
+ job_id = jobs.submit("Checking Zenius for updates", upd.scheduler.run_once, kind="check")
371
+ return {"status": "started", "job_id": job_id}
372
+
373
+
374
+ @app.post("/api/updates/apply")
375
+ async def apply_updates(body: SimfileIds) -> dict[str, Any]:
376
+ job_ids: list[str] = []
377
+ for simfile_id in body.simfile_ids:
378
+ entry = library.get_pending(simfile_id)
379
+ if entry is None:
380
+ continue
381
+ job_ids.append(
382
+ jobs.submit(
383
+ f"Update: {entry.song_title} ({entry.pack_name})",
384
+ upd.apply_pending,
385
+ simfile_id,
386
+ kind="update",
387
+ )
388
+ )
389
+ return {"job_ids": job_ids, "count": len(job_ids)}
390
+
391
+
392
+ @app.post("/api/updates/dismiss")
393
+ async def dismiss_updates(body: SimfileIds) -> dict[str, int]:
394
+ return {"dismissed": library.dismiss_pending(body.simfile_ids)}
235
395
 
236
396
 
237
397
  # --- Entrypoint ---
@@ -254,7 +414,7 @@ def main() -> None:
254
414
  print(f"Starting smfetch on http://localhost:{args.port}")
255
415
  uvicorn.run(
256
416
  "smfetch.app:app",
257
- host="127.0.0.1",
417
+ host="0.0.0.1",
258
418
  port=args.port,
259
419
  log_level="warning",
260
420
  )
@@ -71,6 +71,8 @@ class AppConfig:
71
71
  songs_dir: str = field(default_factory=lambda: str(_default_songs_dir()))
72
72
  log_dir: str = field(default_factory=lambda: str(_default_log_dir()))
73
73
  config_dir: str = field(default_factory=lambda: str(_default_config_dir()))
74
+ update_check_enabled: bool = True
75
+ update_interval_hours: float = 6.0
74
76
 
75
77
  @property
76
78
  def songs_path(self) -> Path: