codetta 0.8.1__tar.gz → 0.8.4__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.4}/PKG-INFO +15 -15
- {codetta-0.8.1 → codetta-0.8.4}/README.md +13 -13
- {codetta-0.8.1 → codetta-0.8.4}/pyproject.toml +2 -2
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/CHANGELOG.md +27 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/cli/run.py +5 -3
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/engine.py +16 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/index.py +22 -4
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/musicbrainz.py +9 -4
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/organize.py +27 -2
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/presets.py +1 -1
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/providers.py +24 -8
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/app.py +67 -8
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/app.css +77 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/app.js +75 -21
- {codetta-0.8.1 → codetta-0.8.4/src/codetta.egg-info}/PKG-INFO +15 -15
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_cli_run.py +9 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_explore.py +5 -4
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_inbox.py +22 -2
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_index.py +39 -2
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_musicbrainz.py +38 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_providers.py +34 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_safety.py +76 -0
- {codetta-0.8.1 → codetta-0.8.4}/LICENSE +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/setup.cfg +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/__main__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/cli/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/cli/__main__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/acoustid.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/activity.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/artwork.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/auth.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/avatar.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/changelog.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/connections.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/describe.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/health.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/inbox.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/library.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/notifications.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/onboarding.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/plugins.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/rawtags.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/slskd.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/tagmap.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/undo.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/core/updates.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/plugins/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/plugins/builtin/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/plugins/builtin/tidy.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/__init__.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/security.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/apple-touch-icon.png +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/fonts/LICENSE-Inter.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/fonts/LICENSE-SchibstedGrotesk.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/fonts/inter-cyrillic.woff2 +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/fonts/schibsted-grotesk.woff2 +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icon.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-dark.png +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-dark.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-dark.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-light.png +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-light.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta-light.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta.png +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta.svg +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/icons/codetta.webp +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/index.html +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta/web/static/theme.js +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta.egg-info/SOURCES.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta.egg-info/dependency_links.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta.egg-info/entry_points.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta.egg-info/requires.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/src/codetta.egg-info/top_level.txt +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_acoustid.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_api.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_artwork.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_attacks.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_auth.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_avatar.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_connections.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_efficiency.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_engine.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_health.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_organize.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_plugins.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_presets.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_privacy.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_rawtags.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_security.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_slskd.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_soulseek_api.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_undo.py +0 -0
- {codetta-0.8.1 → codetta-0.8.4}/tests/test_updates.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codetta
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.4
|
|
4
4
|
Summary: A private, self-hosted music library manager: tags, MusicBrainz matching, batch editing and organizing, in your browser
|
|
5
|
-
Author:
|
|
5
|
+
Author: gavndev
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
7
7
|
Project-URL: Homepage, https://github.com/gavndev/codetta
|
|
8
8
|
Project-URL: Documentation, https://github.com/gavndev/codetta/tree/main/docs
|
|
@@ -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.4" src="https://img.shields.io/badge/version-0.8.4-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>
|
|
@@ -53,7 +53,10 @@ Dynamic: license-file
|
|
|
53
53
|
</p>
|
|
54
54
|
|
|
55
55
|
<p align="center">
|
|
56
|
-
<
|
|
56
|
+
<picture>
|
|
57
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/media/hero-dark.gif">
|
|
58
|
+
<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">
|
|
59
|
+
</picture>
|
|
57
60
|
</p>
|
|
58
61
|
|
|
59
62
|
<p align="center">
|
|
@@ -112,8 +115,8 @@ Runs on Intel/AMD and ARM, from a Raspberry Pi 4 up: about a 100 MB download
|
|
|
112
115
|
and 70 MB of memory (about 130 MB at 100,000 tracks), and no disk activity when idle. The
|
|
113
116
|
[install guide](docs/install.md) walks through every step, including updates.
|
|
114
117
|
|
|
115
|
-
No server? Run it on your own computer instead:
|
|
116
|
-
`
|
|
118
|
+
No server? Run it on your own computer instead: `pipx install codetta`
|
|
119
|
+
(or `sudo snap install codetta` on Ubuntu), then `codetta`
|
|
117
120
|
([details](docs/install.md#on-your-own-computer)).
|
|
118
121
|
|
|
119
122
|
## What Codetta does
|
|
@@ -259,14 +262,10 @@ light and dark themes. [See every feature →](docs/features.md)
|
|
|
259
262
|
|
|
260
263
|
## What's new
|
|
261
264
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
listen with a now-playing pill, multi-disc albums, setup steps, What's new and
|
|
267
|
-
notifications.
|
|
268
|
-
**0.4.0:** offline unless you opt in; Match on MusicBrainz and identify by
|
|
269
|
-
sound with AcoustID. All changes are in the [changelog](CHANGELOG.md).
|
|
265
|
+
Every change is in the [changelog](CHANGELOG.md); each version's notes are also on
|
|
266
|
+
[GitHub Releases](https://github.com/gavndev/codetta/releases). Inside Codetta,
|
|
267
|
+
**What's new** (in the account menu, or the link in the footer) shows the same notes for the
|
|
268
|
+
version you're running.
|
|
270
269
|
|
|
271
270
|
## License
|
|
272
271
|
|
|
@@ -279,4 +278,5 @@ Built with [mutagen](https://github.com/quodlibet/mutagen),
|
|
|
279
278
|
[Schibsted Grotesk](https://github.com/schibsted/schibsted-grotesk) typeface.
|
|
280
279
|
Tag mappings follow [MusicBrainz Picard](https://picard.musicbrainz.org/docs/mappings/).
|
|
281
280
|
The optional Soulseek integration talks to [slskd](https://github.com/slskd/slskd) over its API.
|
|
282
|
-
The
|
|
281
|
+
The header and screenshots show real releases for illustration (the covers belong to their
|
|
282
|
+
artists and labels; the audio files are silent stand-ins); the feature GIFs use made-up music.
|
|
@@ -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.4" src="https://img.shields.io/badge/version-0.8.4-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>
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
25
|
-
<
|
|
25
|
+
<picture>
|
|
26
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/media/hero-dark.gif">
|
|
27
|
+
<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">
|
|
28
|
+
</picture>
|
|
26
29
|
</p>
|
|
27
30
|
|
|
28
31
|
<p align="center">
|
|
@@ -81,8 +84,8 @@ Runs on Intel/AMD and ARM, from a Raspberry Pi 4 up: about a 100 MB download
|
|
|
81
84
|
and 70 MB of memory (about 130 MB at 100,000 tracks), and no disk activity when idle. The
|
|
82
85
|
[install guide](docs/install.md) walks through every step, including updates.
|
|
83
86
|
|
|
84
|
-
No server? Run it on your own computer instead:
|
|
85
|
-
`
|
|
87
|
+
No server? Run it on your own computer instead: `pipx install codetta`
|
|
88
|
+
(or `sudo snap install codetta` on Ubuntu), then `codetta`
|
|
86
89
|
([details](docs/install.md#on-your-own-computer)).
|
|
87
90
|
|
|
88
91
|
## What Codetta does
|
|
@@ -228,14 +231,10 @@ light and dark themes. [See every feature →](docs/features.md)
|
|
|
228
231
|
|
|
229
232
|
## What's new
|
|
230
233
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
listen with a now-playing pill, multi-disc albums, setup steps, What's new and
|
|
236
|
-
notifications.
|
|
237
|
-
**0.4.0:** offline unless you opt in; Match on MusicBrainz and identify by
|
|
238
|
-
sound with AcoustID. All changes are in the [changelog](CHANGELOG.md).
|
|
234
|
+
Every change is in the [changelog](CHANGELOG.md); each version's notes are also on
|
|
235
|
+
[GitHub Releases](https://github.com/gavndev/codetta/releases). Inside Codetta,
|
|
236
|
+
**What's new** (in the account menu, or the link in the footer) shows the same notes for the
|
|
237
|
+
version you're running.
|
|
239
238
|
|
|
240
239
|
## License
|
|
241
240
|
|
|
@@ -248,4 +247,5 @@ Built with [mutagen](https://github.com/quodlibet/mutagen),
|
|
|
248
247
|
[Schibsted Grotesk](https://github.com/schibsted/schibsted-grotesk) typeface.
|
|
249
248
|
Tag mappings follow [MusicBrainz Picard](https://picard.musicbrainz.org/docs/mappings/).
|
|
250
249
|
The optional Soulseek integration talks to [slskd](https://github.com/slskd/slskd) over its API.
|
|
251
|
-
The
|
|
250
|
+
The header and screenshots show real releases for illustration (the covers belong to their
|
|
251
|
+
artists and labels; the audio files are silent stand-ins); the feature GIFs use made-up music.
|
|
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "codetta"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.4"
|
|
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
|
-
authors = [{ name = "
|
|
10
|
+
authors = [{ name = "gavndev" }]
|
|
11
11
|
keywords = ["music", "tags", "tagger", "metadata", "musicbrainz", "flac", "id3", "self-hosted", "library", "organizer"]
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Development Status :: 4 - Beta",
|
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Codetta. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.8.4 (2026-11-19)
|
|
6
|
+
|
|
7
|
+
- **Covers in the grid view:** switch the Library to the grid and every folder shows the cover of an album inside it, artists included. Nothing extra is read from your disk: the covers come from the search index.
|
|
8
|
+
- **Easier to tap on phones:** every button, field and toggle is now at least 44 points tall, as Apple recommends. The search bar responds anywhere you tap it, not just on a thin strip in the middle.
|
|
9
|
+
- **Selecting tracks on a phone:** the bar at the bottom no longer runs off the screen. Preset, Replace and Actions now share a "…" menu next to Edit.
|
|
10
|
+
- **Safer moves:** Organize, Rename folder and the inbox now move a file in a way that can never replace another file that appears at the same name at the last moment (say, a download finishing). Very long file names also move between disks correctly now.
|
|
11
|
+
- **Saves survive power cuts better:** after a file is safely swapped in, its folder is flushed to disk too.
|
|
12
|
+
- **Fixed:** filing the same inbox album twice at once (a double tap, or "File all" while it was filing itself) could mark a successfully filed album as failed. A second request is now turned away.
|
|
13
|
+
- **Fixed:** a double tap on Undo could run the same undo twice, and undoing a move whose folder no longer exists showed a server error instead of saying why.
|
|
14
|
+
- **Fixed:** after saving, going back to a search or a grid could still show the old tags or cover until you reloaded.
|
|
15
|
+
- **Fixed:** a MusicBrainz match that saved the tags but not the cover left search and Library health showing the old tags.
|
|
16
|
+
- **Fixed:** pressing Ctrl/Cmd+S twice quickly saved everything twice (and logged it twice). A save already under way now just carries on.
|
|
17
|
+
- The "/" shortcut for search no longer jumps behind an open dialog.
|
|
18
|
+
- **Fixed:** applying a Tag Preset to a folder stopped part-way if one file couldn't be opened (say, a permissions problem), and the files it had already changed weren't in Activity, so they couldn't be undone. Now that one file is reported and the rest carry on, all undoable.
|
|
19
|
+
- **Library health's one-tap fixes** check the album again first if anything changed since the list was made.
|
|
20
|
+
- **What's new** shows its links properly (they opened as plain text before) and they now open on GitHub.
|
|
21
|
+
|
|
22
|
+
## 0.8.3 (2026-11-19)
|
|
23
|
+
|
|
24
|
+
(0.8.2 was tagged but never released: our tests caught the Library health bug below just in time.)
|
|
25
|
+
|
|
26
|
+
- **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).
|
|
27
|
+
- **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.
|
|
28
|
+
- **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.
|
|
29
|
+
- **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.
|
|
30
|
+
- New screenshots and an animated README header, with real albums.
|
|
31
|
+
|
|
5
32
|
## 0.8.1 (2026-11-19)
|
|
6
33
|
|
|
7
34
|
- **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:
|
|
@@ -306,6 +306,7 @@ class MetadataEngine:
|
|
|
306
306
|
# client still seeding it) keeps the original bytes.
|
|
307
307
|
os.replace(temp_path, target)
|
|
308
308
|
temp_path = None
|
|
309
|
+
_fsync_dir(target.parent) # and the new name too, so a power cut can't undo the swap
|
|
309
310
|
except OSError as exc:
|
|
310
311
|
raise MetadataError(f"Could not write to {path}: {exc}") from exc
|
|
311
312
|
finally:
|
|
@@ -459,6 +460,21 @@ def _normalize_value(value: TagValue) -> list[str]:
|
|
|
459
460
|
return [] if all(v == "" for v in values) else values
|
|
460
461
|
|
|
461
462
|
|
|
463
|
+
def _fsync_dir(folder: Path) -> None:
|
|
464
|
+
"""Flush a folder's entries (a rename) to disk. Best effort: not every system or
|
|
465
|
+
filesystem supports it (Windows, some network shares), and the data is already safe."""
|
|
466
|
+
try:
|
|
467
|
+
fd = os.open(folder, os.O_RDONLY | getattr(os, "O_DIRECTORY", 0))
|
|
468
|
+
except OSError:
|
|
469
|
+
return
|
|
470
|
+
try:
|
|
471
|
+
os.fsync(fd)
|
|
472
|
+
except OSError:
|
|
473
|
+
pass
|
|
474
|
+
finally:
|
|
475
|
+
os.close(fd)
|
|
476
|
+
|
|
477
|
+
|
|
462
478
|
def _copy_ownership(source: Path, dest: Path) -> None:
|
|
463
479
|
"""Give ``dest`` the same owner/group as ``source`` where permitted.
|
|
464
480
|
|
|
@@ -43,12 +43,12 @@ from dataclasses import dataclass, field
|
|
|
43
43
|
from pathlib import Path
|
|
44
44
|
|
|
45
45
|
from codetta.core.engine import SUPPORTED_EXTENSIONS
|
|
46
|
-
from codetta.core.library import _is_valid_text, _sort_text
|
|
46
|
+
from codetta.core.library import _is_valid_text, _sort_text
|
|
47
47
|
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
|
|
@@ -627,6 +628,23 @@ class LibraryIndex:
|
|
|
627
628
|
yield path, _unpack(blob)
|
|
628
629
|
last = rows[-1][0]
|
|
629
630
|
|
|
631
|
+
def cover_tracks(self, folders: Iterable[str], look: int = 30) -> dict[str, tuple[str, str]]:
|
|
632
|
+
"""For each folder, a track inside it (at any depth) that has embedded art:
|
|
633
|
+
folder -> (track path, art hash). Reads the index only (no file is opened); looks at the
|
|
634
|
+
first ``look`` tracks of each folder, so a huge folder never makes this slow."""
|
|
635
|
+
out: dict[str, tuple[str, str]] = {}
|
|
636
|
+
with self._lock:
|
|
637
|
+
for folder in folders:
|
|
638
|
+
lo, hi = (folder + "/", folder + "0") if folder else ("", "\U0010ffff") # "0" sorts right after "/"
|
|
639
|
+
rows = self.db.execute("SELECT path, track FROM files WHERE path >= ? AND path < ? ORDER BY path LIMIT ?",
|
|
640
|
+
(lo, hi, look)).fetchall()
|
|
641
|
+
for path, blob in rows:
|
|
642
|
+
art = _unpack(blob).get("art") or {}
|
|
643
|
+
if art.get("hash"):
|
|
644
|
+
out[folder] = (path, art["hash"])
|
|
645
|
+
break
|
|
646
|
+
return out
|
|
647
|
+
|
|
630
648
|
def paths_with_any(self, keys: Iterable[str]) -> set[str]:
|
|
631
649
|
"""Files that have at least one of these tags (by name, any case)."""
|
|
632
650
|
with self._lock:
|
|
@@ -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:
|
|
@@ -22,8 +22,11 @@ every move (see ``undo_moves``).
|
|
|
22
22
|
|
|
23
23
|
from __future__ import annotations
|
|
24
24
|
|
|
25
|
+
import contextlib
|
|
26
|
+
import errno
|
|
25
27
|
import os
|
|
26
28
|
import re
|
|
29
|
+
import secrets
|
|
27
30
|
import shutil
|
|
28
31
|
import threading
|
|
29
32
|
import unicodedata
|
|
@@ -361,18 +364,40 @@ def _move_one(root: Root, src: str, dst: str) -> None:
|
|
|
361
364
|
if os.path.lexists(b) and not _same_file(a, b):
|
|
362
365
|
raise FileExistsError("A different file already has that name")
|
|
363
366
|
b.parent.mkdir(parents=True, exist_ok=True)
|
|
367
|
+
if not a.is_dir() and not _same_file(a, b) and _link_then_unlink(a, b):
|
|
368
|
+
return
|
|
364
369
|
try:
|
|
365
370
|
os.rename(a, b) # same filesystem: instant, and the file itself is never rewritten
|
|
366
371
|
except OSError as exc:
|
|
367
|
-
if exc.errno !=
|
|
372
|
+
if exc.errno != errno.EXDEV: # another disk or mount (e.g. the inbox folder)
|
|
368
373
|
raise
|
|
369
374
|
_copy_then_remove(a, b)
|
|
370
375
|
|
|
371
376
|
|
|
377
|
+
def _link_then_unlink(a: Path, b: Path) -> bool:
|
|
378
|
+
"""Move a file without any chance of replacing one that appeared at ``b`` a moment ago
|
|
379
|
+
(a plain rename would silently overwrite it). True when done; False when hard links
|
|
380
|
+
aren't possible here (another disk, exFAT, some network shares), so the caller renames."""
|
|
381
|
+
try:
|
|
382
|
+
os.link(a, b, follow_symlinks=False)
|
|
383
|
+
except FileExistsError:
|
|
384
|
+
raise FileExistsError("A different file already has that name") from None
|
|
385
|
+
except OSError:
|
|
386
|
+
return False
|
|
387
|
+
try:
|
|
388
|
+
os.unlink(a)
|
|
389
|
+
except OSError:
|
|
390
|
+
with contextlib.suppress(OSError):
|
|
391
|
+
os.unlink(b) # couldn't let go of the old name: put things back as they were
|
|
392
|
+
raise
|
|
393
|
+
return True
|
|
394
|
+
|
|
395
|
+
|
|
372
396
|
def _copy_then_remove(a: Path, b: Path) -> None:
|
|
373
397
|
"""Move across disks: copy to a temporary name next to the target, check
|
|
374
398
|
it, give it its real name, and only then delete the original."""
|
|
375
|
-
|
|
399
|
+
# A short temporary name: the real one may already be at the 255-byte limit.
|
|
400
|
+
tmp = b.with_name(f".codetta-move-{os.getpid()}-{secrets.token_hex(4)}{b.suffix[:16]}")
|
|
376
401
|
try:
|
|
377
402
|
if a.is_dir() and not a.is_symlink():
|
|
378
403
|
shutil.copytree(a, tmp, symlinks=True)
|
|
@@ -299,7 +299,7 @@ def _apply_one(
|
|
|
299
299
|
result.previous = {k: list(current.tags.get(k, [])) for k in changes}
|
|
300
300
|
if changes and not dry_run:
|
|
301
301
|
engine.update_tags(path, changes)
|
|
302
|
-
except (MetadataError,
|
|
302
|
+
except (MetadataError, OSError) as exc: # any one file failing (unreadable, no permission) never stops the rest
|
|
303
303
|
result.applied = {}
|
|
304
304
|
result.error = str(exc)
|
|
305
305
|
return result
|
|
@@ -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:
|
|
@@ -48,7 +48,7 @@ from contextlib import asynccontextmanager
|
|
|
48
48
|
from dataclasses import dataclass
|
|
49
49
|
from importlib.metadata import PackageNotFoundError, version
|
|
50
50
|
from pathlib import Path
|
|
51
|
-
from typing import Literal
|
|
51
|
+
from typing import Annotated, Literal
|
|
52
52
|
from urllib.parse import urlsplit
|
|
53
53
|
|
|
54
54
|
from fastapi import FastAPI, HTTPException, Query, Request
|
|
@@ -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,
|
|
@@ -350,6 +351,10 @@ def _unique(paths: list[str]) -> list[str]:
|
|
|
350
351
|
return list(dict.fromkeys(paths))
|
|
351
352
|
|
|
352
353
|
|
|
354
|
+
class FolderCoversIn(BaseModel):
|
|
355
|
+
paths: list[Annotated[str, Field(max_length=MAX_PATH_CHARS)]] = Field(max_length=200)
|
|
356
|
+
|
|
357
|
+
|
|
353
358
|
class UpdateIn(BaseModel):
|
|
354
359
|
paths: list[str] = Field(min_length=1, max_length=MAX_PATHS_PER_REQUEST)
|
|
355
360
|
# Tag name -> new value(s). null, "" or [] removes the tag.
|
|
@@ -562,7 +567,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
562
567
|
mb_mirror += "/ws/2"
|
|
563
568
|
mb = MusicBrainz(
|
|
564
569
|
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)),
|
|
570
|
+
allow_http=mb_mirror is not None, timeout=MB_TIMEOUT)),
|
|
566
571
|
base=mb_mirror or MB_BASE,
|
|
567
572
|
min_interval=0 if mb_mirror else 1.0, # musicbrainz.org allows one request a second
|
|
568
573
|
)
|
|
@@ -1012,6 +1017,20 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1012
1017
|
tracks=tracks_out(listing.files),
|
|
1013
1018
|
)
|
|
1014
1019
|
|
|
1020
|
+
@app.post("/api/folder-covers")
|
|
1021
|
+
def folder_covers(body: FolderCoversIn) -> dict:
|
|
1022
|
+
"""A cover for each folder in the grid: a track inside it with embedded art (from the
|
|
1023
|
+
search index, so nothing is read from disk). The page shows it with /api/art."""
|
|
1024
|
+
require_library()
|
|
1025
|
+
folders = []
|
|
1026
|
+
for rel in body.paths:
|
|
1027
|
+
try:
|
|
1028
|
+
folders.append(library.relative(library.resolve(rel))) # rejects anything outside the library
|
|
1029
|
+
except (LibraryPathError, ValueError):
|
|
1030
|
+
continue
|
|
1031
|
+
found = lib_index.cover_tracks(f for f in folders if not f.startswith("@"))
|
|
1032
|
+
return {"covers": {f: {"path": p, "hash": h} for f, (p, h) in found.items()}}
|
|
1033
|
+
|
|
1015
1034
|
@app.get("/api/track", response_model=TrackOut)
|
|
1016
1035
|
def get_track(path: str = Query(..., max_length=MAX_PATH_CHARS, description="File, relative to the music folder")):
|
|
1017
1036
|
require_library()
|
|
@@ -1373,7 +1392,8 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1373
1392
|
undo = parts[0] if len(parts) == 1 else {"type": "multi", "parts": parts} if parts else None
|
|
1374
1393
|
if results:
|
|
1375
1394
|
_log_musicbrainz(activity, summary, proposal["files"], results, bool(art_undo), undo)
|
|
1376
|
-
|
|
1395
|
+
# Every file that changed, including one whose tags saved but cover didn't.
|
|
1396
|
+
lib_index.mark_dirty({r["path"] for r in results if r["ok"]} | set(tag_undo) | set(art_undo))
|
|
1377
1397
|
return {
|
|
1378
1398
|
"release": summary,
|
|
1379
1399
|
"results": results,
|
|
@@ -1683,6 +1703,8 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1683
1703
|
if exact and inbox_auto(key):
|
|
1684
1704
|
inbox_file(key, automatic=True)
|
|
1685
1705
|
except HTTPException as exc:
|
|
1706
|
+
if exc.status_code == 409 and key in inbox_filing:
|
|
1707
|
+
return # someone tapped "File" a moment earlier: that filing carries on
|
|
1686
1708
|
inbox.update(key, status=INBOX_ERROR, title=title, artist=artist, note=str(exc.detail))
|
|
1687
1709
|
|
|
1688
1710
|
def inbox_auto(key: str) -> bool:
|
|
@@ -1693,7 +1715,23 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1693
1715
|
return not soulseek_store.settings.review
|
|
1694
1716
|
return inbox.settings.auto
|
|
1695
1717
|
|
|
1718
|
+
inbox_filing: set[str] = set()
|
|
1719
|
+
inbox_filing_lock = threading.Lock()
|
|
1720
|
+
|
|
1696
1721
|
def inbox_file(key: str, release: str | None = None, recordings: dict | None = None, automatic: bool = False) -> dict:
|
|
1722
|
+
"""File one album. A second request for the same album while it's being filed (a double
|
|
1723
|
+
tap, or "File all" while it's filing itself) is turned away instead of running twice."""
|
|
1724
|
+
with inbox_filing_lock:
|
|
1725
|
+
if key in inbox_filing:
|
|
1726
|
+
raise HTTPException(409, "This album is already being filed.")
|
|
1727
|
+
inbox_filing.add(key)
|
|
1728
|
+
try:
|
|
1729
|
+
return inbox_file_locked(key, release, recordings, automatic)
|
|
1730
|
+
finally:
|
|
1731
|
+
with inbox_filing_lock:
|
|
1732
|
+
inbox_filing.discard(key)
|
|
1733
|
+
|
|
1734
|
+
def inbox_file_locked(key: str, release: str | None, recordings: dict | None, automatic: bool) -> dict:
|
|
1697
1735
|
g = inbox.groups.get(key)
|
|
1698
1736
|
if g is None:
|
|
1699
1737
|
raise HTTPException(404, "That album is no longer in the inbox")
|
|
@@ -1907,7 +1945,13 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1907
1945
|
"""File every confident match in one go."""
|
|
1908
1946
|
require_library()
|
|
1909
1947
|
keys = [g.key for g in list(inbox.groups.values()) if g.status == READY]
|
|
1910
|
-
filed =
|
|
1948
|
+
filed = 0
|
|
1949
|
+
for k in keys:
|
|
1950
|
+
try:
|
|
1951
|
+
filed += inbox_file(k)["status"] == FILED
|
|
1952
|
+
except HTTPException as exc:
|
|
1953
|
+
if exc.status_code != 409: # 409: already being filed, by itself or another tap
|
|
1954
|
+
raise
|
|
1911
1955
|
return {"filed": filed, "total": len(keys), "inbox": inbox_out()}
|
|
1912
1956
|
|
|
1913
1957
|
@app.post("/api/inbox/skip")
|
|
@@ -2313,7 +2357,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2313
2357
|
# --- Library health -------------------------------------------------------------------------
|
|
2314
2358
|
|
|
2315
2359
|
health_store = HealthStore(settings.config_dir / "health.json")
|
|
2316
|
-
health_cache: dict = {"key": None, "data": None, "at": 0.0, "fixed": {}}
|
|
2360
|
+
health_cache: dict = {"key": None, "data": None, "at": 0.0, "fixed": {}, "complete": False}
|
|
2317
2361
|
health_lock = threading.Lock()
|
|
2318
2362
|
|
|
2319
2363
|
health_compute_lock = threading.Lock()
|
|
@@ -2322,12 +2366,13 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2322
2366
|
def health_compute() -> None:
|
|
2323
2367
|
with health_compute_lock:
|
|
2324
2368
|
key = lib_index.version
|
|
2369
|
+
complete = lib_index.status().ready # made from the whole library, not mid-way through the first scan
|
|
2325
2370
|
inbox_folder = inbox.settings.folder
|
|
2326
2371
|
skip = [inbox_folder] if inbox_folder and not inbox_folder.startswith("@") else []
|
|
2327
2372
|
data = health_run(lib_index.iter_tracks(), folder_has_image(library.resolve),
|
|
2328
2373
|
lib_index.paths_with_any(MB_RELEASE_KEYS), skip)
|
|
2329
2374
|
with health_lock:
|
|
2330
|
-
health_cache.update(data=data, key=key, at=time.time())
|
|
2375
|
+
health_cache.update(data=data, key=key, at=time.time(), complete=complete)
|
|
2331
2376
|
|
|
2332
2377
|
def health_data() -> dict:
|
|
2333
2378
|
"""Every issue. The first check waits for the answer; after that, a change to the library
|
|
@@ -2336,7 +2381,8 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2336
2381
|
with health_lock:
|
|
2337
2382
|
data = health_cache["data"]
|
|
2338
2383
|
stale = health_cache["key"] != lib_index.version or time.time() - health_cache["at"] > 600
|
|
2339
|
-
|
|
2384
|
+
partial = not health_cache["complete"] and lib_index.status().ready
|
|
2385
|
+
if data is None or partial: # never show an answer from half a library once the whole one is read
|
|
2340
2386
|
health_compute()
|
|
2341
2387
|
elif stale and not (health_worker["thread"] and health_worker["thread"].is_alive()):
|
|
2342
2388
|
health_worker["thread"] = threading.Thread(target=health_compute, name="codetta-health", daemon=True)
|
|
@@ -2431,6 +2477,10 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2431
2477
|
require_library()
|
|
2432
2478
|
if not health_store.enabled:
|
|
2433
2479
|
raise HTTPException(409, "Library health is switched off.")
|
|
2480
|
+
with health_lock:
|
|
2481
|
+
stale = health_cache["key"] != lib_index.version
|
|
2482
|
+
if stale: # the library changed since this list was made: check again before writing anything
|
|
2483
|
+
health_compute()
|
|
2434
2484
|
issue = next((i for i in health_data()["issues"] if i["id"] == body.id), None)
|
|
2435
2485
|
if issue is None:
|
|
2436
2486
|
raise HTTPException(404, "That issue is gone (fixed already?)")
|
|
@@ -2633,10 +2683,16 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2633
2683
|
lib_index.mark_dirty(done)
|
|
2634
2684
|
return done, failed
|
|
2635
2685
|
|
|
2686
|
+
undo_lock = threading.Lock() # one undo at a time: a double tap can't run the same undo twice
|
|
2687
|
+
|
|
2636
2688
|
@app.post("/api/activity/{entry_id}/undo")
|
|
2637
2689
|
def undo(entry_id: int) -> dict:
|
|
2638
2690
|
"""Reverse a logged change. Files edited again since are left alone."""
|
|
2639
2691
|
require_library()
|
|
2692
|
+
with undo_lock:
|
|
2693
|
+
return undo_locked(entry_id)
|
|
2694
|
+
|
|
2695
|
+
def undo_locked(entry_id: int) -> dict:
|
|
2640
2696
|
entry = activity.get(entry_id)
|
|
2641
2697
|
if entry is None:
|
|
2642
2698
|
raise HTTPException(404, "That change is no longer in the activity log")
|
|
@@ -2644,7 +2700,10 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2644
2700
|
raise HTTPException(422, "This change can't be undone")
|
|
2645
2701
|
if activity.is_undone(entry_id):
|
|
2646
2702
|
raise HTTPException(409, "This change has already been undone")
|
|
2647
|
-
|
|
2703
|
+
try:
|
|
2704
|
+
outcome = undo_change(engine, library.resolve, art_store, entry["undo"])
|
|
2705
|
+
except LibraryPathError as exc: # e.g. it moved files in the inbox, and there's no inbox folder now
|
|
2706
|
+
raise HTTPException(409, f"This change can't be undone any more: {exc}") from exc
|
|
2648
2707
|
lib_index.mark_dirty(r.path for r in outcome.results if r.ok)
|
|
2649
2708
|
if entry["undo"].get("type") == "moves" and outcome.reverse:
|
|
2650
2709
|
lib_index.mark_dirty(p for pair in outcome.reverse["moves"] for p in pair if not p.startswith("@"))
|