smfetch 1.0.1__tar.gz → 1.2.0__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.2.0/Makefile ADDED
@@ -0,0 +1,59 @@
1
+ UV ?= uv
2
+ PROJECT_DIR ?= .
3
+
4
+ .PHONY: run check format install clean publish sync-version
5
+
6
+ VERSION_FILES = smfetch/app.py smfetch/static/index.html
7
+
8
+ run:
9
+ $(UV) run smfetch
10
+
11
+ format:
12
+ $(UV) run ruff format $(PROJECT_DIR)
13
+
14
+ check:
15
+ $(UV) run ruff check --fix --select I,F,UP,B $(PROJECT_DIR)
16
+ $(UV) run ty check $(PROJECT_DIR)
17
+
18
+ install: clean format check
19
+ $(UV) sync
20
+
21
+ clean:
22
+ find $(PROJECT_DIR) -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
23
+ find $(PROJECT_DIR) -type f -name "*.py[co]" -delete 2>/dev/null || true
24
+ rm -rf $(PROJECT_DIR)/.ruff_cache $(PROJECT_DIR)/.ty_cache $(PROJECT_DIR)/.mypy_cache $(PROJECT_DIR)/.pyright $(PROJECT_DIR)/.eggs 2>/dev/null || true
25
+ rm -rf $(PROJECT_DIR)/dist $(PROJECT_DIR)/build $(PROJECT_DIR)/*.egg-info 2>/dev/null || true
26
+ rm -rf $(PROJECT_DIR)/.pytest_cache $(PROJECT_DIR)/.coverage* $(PROJECT_DIR)/htmlcov 2>/dev/null || true
27
+
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
+ publish:
35
+ @CURRENT_VERSION=$$($(UV) version --short); \
36
+ echo "Current version: $$CURRENT_VERSION"; \
37
+ read -p "Enter new version (or press Enter to keep current): " NEW_VERSION; \
38
+ if [ -n "$$NEW_VERSION" ] && [ "$$NEW_VERSION" != "$$CURRENT_VERSION" ]; then \
39
+ echo "Updating version to $$NEW_VERSION..."; \
40
+ $(UV) version "$$NEW_VERSION"; \
41
+ elif [ -n "$$NEW_VERSION" ] && [ "$$NEW_VERSION" = "$$CURRENT_VERSION" ]; then \
42
+ echo "Version unchanged (same as current)."; \
43
+ else \
44
+ echo "Using current version: $$CURRENT_VERSION"; \
45
+ fi; \
46
+ FINAL_VERSION=$$($(UV) version --short); \
47
+ $(MAKE) sync-version; \
48
+ $(MAKE) install; \
49
+ $(UV) build; \
50
+ $(UV) publish; \
51
+ if [ -n "$$(git status --porcelain -- pyproject.toml uv.lock $(VERSION_FILES))" ]; then \
52
+ echo "Committing version changes..."; \
53
+ git add pyproject.toml uv.lock $(VERSION_FILES); \
54
+ git commit -m "Release $$FINAL_VERSION"; \
55
+ echo "Pushing to remote..."; \
56
+ git push origin HEAD; \
57
+ else \
58
+ echo "No version-related changes; skipping commit and push."; \
59
+ fi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smfetch
3
- Version: 1.0.1
3
+ Version: 1.2.0
4
4
  Summary: Web interface for downloading simfiles from Zenius and StepManiaOnline
5
5
  Author-email: Raeed Ahmed <code@raeed.me>
6
6
  Requires-Python: <4,>=3.10
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "smfetch"
3
- version = "1.0.1"
3
+ version = "1.2.0"
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"
@@ -70,7 +70,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
70
70
  logger.info("smfetch shutting down")
71
71
 
72
72
 
73
- app = FastAPI(title="smfetch", version="1.0.0", lifespan=lifespan)
73
+ app = FastAPI(title="smfetch", version="1.2.0", lifespan=lifespan)
74
74
  app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
75
75
 
76
76
 
@@ -177,17 +177,21 @@ async def zenius_download_category(body: ZenCategoryDownload) -> dict[str, str]:
177
177
 
178
178
 
179
179
  @app.post("/api/zenius/download/group")
180
- async def zenius_download_group(body: ZenGroupDownload) -> dict[str, str]:
180
+ async def zenius_download_group(body: ZenGroupDownload) -> dict[str, list[str]]:
181
181
  try:
182
182
  group = zen.Group[body.group.upper()]
183
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}
184
+ return {"error": [f"Invalid group: {body.group}"]}
185
+ categories = zen.fetch_categories(group)
186
+ job_ids = [
187
+ jobs.submit(
188
+ f"Zenius pack: {cat['title']}",
189
+ zen.download_category,
190
+ cat["id"],
191
+ )
192
+ for cat in categories
193
+ ]
194
+ return {"job_ids": job_ids}
191
195
 
192
196
 
193
197
  # --- SMOnline endpoints ---
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import threading
6
6
  import uuid
7
7
  from collections.abc import Callable
8
+ from concurrent.futures.thread import ThreadPoolExecutor
8
9
  from dataclasses import dataclass, field
9
10
  from datetime import datetime
10
11
  from enum import Enum
@@ -42,9 +43,10 @@ class Job:
42
43
  class JobManager:
43
44
  """Thread-safe job manager with automatic status tracking."""
44
45
 
45
- def __init__(self) -> None:
46
+ def __init__(self, concurrency: int = 8) -> None:
46
47
  self._jobs: dict[str, Job] = {}
47
48
  self._lock = threading.Lock()
49
+ self._pool = ThreadPoolExecutor(max_workers=concurrency)
48
50
 
49
51
  def submit(self, name: str, fn: Callable[..., Any], *args: Any, **kwargs: Any) -> str:
50
52
  job_id = uuid.uuid4().hex[:8]
@@ -63,18 +65,15 @@ class JobManager:
63
65
  self._jobs[job_id].error = str(e)
64
66
  logger.error(f"Job failed: {name} - {e}")
65
67
 
66
- thread = threading.Thread(target=_wrapper, daemon=True)
67
-
68
68
  job = Job(
69
69
  id=job_id,
70
70
  name=name,
71
71
  status=JobStatus.PENDING,
72
72
  created_at=datetime.now(),
73
- _thread=thread,
74
73
  )
75
74
  with self._lock:
76
75
  self._jobs[job_id] = job
77
- thread.start()
76
+ self._pool.submit(_wrapper)
78
77
  logger.info(f"Job started: {name} ({job_id})")
79
78
  return job_id
80
79
 
@@ -56,13 +56,13 @@ class SongEntry(NamedTuple):
56
56
  }
57
57
 
58
58
 
59
- def _parse_pack_row(row: Tag) -> PackEntry:
60
- tags = row.select("td")
61
- title = tags[1].find("a").text # type: ignore[union-attr]
62
- size = tags[2].text.replace("\xa0", " ")
63
- songs = int(tags[3].text)
64
- created = datetime.strptime(tags[5].text.strip(), "%Y-%m-%d").date()
65
- download = f"{BASE}{tags[6].find('a').get('href')}" # type: ignore[union-attr]
59
+ def _parse_pack_row(cells: list[str]) -> PackEntry:
60
+ title = bs(cells[1], "html.parser").find("a").text # type: ignore[union-attr]
61
+ size = bs(cells[2], "html.parser").get_text(strip=True).replace("\xa0", " ")
62
+ songs = int(bs(cells[3], "html.parser").get_text(strip=True))
63
+ created = datetime.strptime(bs(cells[5], "html.parser").get_text(strip=True), "%Y-%m-%d").date()
64
+ href = bs(cells[6], "html.parser").find("a").get("href") # type: ignore[union-attr]
65
+ download = f"{BASE}{href}"
66
66
  idx = int(download.split("/")[-2])
67
67
  return PackEntry(title, size, songs, created, download, idx)
68
68
 
@@ -96,9 +96,25 @@ class PackCache:
96
96
 
97
97
  try:
98
98
  logger.info("Building SMOnline pack cache...")
99
- response = requests.get(f"{BASE}/packs").text
100
- soup = bs(response, "html.parser")
101
- entries = [_parse_pack_row(row) for row in soup.select("tbody tr")]
99
+ entries: list[PackEntry] = []
100
+ page_size = 500
101
+ start = 0
102
+ while True:
103
+ params = {
104
+ "draw": 1,
105
+ "start": start,
106
+ "length": page_size,
107
+ "order[0][column]": 1,
108
+ "order[0][dir]": "asc",
109
+ }
110
+ data = requests.get(f"{BASE}/api/packs/datatables", params=params).json()
111
+ rows = data.get("data") or []
112
+ if not rows:
113
+ break
114
+ entries.extend(_parse_pack_row(row) for row in rows)
115
+ start += page_size
116
+ if start >= data.get("recordsTotal", 0):
117
+ break
102
118
  with self._lock:
103
119
  self._entries = entries
104
120
  self._built = True
@@ -581,7 +581,7 @@
581
581
 
582
582
  <!-- Header -->
583
583
  <header>
584
- <div class="logo">smfetch<span> v1.0</span></div>
584
+ <div class="logo">smfetch<span> v1.2.0</span></div>
585
585
  <div class="header-right">
586
586
  <button class="job-badge" id="jobBadge" onclick="toggleJobs()">0 jobs</button>
587
587
  <button class="icon-btn" onclick="openSettings()" title="Settings">⚙</button>
@@ -276,13 +276,6 @@ def download_sim(
276
276
  _download_category_songs(sim)
277
277
 
278
278
 
279
- def download_group(group: Group) -> None:
280
- """Download all packs in a group (ARCADE/SPINOFF/OFFICIAL)."""
281
- for cat_info in fetch_categories(group):
282
- category = Category(cat_info["id"], cat_info["title"])
283
- download_sim(category)
284
-
285
-
286
279
  def download_category(category_id: str) -> None:
287
280
  """Download a single category by ID."""
288
281
  category = Category(category_id)
@@ -516,7 +516,7 @@ wheels = [
516
516
 
517
517
  [[package]]
518
518
  name = "smfetch"
519
- version = "1.0.1"
519
+ version = "1.2.0"
520
520
  source = { editable = "." }
521
521
  dependencies = [
522
522
  { name = "beautifulsoup4" },
smfetch-1.0.1/Makefile DELETED
@@ -1,24 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes