codetta 0.8.1__tar.gz → 0.8.3__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.
- {codetta-0.8.1/src/codetta.egg-info → codetta-0.8.3}/PKG-INFO +4 -4
- {codetta-0.8.1 → codetta-0.8.3}/README.md +3 -3
- {codetta-0.8.1 → codetta-0.8.3}/pyproject.toml +1 -1
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/CHANGELOG.md +10 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/cli/run.py +5 -3
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/index.py +4 -3
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/musicbrainz.py +9 -4
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/providers.py +24 -8
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/app.py +7 -4
- {codetta-0.8.1 → codetta-0.8.3/src/codetta.egg-info}/PKG-INFO +4 -4
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_cli_run.py +9 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_explore.py +5 -4
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_index.py +14 -2
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_musicbrainz.py +38 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_providers.py +34 -0
- {codetta-0.8.1 → codetta-0.8.3}/LICENSE +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/setup.cfg +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/__main__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/cli/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/cli/__main__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/acoustid.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/activity.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/artwork.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/auth.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/avatar.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/changelog.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/connections.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/describe.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/engine.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/health.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/inbox.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/library.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/notifications.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/onboarding.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/organize.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/plugins.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/presets.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/rawtags.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/slskd.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/tagmap.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/undo.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/core/updates.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/plugins/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/plugins/builtin/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/plugins/builtin/tidy.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/security.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/app.css +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/app.js +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/apple-touch-icon.png +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/fonts/LICENSE-Inter.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/fonts/LICENSE-SchibstedGrotesk.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/fonts/inter-cyrillic.woff2 +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/fonts/schibsted-grotesk.woff2 +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icon.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-dark.png +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-dark.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-dark.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-light.png +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-light.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta-light.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta.png +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/icons/codetta.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/index.html +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta/web/static/theme.js +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta.egg-info/SOURCES.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta.egg-info/dependency_links.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta.egg-info/entry_points.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta.egg-info/requires.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/src/codetta.egg-info/top_level.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_acoustid.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_api.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_artwork.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_attacks.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_auth.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_avatar.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_connections.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_efficiency.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_engine.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_health.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_inbox.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_organize.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_plugins.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_presets.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_privacy.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_rawtags.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_safety.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_security.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_slskd.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_soulseek_api.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_undo.py +0 -0
- {codetta-0.8.1 → codetta-0.8.3}/tests/test_updates.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codetta
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.3
|
|
4
4
|
Summary: A private, self-hosted music library manager: tags, MusicBrainz matching, batch editing and organizing, in your browser
|
|
5
5
|
Author: Gavin Griggs
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -31,8 +31,8 @@ Dynamic: license-file
|
|
|
31
31
|
|
|
32
32
|
<p align="center">
|
|
33
33
|
<picture>
|
|
34
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/
|
|
35
|
-
<img src="docs/
|
|
34
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/media/hero-dark.gif">
|
|
35
|
+
<img src="docs/media/hero-light.gif" alt="Codetta: your music library, looked after. Fix tags, match albums on MusicBrainz and organize your files, from any browser." width="900">
|
|
36
36
|
</picture>
|
|
37
37
|
</p>
|
|
38
38
|
|
|
@@ -44,7 +44,7 @@ Dynamic: license-file
|
|
|
44
44
|
|
|
45
45
|
<p align="center">
|
|
46
46
|
<img alt="Status: alpha" src="https://img.shields.io/badge/status-alpha-f59e0b">
|
|
47
|
-
<img alt="Version 0.8.
|
|
47
|
+
<img alt="Version 0.8.3" src="https://img.shields.io/badge/version-0.8.3-0e7c74">
|
|
48
48
|
<a href="LICENSE"><img alt="License: AGPL-3.0" src="https://img.shields.io/badge/license-AGPL--3.0-555"></a>
|
|
49
49
|
<img alt="Python 3.14" src="https://img.shields.io/badge/python-3.14-3776ab">
|
|
50
50
|
<a href="https://github.com/gavndev/codetta/actions/workflows/ci.yml"><img alt="Tests" src="https://github.com/gavndev/codetta/actions/workflows/ci.yml/badge.svg"></a>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/
|
|
4
|
-
<img src="docs/
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/media/hero-dark.gif">
|
|
4
|
+
<img src="docs/media/hero-light.gif" alt="Codetta: your music library, looked after. Fix tags, match albums on MusicBrainz and organize your files, from any browser." width="900">
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<img alt="Status: alpha" src="https://img.shields.io/badge/status-alpha-f59e0b">
|
|
16
|
-
<img alt="Version 0.8.
|
|
16
|
+
<img alt="Version 0.8.3" src="https://img.shields.io/badge/version-0.8.3-0e7c74">
|
|
17
17
|
<a href="LICENSE"><img alt="License: AGPL-3.0" src="https://img.shields.io/badge/license-AGPL--3.0-555"></a>
|
|
18
18
|
<img alt="Python 3.14" src="https://img.shields.io/badge/python-3.14-3776ab">
|
|
19
19
|
<a href="https://github.com/gavndev/codetta/actions/workflows/ci.yml"><img alt="Tests" src="https://github.com/gavndev/codetta/actions/workflows/ci.yml/badge.svg"></a>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "codetta"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.3"
|
|
8
8
|
description = "A private, self-hosted music library manager: tags, MusicBrainz matching, batch editing and organizing, in your browser"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Gavin Griggs" }]
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Codetta. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.8.3 (2026-11-19)
|
|
6
|
+
|
|
7
|
+
(0.8.2 was tagged but never released: our tests caught the Library health bug below just in time.)
|
|
8
|
+
|
|
9
|
+
- **Snap:** `sudo snap install codetta` on Ubuntu and other Linux systems, for Intel/AMD and ARM. It updates itself. See [On your own computer](docs/install.md#on-your-own-computer).
|
|
10
|
+
- **MusicBrainz, more patient:** when it's busy or slow, Codetta now waits longer (20 seconds instead of 8), tries up to three times with a growing pause, and waits as long as MusicBrainz asks. Fewer "busy" and "couldn't reach" errors.
|
|
11
|
+
- **Fixed:** Library health said every album "isn't matched on MusicBrainz yet", even matched ones. Your search index is rebuilt once after updating so it can tell them apart.
|
|
12
|
+
- **Fixed:** right after Codetta first reads your library, Library health could briefly show an incomplete list from part-way through. It now waits for the full answer.
|
|
13
|
+
- New screenshots and an animated README header, with real albums.
|
|
14
|
+
|
|
5
15
|
## 0.8.1 (2026-11-19)
|
|
6
16
|
|
|
7
17
|
- **Run it on your own computer:** no server or Docker needed. `pipx install codetta`, then `codetta` opens your Music folder in the browser (Linux and macOS; Windows support is coming). `codetta set-password` and `codetta sign-out-all` work there too. See [On your own computer](docs/install.md#on-your-own-computer).
|
|
@@ -35,10 +35,12 @@ def default_config_dir() -> Path:
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
def default_music_dir() -> Path:
|
|
38
|
+
# In a snap, HOME is the snap's own folder (~/snap/codetta/<n>): the real one is SNAP_REAL_HOME.
|
|
39
|
+
home = Path(os.environ.get("SNAP_REAL_HOME") or Path.home())
|
|
38
40
|
for name in ("Music", "music"):
|
|
39
|
-
if (
|
|
40
|
-
return
|
|
41
|
-
return
|
|
41
|
+
if (home / name).is_dir():
|
|
42
|
+
return home / name
|
|
43
|
+
return home / "Music"
|
|
42
44
|
|
|
43
45
|
|
|
44
46
|
def _free(host: str, port: int) -> bool:
|
|
@@ -48,7 +48,7 @@ from codetta.core.tagmap import FIELDS
|
|
|
48
48
|
|
|
49
49
|
log = logging.getLogger("codetta.index")
|
|
50
50
|
|
|
51
|
-
SCHEMA_VERSION =
|
|
51
|
+
SCHEMA_VERSION = 5 # 4: a stored natural sort key per file; 5: keeps musicbrainz_albumid (Library health)
|
|
52
52
|
RESCAN_SECONDS = 15 * 60 # a search re-checks the library if the last scan is older than this
|
|
53
53
|
BATCH = 200 # files per database transaction while scanning
|
|
54
54
|
PAR_CHUNK = 128 # files per job when worker processes help with a big scan
|
|
@@ -58,8 +58,9 @@ MAX_QUERY_CHARS = 500
|
|
|
58
58
|
# Tags searched by plain words (no "key:").
|
|
59
59
|
FREE_TEXT_KEYS = ("title", "artist", "album", "albumartist")
|
|
60
60
|
|
|
61
|
-
# Not worth searching, and often large: fingerprints, IDs, loudness data.
|
|
62
|
-
|
|
61
|
+
# Not worth searching, and often large: fingerprints, IDs, loudness data. The MusicBrainz
|
|
62
|
+
# album ID stays: Library health tells matched albums from unmatched ones by it.
|
|
63
|
+
_SKIP_KEY = re.compile(r"^(lyrics$|unsyncedlyrics$|acoustid_|musicbrainz_(?!albumid$)|replaygain_|itunnorm|itunsmpb|isrc$|barcode$|tidal_|spotify_|discogs_|deezer_|qobuz_|.*_id$|.*fingerprint)")
|
|
63
64
|
# Searchable, but not worth an index entry: sort names and credits repeat the real names.
|
|
64
65
|
_DUPLICATE_KEY = re.compile(r"^(.*sort|.*_credit|.*sortorder)$")
|
|
65
66
|
MAX_INDEXED_VALUE = 300 # longer values (lyrics, essays in comments) aren't searchable
|
|
@@ -159,6 +159,9 @@ def credit_ids(credits: list | None) -> list[str]:
|
|
|
159
159
|
# --- The client -------------------------------------------------------------------------
|
|
160
160
|
|
|
161
161
|
Fetcher = Callable[[str], object] # url -> parsed JSON, or None for 404
|
|
162
|
+
RETRY_WAITS = (2.0, 4.0) # seconds before the 2nd and 3rd try when MusicBrainz is busy or slow
|
|
163
|
+
MAX_RETRY_WAIT = 15.0 # never wait longer than this for one "Retry-After"
|
|
164
|
+
MB_TIMEOUT = 20 # big releases with credits can take MusicBrainz well over 8 seconds
|
|
162
165
|
|
|
163
166
|
|
|
164
167
|
class MusicBrainz:
|
|
@@ -180,7 +183,7 @@ class MusicBrainz:
|
|
|
180
183
|
self._cache.move_to_end(url)
|
|
181
184
|
return self._cache[url]
|
|
182
185
|
with self._rate_lock: # one request at a time, at most one per min_interval
|
|
183
|
-
for attempt in (1, 2):
|
|
186
|
+
for attempt in range(1, len(RETRY_WAITS) + 2):
|
|
184
187
|
wait = self._last + self.min_interval - self._clock()
|
|
185
188
|
if wait > 0:
|
|
186
189
|
self._sleep(wait)
|
|
@@ -188,10 +191,12 @@ class MusicBrainz:
|
|
|
188
191
|
data = self.fetch(url)
|
|
189
192
|
break
|
|
190
193
|
except ProviderError as exc:
|
|
191
|
-
#
|
|
192
|
-
|
|
194
|
+
# Busy (503/429), timed out or dropped: MusicBrainz is often briefly overloaded.
|
|
195
|
+
# Back off (as long as it asks, within reason) and try again, a few times.
|
|
196
|
+
if not getattr(exc, "transient", False) or attempt > len(RETRY_WAITS):
|
|
193
197
|
raise
|
|
194
|
-
|
|
198
|
+
asked = getattr(exc, "retry_after", None)
|
|
199
|
+
self._sleep(min(MAX_RETRY_WAIT, asked) if asked else RETRY_WAITS[attempt - 1])
|
|
195
200
|
finally:
|
|
196
201
|
self._last = self._clock()
|
|
197
202
|
with self._cache_lock:
|
|
@@ -26,7 +26,22 @@ TIMEOUT = 8
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
class ProviderError(Exception):
|
|
29
|
-
"""The provider couldn't be reached or answered with something unusable.
|
|
29
|
+
"""The provider couldn't be reached or answered with something unusable.
|
|
30
|
+
|
|
31
|
+
``transient``: worth trying again shortly (busy, timed out, connection dropped);
|
|
32
|
+
``retry_after``: seconds the service asked us to wait, if it said."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, message: str, *, transient: bool = False, retry_after: float | None = None) -> None:
|
|
35
|
+
super().__init__(message)
|
|
36
|
+
self.transient = transient
|
|
37
|
+
self.retry_after = retry_after
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _retry_after(exc: urllib.error.HTTPError) -> float | None:
|
|
41
|
+
try:
|
|
42
|
+
return max(0.0, float(exc.headers.get("Retry-After", "")))
|
|
43
|
+
except (TypeError, ValueError, AttributeError):
|
|
44
|
+
return None # missing, or an HTTP date (not worth parsing: we cap the wait anyway)
|
|
30
45
|
|
|
31
46
|
|
|
32
47
|
@dataclass
|
|
@@ -70,7 +85,7 @@ _opener = urllib.request.build_opener(_HttpsOnlyRedirects)
|
|
|
70
85
|
|
|
71
86
|
|
|
72
87
|
def http_get(url: str, user_agent: str, *, accept: str = "application/json", max_bytes: int = MAX_RESPONSE_BYTES,
|
|
73
|
-
service: str = "the lyrics service", allow_http: bool = False) -> bytes | None:
|
|
88
|
+
service: str = "the lyrics service", allow_http: bool = False, timeout: float = TIMEOUT) -> bytes | None:
|
|
74
89
|
"""GET a provider URL, size- and time-limited. None means 404 (not found).
|
|
75
90
|
|
|
76
91
|
Only https, unless ``allow_http`` (a self-hosted mirror the admin set up)."""
|
|
@@ -78,16 +93,17 @@ def http_get(url: str, user_agent: str, *, accept: str = "application/json", max
|
|
|
78
93
|
raise ProviderError("Providers must use https")
|
|
79
94
|
req = urllib.request.Request(url, headers={"User-Agent": user_agent, "Accept": accept})
|
|
80
95
|
try:
|
|
81
|
-
with _opener.open(req, timeout=
|
|
96
|
+
with _opener.open(req, timeout=timeout) as res: # nosec B310: http(s) only, fixed provider hosts
|
|
82
97
|
data = res.read(max_bytes + 1)
|
|
83
98
|
except urllib.error.HTTPError as exc:
|
|
84
99
|
if exc.code == 404:
|
|
85
100
|
return None
|
|
86
|
-
if exc.code in (429, 503):
|
|
87
|
-
raise ProviderError(f"{service.capitalize()} is busy right now. Try again in a moment."
|
|
101
|
+
if exc.code in (429, 502, 503, 504):
|
|
102
|
+
raise ProviderError(f"{service.capitalize()} is busy right now. Try again in a moment.",
|
|
103
|
+
transient=True, retry_after=_retry_after(exc)) from exc
|
|
88
104
|
raise ProviderError(f"{service.capitalize()} answered with an error ({exc.code})") from exc
|
|
89
105
|
except (urllib.error.URLError, TimeoutError, OSError) as exc:
|
|
90
|
-
raise ProviderError(f"Couldn't reach {service}. Is the server online?") from exc
|
|
106
|
+
raise ProviderError(f"Couldn't reach {service}. Is the server online?", transient=True) from exc
|
|
91
107
|
if len(data) > max_bytes:
|
|
92
108
|
raise ProviderError(f"{service.capitalize()} sent an unexpectedly large answer")
|
|
93
109
|
return data
|
|
@@ -127,9 +143,9 @@ def http_post_json(url: str, user_agent: str, form: dict[str, str], *, service:
|
|
|
127
143
|
|
|
128
144
|
|
|
129
145
|
def http_get_json(url: str, user_agent: str, *, max_bytes: int = MAX_RESPONSE_BYTES,
|
|
130
|
-
service: str = "the lyrics service", allow_http: bool = False) -> object:
|
|
146
|
+
service: str = "the lyrics service", allow_http: bool = False, timeout: float = TIMEOUT) -> object:
|
|
131
147
|
"""GET a JSON document (None for 404)."""
|
|
132
|
-
data = http_get(url, user_agent, max_bytes=max_bytes, service=service, allow_http=allow_http)
|
|
148
|
+
data = http_get(url, user_agent, max_bytes=max_bytes, service=service, allow_http=allow_http, timeout=timeout)
|
|
133
149
|
if data is None:
|
|
134
150
|
return None
|
|
135
151
|
try:
|
|
@@ -126,6 +126,7 @@ from codetta.core.musicbrainz import (
|
|
|
126
126
|
ID_LABELS as MB_ID_LABELS,
|
|
127
127
|
MAX_MB_BYTES,
|
|
128
128
|
MB_BASE,
|
|
129
|
+
MB_TIMEOUT,
|
|
129
130
|
MBID_RE,
|
|
130
131
|
DEFAULT_OFF as MB_DEFAULT_OFF,
|
|
131
132
|
FileInfo,
|
|
@@ -562,7 +563,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
562
563
|
mb_mirror += "/ws/2"
|
|
563
564
|
mb = MusicBrainz(
|
|
564
565
|
fetch_mb or (lambda url: http_get_json(url, user_agent, max_bytes=MAX_MB_BYTES, service="MusicBrainz",
|
|
565
|
-
allow_http=mb_mirror is not None)),
|
|
566
|
+
allow_http=mb_mirror is not None, timeout=MB_TIMEOUT)),
|
|
566
567
|
base=mb_mirror or MB_BASE,
|
|
567
568
|
min_interval=0 if mb_mirror else 1.0, # musicbrainz.org allows one request a second
|
|
568
569
|
)
|
|
@@ -2313,7 +2314,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2313
2314
|
# --- Library health -------------------------------------------------------------------------
|
|
2314
2315
|
|
|
2315
2316
|
health_store = HealthStore(settings.config_dir / "health.json")
|
|
2316
|
-
health_cache: dict = {"key": None, "data": None, "at": 0.0, "fixed": {}}
|
|
2317
|
+
health_cache: dict = {"key": None, "data": None, "at": 0.0, "fixed": {}, "complete": False}
|
|
2317
2318
|
health_lock = threading.Lock()
|
|
2318
2319
|
|
|
2319
2320
|
health_compute_lock = threading.Lock()
|
|
@@ -2322,12 +2323,13 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2322
2323
|
def health_compute() -> None:
|
|
2323
2324
|
with health_compute_lock:
|
|
2324
2325
|
key = lib_index.version
|
|
2326
|
+
complete = lib_index.status().ready # made from the whole library, not mid-way through the first scan
|
|
2325
2327
|
inbox_folder = inbox.settings.folder
|
|
2326
2328
|
skip = [inbox_folder] if inbox_folder and not inbox_folder.startswith("@") else []
|
|
2327
2329
|
data = health_run(lib_index.iter_tracks(), folder_has_image(library.resolve),
|
|
2328
2330
|
lib_index.paths_with_any(MB_RELEASE_KEYS), skip)
|
|
2329
2331
|
with health_lock:
|
|
2330
|
-
health_cache.update(data=data, key=key, at=time.time())
|
|
2332
|
+
health_cache.update(data=data, key=key, at=time.time(), complete=complete)
|
|
2331
2333
|
|
|
2332
2334
|
def health_data() -> dict:
|
|
2333
2335
|
"""Every issue. The first check waits for the answer; after that, a change to the library
|
|
@@ -2336,7 +2338,8 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2336
2338
|
with health_lock:
|
|
2337
2339
|
data = health_cache["data"]
|
|
2338
2340
|
stale = health_cache["key"] != lib_index.version or time.time() - health_cache["at"] > 600
|
|
2339
|
-
|
|
2341
|
+
partial = not health_cache["complete"] and lib_index.status().ready
|
|
2342
|
+
if data is None or partial: # never show an answer from half a library once the whole one is read
|
|
2340
2343
|
health_compute()
|
|
2341
2344
|
elif stale and not (health_worker["thread"] and health_worker["thread"].is_alive()):
|
|
2342
2345
|
health_worker["thread"] = threading.Thread(target=health_compute, name="codetta-health", daemon=True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codetta
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.3
|
|
4
4
|
Summary: A private, self-hosted music library manager: tags, MusicBrainz matching, batch editing and organizing, in your browser
|
|
5
5
|
Author: Gavin Griggs
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -31,8 +31,8 @@ Dynamic: license-file
|
|
|
31
31
|
|
|
32
32
|
<p align="center">
|
|
33
33
|
<picture>
|
|
34
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/
|
|
35
|
-
<img src="docs/
|
|
34
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/media/hero-dark.gif">
|
|
35
|
+
<img src="docs/media/hero-light.gif" alt="Codetta: your music library, looked after. Fix tags, match albums on MusicBrainz and organize your files, from any browser." width="900">
|
|
36
36
|
</picture>
|
|
37
37
|
</p>
|
|
38
38
|
|
|
@@ -44,7 +44,7 @@ Dynamic: license-file
|
|
|
44
44
|
|
|
45
45
|
<p align="center">
|
|
46
46
|
<img alt="Status: alpha" src="https://img.shields.io/badge/status-alpha-f59e0b">
|
|
47
|
-
<img alt="Version 0.8.
|
|
47
|
+
<img alt="Version 0.8.3" src="https://img.shields.io/badge/version-0.8.3-0e7c74">
|
|
48
48
|
<a href="LICENSE"><img alt="License: AGPL-3.0" src="https://img.shields.io/badge/license-AGPL--3.0-555"></a>
|
|
49
49
|
<img alt="Python 3.14" src="https://img.shields.io/badge/python-3.14-3776ab">
|
|
50
50
|
<a href="https://github.com/gavndev/codetta/actions/workflows/ci.yml"><img alt="Tests" src="https://github.com/gavndev/codetta/actions/workflows/ci.yml/badge.svg"></a>
|
|
@@ -76,6 +76,15 @@ def test_config_folder_per_system(monkeypatch, tmp_path):
|
|
|
76
76
|
assert run.default_config_dir() == tmp_path / "snap" / "config"
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
def test_music_folder_in_a_snap_is_the_real_home(monkeypatch, tmp_path):
|
|
80
|
+
(tmp_path / "real" / "Music").mkdir(parents=True)
|
|
81
|
+
monkeypatch.setattr(run.Path, "home", lambda: tmp_path / "snap" / "codetta" / "12")
|
|
82
|
+
monkeypatch.setenv("SNAP_REAL_HOME", str(tmp_path / "real"))
|
|
83
|
+
assert run.default_music_dir() == tmp_path / "real" / "Music"
|
|
84
|
+
monkeypatch.delenv("SNAP_REAL_HOME")
|
|
85
|
+
assert run.default_music_dir() == tmp_path / "snap" / "codetta" / "12" / "Music"
|
|
86
|
+
|
|
87
|
+
|
|
79
88
|
def test_admin_commands_use_the_same_config_folder(monkeypatch, tmp_path):
|
|
80
89
|
seen = []
|
|
81
90
|
import codetta.cli.__main__ as admin
|
|
@@ -128,7 +128,7 @@ def test_explore_needs_the_musicbrainz_connection_and_valid_ids(client):
|
|
|
128
128
|
assert c.get("/api/musicbrainz/cover/" + RG1, params={"kind": "nope"}).status_code in (403, 422)
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
def
|
|
131
|
+
def test_busy_musicbrainz_is_retried():
|
|
132
132
|
from codetta.core.musicbrainz import MusicBrainz
|
|
133
133
|
from codetta.core.providers import ProviderError
|
|
134
134
|
calls, slept = [], []
|
|
@@ -136,11 +136,12 @@ def test_busy_musicbrainz_is_retried_once():
|
|
|
136
136
|
def fetch(url):
|
|
137
137
|
calls.append(url)
|
|
138
138
|
if len(calls) == 1:
|
|
139
|
-
raise ProviderError("MusicBrainz is busy right now. Try again in a moment.")
|
|
139
|
+
raise ProviderError("MusicBrainz is busy right now. Try again in a moment.", transient=True)
|
|
140
140
|
return {"artists": []}
|
|
141
141
|
|
|
142
142
|
mb = MusicBrainz(fetch, min_interval=1.0, sleep=slept.append)
|
|
143
|
-
assert mb.search_artists("x") == [] and len(calls) == 2 and
|
|
144
|
-
always = MusicBrainz(lambda url: (_ for _ in ()).throw(ProviderError("MusicBrainz is busy right now."
|
|
143
|
+
assert mb.search_artists("x") == [] and len(calls) == 2 and 2.0 in slept
|
|
144
|
+
always = MusicBrainz(lambda url: (_ for _ in ()).throw(ProviderError("MusicBrainz is busy right now.", transient=True)),
|
|
145
|
+
sleep=lambda s: None)
|
|
145
146
|
with pytest.raises(ProviderError):
|
|
146
147
|
always.search_artists("y")
|
|
@@ -77,6 +77,18 @@ def make_index(root, tmp_path, engine):
|
|
|
77
77
|
return LibraryIndex(root, tmp_path / "config" / "library-index.sqlite3", describe)
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
def test_musicbrainz_album_id_is_kept_for_library_health(library, tmp_path):
|
|
81
|
+
# Library health counts albums "not matched on MusicBrainz yet" from the index: the album
|
|
82
|
+
# ID must be there (other IDs are still left out, to keep the index small).
|
|
83
|
+
root, add, engine = library
|
|
84
|
+
add("Drake/Views/01 - Keep the Family Close.flac", title="Keep the Family Close", artist="Drake",
|
|
85
|
+
musicbrainz_albumid="11111111-1111-4111-8111-111111111111", musicbrainz_trackid="22222222-2222-4222-8222-222222222222")
|
|
86
|
+
idx = make_index(root, tmp_path, engine)
|
|
87
|
+
idx.scan()
|
|
88
|
+
assert idx.paths_with_any(("musicbrainz_albumid",)) == {"Drake/Views/01 - Keep the Family Close.flac"}
|
|
89
|
+
assert not idx.has_key("musicbrainz_trackid")
|
|
90
|
+
|
|
91
|
+
|
|
80
92
|
def titles(tracks):
|
|
81
93
|
return [t["tags"]["title"][0] for t in tracks]
|
|
82
94
|
|
|
@@ -230,13 +242,13 @@ def test_technical_and_long_tags_are_not_indexed_but_editor_gets_them(library, t
|
|
|
230
242
|
root, add, engine = library
|
|
231
243
|
big = "AQAD" + "x" * 3000
|
|
232
244
|
add("Big/01 - Big.flac", title="Big", artist="Somebody", acoustid_fingerprint=big,
|
|
233
|
-
|
|
245
|
+
musicbrainz_trackid="4f0c3a8e-0000-4000-8000-000000000000", lyrics="la " * 2000)
|
|
234
246
|
idx = make_index(root, tmp_path, engine)
|
|
235
247
|
idx.scan()
|
|
236
248
|
tracks, _ = idx.search(parse_query("artist: somebody"))
|
|
237
249
|
t = tracks[0]
|
|
238
250
|
assert t["partial"] is True
|
|
239
|
-
assert "acoustid_fingerprint" not in t["tags"] and "
|
|
251
|
+
assert "acoustid_fingerprint" not in t["tags"] and "musicbrainz_trackid" not in t["tags"]
|
|
240
252
|
assert "lyrics" not in t["tags"] # too long to store; the editor reloads it from the file
|
|
241
253
|
assert idx.search(parse_query("acoustid_fingerprint: aqad"))[1] == 0
|
|
242
254
|
|
|
@@ -212,6 +212,44 @@ def test_rate_limit_and_cache():
|
|
|
212
212
|
assert len(fake.urls) == 2 # the second lookup came from the cache
|
|
213
213
|
|
|
214
214
|
|
|
215
|
+
def test_busy_or_slow_musicbrainz_is_retried_with_backoff():
|
|
216
|
+
now = [100.0]
|
|
217
|
+
slept = []
|
|
218
|
+
answers = [ProviderError("MusicBrainz is busy right now.", transient=True),
|
|
219
|
+
ProviderError("Couldn't reach MusicBrainz.", transient=True, retry_after=60), ALBUM]
|
|
220
|
+
|
|
221
|
+
def flaky(url):
|
|
222
|
+
a = answers.pop(0)
|
|
223
|
+
if isinstance(a, Exception):
|
|
224
|
+
raise a
|
|
225
|
+
return a
|
|
226
|
+
|
|
227
|
+
mb = MusicBrainz(flaky, clock=lambda: now[0], sleep=lambda s: (slept.append(s), now.__setitem__(0, now[0] + s)))
|
|
228
|
+
assert mb.release(REL)["id"] == REL
|
|
229
|
+
assert 2.0 in slept # the first back-off
|
|
230
|
+
assert 15.0 in slept and 60 not in slept # "Retry-After: 60" honoured, but capped
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def test_musicbrainz_gives_up_after_three_tries_and_never_retries_real_errors():
|
|
234
|
+
calls = []
|
|
235
|
+
|
|
236
|
+
def always(exc):
|
|
237
|
+
def fetch(url):
|
|
238
|
+
calls.append(url)
|
|
239
|
+
raise exc
|
|
240
|
+
return fetch
|
|
241
|
+
|
|
242
|
+
mb = MusicBrainz(always(ProviderError("busy", transient=True)), sleep=lambda s: None)
|
|
243
|
+
with pytest.raises(ProviderError):
|
|
244
|
+
mb.release(REL)
|
|
245
|
+
assert len(calls) == 3
|
|
246
|
+
calls.clear()
|
|
247
|
+
mb = MusicBrainz(always(ProviderError("answered with an error (400)")), sleep=lambda s: None)
|
|
248
|
+
with pytest.raises(ProviderError):
|
|
249
|
+
mb.release(REL)
|
|
250
|
+
assert len(calls) == 1
|
|
251
|
+
|
|
252
|
+
|
|
215
253
|
def test_search_query_is_escaped():
|
|
216
254
|
fake = FakeMB()
|
|
217
255
|
MusicBrainz(fake, min_interval=0).search('AC/DC: "Live"', "Guns N' Roses")
|
|
@@ -117,3 +117,37 @@ def test_lookup_can_be_turned_off(client_for):
|
|
|
117
117
|
assert c.get("/api/lyrics/lookup", params={"path": "a.flac"}).status_code == 403
|
|
118
118
|
assert c.get("/api/status").json()["lyrics_lookup"] is False
|
|
119
119
|
assert svc.urls == [] # nothing was sent anywhere
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_busy_and_unreachable_answers_are_marked_worth_retrying(monkeypatch):
|
|
123
|
+
import email.message
|
|
124
|
+
import urllib.error
|
|
125
|
+
|
|
126
|
+
from codetta.core import providers
|
|
127
|
+
|
|
128
|
+
def busy(req, timeout):
|
|
129
|
+
assert timeout == 20 # the caller's timeout is used
|
|
130
|
+
headers = email.message.Message()
|
|
131
|
+
headers["Retry-After"] = "3"
|
|
132
|
+
raise urllib.error.HTTPError(req.full_url, 503, "busy", headers, None)
|
|
133
|
+
|
|
134
|
+
monkeypatch.setattr(providers._opener, "open", busy)
|
|
135
|
+
with pytest.raises(ProviderError) as err:
|
|
136
|
+
providers.http_get("https://musicbrainz.org/ws/2/x", "UA", service="MusicBrainz", timeout=20)
|
|
137
|
+
assert err.value.transient and err.value.retry_after == 3.0
|
|
138
|
+
|
|
139
|
+
def bad_request(req, timeout):
|
|
140
|
+
raise urllib.error.HTTPError(req.full_url, 400, "bad", email.message.Message(), None)
|
|
141
|
+
|
|
142
|
+
monkeypatch.setattr(providers._opener, "open", bad_request)
|
|
143
|
+
with pytest.raises(ProviderError) as err:
|
|
144
|
+
providers.http_get("https://musicbrainz.org/ws/2/x", "UA", service="MusicBrainz")
|
|
145
|
+
assert not err.value.transient
|
|
146
|
+
|
|
147
|
+
def down(req, timeout):
|
|
148
|
+
raise TimeoutError("timed out")
|
|
149
|
+
|
|
150
|
+
monkeypatch.setattr(providers._opener, "open", down)
|
|
151
|
+
with pytest.raises(ProviderError) as err:
|
|
152
|
+
providers.http_get("https://musicbrainz.org/ws/2/x", "UA", service="MusicBrainz")
|
|
153
|
+
assert err.value.transient and err.value.retry_after is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|