codetta 0.8.4__tar.gz → 0.8.5__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.4/src/codetta.egg-info → codetta-0.8.5}/PKG-INFO +2 -2
- {codetta-0.8.4 → codetta-0.8.5}/README.md +1 -1
- {codetta-0.8.4 → codetta-0.8.5}/pyproject.toml +1 -1
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/CHANGELOG.md +15 -0
- codetta-0.8.5/src/codetta/core/fileinfo.py +99 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/library.py +9 -1
- codetta-0.8.5/src/codetta/core/logbuffer.py +73 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/presets.py +16 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/rawtags.py +5 -1
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/tagmap.py +77 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/app.py +166 -3
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/app.css +69 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/app.js +320 -2
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/index.html +18 -0
- {codetta-0.8.4 → codetta-0.8.5/src/codetta.egg-info}/PKG-INFO +2 -2
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta.egg-info/SOURCES.txt +3 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_api.py +1 -1
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_attacks.py +4 -1
- codetta-0.8.5/tests/test_files.py +160 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_presets.py +24 -2
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_security.py +15 -0
- {codetta-0.8.4 → codetta-0.8.5}/LICENSE +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/setup.cfg +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/__main__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/cli/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/cli/__main__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/cli/run.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/acoustid.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/activity.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/artwork.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/auth.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/avatar.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/changelog.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/connections.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/describe.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/engine.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/health.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/inbox.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/index.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/musicbrainz.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/notifications.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/onboarding.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/organize.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/plugins.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/providers.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/slskd.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/undo.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/core/updates.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/plugins/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/plugins/builtin/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/plugins/builtin/tidy.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/__init__.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/security.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/apple-touch-icon.png +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/fonts/LICENSE-Inter.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/fonts/LICENSE-SchibstedGrotesk.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/fonts/inter-cyrillic.woff2 +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/fonts/schibsted-grotesk.woff2 +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icon.svg +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-dark.png +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-dark.svg +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-dark.webp +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-light.png +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-light.svg +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta-light.webp +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta.png +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta.svg +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/icons/codetta.webp +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta/web/static/theme.js +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta.egg-info/dependency_links.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta.egg-info/entry_points.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta.egg-info/requires.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/src/codetta.egg-info/top_level.txt +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_acoustid.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_artwork.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_auth.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_avatar.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_cli_run.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_connections.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_efficiency.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_engine.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_explore.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_health.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_inbox.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_index.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_musicbrainz.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_organize.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_plugins.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_privacy.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_providers.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_rawtags.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_safety.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_slskd.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_soulseek_api.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/tests/test_undo.py +0 -0
- {codetta-0.8.4 → codetta-0.8.5}/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.5
|
|
4
4
|
Summary: A private, self-hosted music library manager: tags, MusicBrainz matching, batch editing and organizing, in your browser
|
|
5
5
|
Author: gavndev
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -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.5" src="https://img.shields.io/badge/version-0.8.5-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>
|
|
@@ -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.5" src="https://img.shields.io/badge/version-0.8.5-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.5"
|
|
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 = "gavndev" }]
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Codetta. Versions follow [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.8.5 (2026-11-19)
|
|
6
|
+
|
|
7
|
+
- **Right-click menu (long press on phones):** for any track or folder: Rename, Move to, Select, Actions, Get info, Find in MusicBrainz, Find in slskd and Delete. It's small and quick, opens right where you clicked, and works on a selection too.
|
|
8
|
+
- **Get info** shows what the tags don't: format, bit depth, sample rate, bitrate, file size, tag type, cover size and location.
|
|
9
|
+
- **Delete** asks once, then moves things to *Recently deleted* for 30 days instead of erasing them, and Activity can bring them back.
|
|
10
|
+
- The MusicBrainz and slskd entries keep their colours.
|
|
11
|
+
- **Move to** and **Rename** work like Organize: nothing is ever overwritten, lyrics files follow their song, and one tap undoes it.
|
|
12
|
+
- **Advanced mode, deeper:** switch it on in the account menu for a closer look at your files.
|
|
13
|
+
- Every field in the editor shows how this file actually stores it, in a code font: `TPE1` in an MP3, `©ART` in an M4A, `ARTIST` in a FLAC, or "not in WMA" when the format can't hold it.
|
|
14
|
+
- **Get info** adds the encoder, how many of Codetta's fields the format can store, and the file's full location on the server.
|
|
15
|
+
- **Server log:** a live view of Codetta's own log (what `docker logs` shows) at the bottom of the account menu. It's kept in memory only, only you can see it, it never includes who visited, and anything that looks like a key or password is masked.
|
|
16
|
+
- **Fixed:** the raw tag view in Advanced mode failed on M4A files marked as a compilation, and showed production credits in MP3s as unreadable code.
|
|
17
|
+
- **Privacy:** a failed sign-in no longer writes the typed username to the log (people sometimes type their password there by mistake).
|
|
18
|
+
- **Explicit and Clean presets:** mark a folder or a selection as explicit or clean in one go. They set the advisory tag Navidrome and Apple Music read (1 = explicit, 2 = clean), in every format, including Apple's own field in M4A files. The tag also shows in the editor as **Explicit**, under Release.
|
|
19
|
+
|
|
5
20
|
## 0.8.4 (2026-11-19)
|
|
6
21
|
|
|
7
22
|
- **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.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Get info: details about a file or folder beyond its tags (format, quality, size, dates)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from codetta.core.engine import SUPPORTED_EXTENSIONS, MetadataEngine, _open_raw
|
|
9
|
+
from codetta.core.artwork import read_picture
|
|
10
|
+
from codetta.core.tagmap import FIELDS, is_tag_supported
|
|
11
|
+
|
|
12
|
+
MAX_FOLDER_FILES = 20_000 # counting stops here, so a huge folder answers quickly
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _tag_kind(audio) -> str | None:
|
|
16
|
+
"""The kind of tag block the file carries, e.g. "ID3v2.4", "Vorbis comments", "MP4 atoms"."""
|
|
17
|
+
tags = getattr(audio, "tags", None)
|
|
18
|
+
if tags is None:
|
|
19
|
+
return None
|
|
20
|
+
name = type(tags).__name__
|
|
21
|
+
if name.startswith("ID3"):
|
|
22
|
+
version = getattr(tags, "version", None)
|
|
23
|
+
return f"ID3v{version[0]}.{version[1]}" if version else "ID3"
|
|
24
|
+
return {"VCFLACDict": "Vorbis comments", "VComment": "Vorbis comments", "OggVCommentDict": "Vorbis comments",
|
|
25
|
+
"OggOpusVComment": "Vorbis comments", "OggFLACVComment": "Vorbis comments", "OggSpeexVComment": "Vorbis comments",
|
|
26
|
+
"MP4Tags": "MP4 atoms", "APEv2": "APEv2", "ASFTags": "ASF attributes"}.get(name, name)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _encoder(audio) -> str | None:
|
|
30
|
+
"""What made the file ("LAME 3.100", "Lavf62.3.100"...), when it says."""
|
|
31
|
+
tags = getattr(audio, "tags", None)
|
|
32
|
+
if not tags:
|
|
33
|
+
return None
|
|
34
|
+
for key in ("TSSE", "TENC", "©too", "encoder", "ENCODER", "Encoder", "WM/EncodingSettings", "WM/ToolName"):
|
|
35
|
+
try:
|
|
36
|
+
value = tags.get(key) if hasattr(tags, "get") else None
|
|
37
|
+
except (KeyError, ValueError, TypeError):
|
|
38
|
+
value = None
|
|
39
|
+
if value:
|
|
40
|
+
text = str(value[0] if isinstance(value, list) else value)
|
|
41
|
+
if text.strip():
|
|
42
|
+
return text.strip()[:120]
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def file_info(engine: MetadataEngine, path: Path) -> dict:
|
|
47
|
+
"""What Get info shows for one audio file."""
|
|
48
|
+
st = path.stat()
|
|
49
|
+
meta = engine.load_metadata(path)
|
|
50
|
+
audio, format_name = _open_raw(path)
|
|
51
|
+
info = audio.info
|
|
52
|
+
art = read_picture(audio, format_name)
|
|
53
|
+
codec = getattr(info, "codec_description", None) or getattr(info, "codec", None)
|
|
54
|
+
return {
|
|
55
|
+
"kind": "file",
|
|
56
|
+
"name": path.name,
|
|
57
|
+
"format": meta.format,
|
|
58
|
+
"codec": str(codec) if codec else None,
|
|
59
|
+
"duration": meta.duration,
|
|
60
|
+
"bitrate": meta.bitrate,
|
|
61
|
+
"sample_rate": meta.sample_rate,
|
|
62
|
+
"bits_per_sample": getattr(info, "bits_per_sample", None) or None,
|
|
63
|
+
"channels": meta.channels,
|
|
64
|
+
"size": st.st_size,
|
|
65
|
+
"modified": int(st.st_mtime),
|
|
66
|
+
"tag_kind": _tag_kind(audio),
|
|
67
|
+
"tag_count": sum(len(v) for v in meta.tags.values()),
|
|
68
|
+
"art": {"mime": art.mime, "width": art.width, "height": art.height, "size": len(art.data)} if art else None,
|
|
69
|
+
"encoder": _encoder(audio),
|
|
70
|
+
"fields_supported": sum(is_tag_supported(meta.format or "", f.key) for f in FIELDS),
|
|
71
|
+
"fields_total": len(FIELDS),
|
|
72
|
+
"fields_unsupported": [f.label for f in FIELDS if not is_tag_supported(meta.format or "", f.key)],
|
|
73
|
+
"on_disk": str(path),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def folder_info(path: Path) -> dict:
|
|
78
|
+
"""What Get info shows for a folder (counted up to MAX_FOLDER_FILES files)."""
|
|
79
|
+
files = audio = folders = size = 0
|
|
80
|
+
capped = False
|
|
81
|
+
for dirpath, dirs, names in os.walk(path):
|
|
82
|
+
dirs[:] = [d for d in dirs if not d.startswith(".")]
|
|
83
|
+
folders += len(dirs)
|
|
84
|
+
for n in names:
|
|
85
|
+
if n.startswith("."):
|
|
86
|
+
continue
|
|
87
|
+
files += 1
|
|
88
|
+
audio += Path(n).suffix.lower() in SUPPORTED_EXTENSIONS
|
|
89
|
+
try:
|
|
90
|
+
size += (Path(dirpath) / n).stat().st_size
|
|
91
|
+
except OSError:
|
|
92
|
+
pass
|
|
93
|
+
if files >= MAX_FOLDER_FILES:
|
|
94
|
+
capped = True
|
|
95
|
+
break
|
|
96
|
+
if capped:
|
|
97
|
+
break
|
|
98
|
+
return {"kind": "folder", "name": path.name, "files": files, "audio": audio, "folders": folders,
|
|
99
|
+
"size": size, "capped": capped, "modified": int(path.stat().st_mtime), "on_disk": str(path)}
|
|
@@ -33,16 +33,19 @@ class FolderListing:
|
|
|
33
33
|
|
|
34
34
|
INBOX = "@inbox" # paths starting with this live in the inbox folder, outside the library
|
|
35
35
|
REPLACED = "@replaced" # albums an upgrade replaced (kept in the config folder so it can be undone)
|
|
36
|
+
DELETED = "@deleted" # "Recently deleted": files you deleted, kept in the config folder for 30 days
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
class Library:
|
|
39
|
-
def __init__(self, root: str | Path, inbox: str | Path | None = None, replaced: str | Path | None = None
|
|
40
|
+
def __init__(self, root: str | Path, inbox: str | Path | None = None, replaced: str | Path | None = None,
|
|
41
|
+
deleted: str | Path | None = None) -> None:
|
|
40
42
|
# Normalise without resolving symlinks: a library that links to music
|
|
41
43
|
# on other disks is normal, and the engine follows links when writing.
|
|
42
44
|
self.root = Path(os.path.abspath(root))
|
|
43
45
|
# Optional second folder (e.g. slskd's downloads), addressed as "@inbox/...".
|
|
44
46
|
self.inbox = Path(os.path.abspath(inbox)) if inbox else None
|
|
45
47
|
self.replaced = Path(os.path.abspath(replaced)) if replaced else None
|
|
48
|
+
self.deleted = Path(os.path.abspath(deleted)) if deleted else None
|
|
46
49
|
|
|
47
50
|
def inbox_available(self) -> bool:
|
|
48
51
|
return self.inbox is not None and self.inbox.is_dir()
|
|
@@ -63,6 +66,8 @@ class Library:
|
|
|
63
66
|
return self.inbox.joinpath(*rel.parts[1:])
|
|
64
67
|
if rel.parts and rel.parts[0] == REPLACED and self.replaced is not None:
|
|
65
68
|
return self.replaced.joinpath(*rel.parts[1:])
|
|
69
|
+
if rel.parts and rel.parts[0] == DELETED and self.deleted is not None:
|
|
70
|
+
return self.deleted.joinpath(*rel.parts[1:])
|
|
66
71
|
if rel.parts and rel.parts[0].startswith("@"):
|
|
67
72
|
raise LibraryPathError(f"Unknown folder: {rel.parts[0]}")
|
|
68
73
|
return self.root.joinpath(*rel.parts)
|
|
@@ -76,6 +81,9 @@ class Library:
|
|
|
76
81
|
if self.replaced is not None and path.is_relative_to(self.replaced) and not path.is_relative_to(self.root):
|
|
77
82
|
rel = path.relative_to(self.replaced).as_posix()
|
|
78
83
|
return REPLACED if rel == "." else f"{REPLACED}/{rel}"
|
|
84
|
+
if self.deleted is not None and path.is_relative_to(self.deleted) and not path.is_relative_to(self.root):
|
|
85
|
+
rel = path.relative_to(self.deleted).as_posix()
|
|
86
|
+
return DELETED if rel == "." else f"{DELETED}/{rel}"
|
|
79
87
|
rel = path.relative_to(self.root).as_posix()
|
|
80
88
|
return "" if rel == "." else rel
|
|
81
89
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""The server log, for Advanced mode's live log view: Codetta's own log lines (what `docker logs`
|
|
2
|
+
shows), kept in memory only. Nothing is written to disk, and the page only ever gets them through
|
|
3
|
+
a signed-in, private route.
|
|
4
|
+
|
|
5
|
+
Kept out on purpose: per-request access lines (Codetta keeps no record of who visits; they're off
|
|
6
|
+
anyway) and anything that looks like a secret (tokens, keys, passwords), which is masked even
|
|
7
|
+
though Codetta never logs them.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import logging
|
|
13
|
+
import re
|
|
14
|
+
import threading
|
|
15
|
+
from collections import deque
|
|
16
|
+
|
|
17
|
+
MAX_LINES = 500
|
|
18
|
+
MAX_LINE_CHARS = 2000
|
|
19
|
+
|
|
20
|
+
# key=value / key: value pairs whose value must never be shown, and bearer tokens.
|
|
21
|
+
_SECRET = re.compile(r"(?i)\b(api[_-]?key|token|password|passwd|secret|session|cookie|authorization)(\s*[=:]\s*)(\S+)")
|
|
22
|
+
_BEARER = re.compile(r"(?i)\bbearer\s+\S+")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def redact(text: str) -> str:
|
|
26
|
+
text = _SECRET.sub(lambda m: f"{m.group(1)}{m.group(2)}•••", text)
|
|
27
|
+
return _BEARER.sub("Bearer •••", text)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class LogBuffer(logging.Handler):
|
|
31
|
+
"""The last ``MAX_LINES`` log lines, each with an increasing id the page polls from."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, capacity: int = MAX_LINES) -> None:
|
|
34
|
+
super().__init__(level=logging.INFO)
|
|
35
|
+
self.lines: deque[dict] = deque(maxlen=capacity)
|
|
36
|
+
self._next = 1
|
|
37
|
+
self._lock = threading.Lock()
|
|
38
|
+
|
|
39
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
40
|
+
if record.name.startswith("uvicorn.access"):
|
|
41
|
+
return # never a record of who visited
|
|
42
|
+
try:
|
|
43
|
+
message = record.getMessage()
|
|
44
|
+
if record.exc_info:
|
|
45
|
+
message += "\n" + "".join(logging.Formatter().formatException(record.exc_info).splitlines(True)[-6:])
|
|
46
|
+
except Exception: # noqa: BLE001 - a bad log call must never break the app
|
|
47
|
+
return
|
|
48
|
+
line = {"time": record.created, "level": record.levelname.lower(), "source": record.name,
|
|
49
|
+
"message": redact(message)[:MAX_LINE_CHARS]}
|
|
50
|
+
with self._lock:
|
|
51
|
+
line["id"] = self._next
|
|
52
|
+
self._next += 1
|
|
53
|
+
self.lines.append(line)
|
|
54
|
+
|
|
55
|
+
def since(self, after: int = 0) -> list[dict]:
|
|
56
|
+
with self._lock:
|
|
57
|
+
return [line for line in self.lines if line["id"] > after]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_shared: LogBuffer | None = None
|
|
61
|
+
_shared_lock = threading.Lock()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def shared_buffer() -> LogBuffer:
|
|
65
|
+
"""One buffer per process, collecting Codetta's and the web server's log lines. "uvicorn" is
|
|
66
|
+
the parent of "uvicorn.error" (and "uvicorn.access", dropped above), so each line arrives once."""
|
|
67
|
+
global _shared
|
|
68
|
+
with _shared_lock:
|
|
69
|
+
if _shared is None:
|
|
70
|
+
_shared = LogBuffer()
|
|
71
|
+
for name in ("codetta", "uvicorn"):
|
|
72
|
+
logging.getLogger(name).addHandler(_shared)
|
|
73
|
+
return _shared
|
|
@@ -425,6 +425,22 @@ def default_presets() -> list[Preset]:
|
|
|
425
425
|
"media": "Digital Media",
|
|
426
426
|
},
|
|
427
427
|
),
|
|
428
|
+
Preset(
|
|
429
|
+
name="Explicit",
|
|
430
|
+
description=(
|
|
431
|
+
"Marks tracks as explicit, so Navidrome and other players show the "
|
|
432
|
+
"explicit badge. Apply to a folder or to selected tracks."
|
|
433
|
+
),
|
|
434
|
+
tags={"itunesadvisory": "1"},
|
|
435
|
+
),
|
|
436
|
+
Preset(
|
|
437
|
+
name="Clean",
|
|
438
|
+
description=(
|
|
439
|
+
"Marks tracks as the clean version, so Navidrome and other players "
|
|
440
|
+
"show them as clean. Apply to a folder or to selected tracks."
|
|
441
|
+
),
|
|
442
|
+
tags={"itunesadvisory": "2"},
|
|
443
|
+
),
|
|
428
444
|
Preset(
|
|
429
445
|
name="Full Credits",
|
|
430
446
|
description=(
|
|
@@ -59,7 +59,9 @@ def raw_tags(audio, format_name: str) -> tuple[str, list[dict]]:
|
|
|
59
59
|
for key, frame in (tags or {}).items():
|
|
60
60
|
if frame.FrameID == "APIC":
|
|
61
61
|
entries.append(_picture(key, frame.mime, frame.data, frame.type))
|
|
62
|
-
elif hasattr(frame, "
|
|
62
|
+
elif hasattr(frame, "people"): # TIPL / TMCL: "producer: Name; mixer: Name"
|
|
63
|
+
entries.append(_text(key, "; ".join(f"{role}: {name}" for role, name in frame.people)))
|
|
64
|
+
elif hasattr(frame, "text") or hasattr(frame, "url"):
|
|
63
65
|
entries.append(_text(key, str(frame)))
|
|
64
66
|
else:
|
|
65
67
|
data = getattr(frame, "data", b"")
|
|
@@ -71,6 +73,8 @@ def raw_tags(audio, format_name: str) -> tuple[str, list[dict]]:
|
|
|
71
73
|
for c in values:
|
|
72
74
|
entries.append(_picture(key, "image/png" if c.imageformat == 14 else "image/jpeg", bytes(c)))
|
|
73
75
|
continue
|
|
76
|
+
if not isinstance(values, list): # single-value atoms: cpil (compilation), pgap, hdvd... are a plain bool/int
|
|
77
|
+
values = [values]
|
|
74
78
|
shown = []
|
|
75
79
|
for v in values:
|
|
76
80
|
if isinstance(v, MP4FreeForm):
|
|
@@ -89,6 +89,9 @@ FIELDS: tuple[Field, ...] = (
|
|
|
89
89
|
Field("releasecountry", "Release country", "Release"),
|
|
90
90
|
Field("discsubtitle", "Disc subtitle", "Release"),
|
|
91
91
|
Field("compilation", "Compilation (1 = yes)", "Release"),
|
|
92
|
+
# Explicit content, the way Navidrome (OpenSubsonic explicitStatus) and Apple Music read it:
|
|
93
|
+
# 1 = explicit, 2 = clean, 0 = not rated.
|
|
94
|
+
Field("itunesadvisory", "Explicit (1 = explicit, 2 = clean)", "Release"),
|
|
92
95
|
Field("titlesort", "Title sort", "Sorting"),
|
|
93
96
|
Field("artistsort", "Artist sort", "Sorting"),
|
|
94
97
|
Field("albumsort", "Album sort", "Sorting"),
|
|
@@ -337,6 +340,7 @@ EasyID3.RegisterTextKey("movementname", "MVNM")
|
|
|
337
340
|
EasyID3.RegisterTXXXKey("work", "WORK")
|
|
338
341
|
EasyID3.RegisterTXXXKey("showmovement", "SHOWMOVEMENT")
|
|
339
342
|
EasyID3.RegisterTXXXKey("script", "SCRIPT")
|
|
343
|
+
EasyID3.RegisterTXXXKey("itunesadvisory", "ITUNESADVISORY")
|
|
340
344
|
|
|
341
345
|
|
|
342
346
|
def _register_id3_movement() -> None:
|
|
@@ -535,4 +539,77 @@ def _register_mp4_compilation() -> None:
|
|
|
535
539
|
_register_mp4_compilation()
|
|
536
540
|
|
|
537
541
|
|
|
542
|
+
def _register_mp4_advisory() -> None:
|
|
543
|
+
"""``itunesadvisory`` -> Apple's ``rtng`` atom (a number): "1" explicit, "2" clean, "0" none."""
|
|
544
|
+
|
|
545
|
+
def get(tags, key):
|
|
546
|
+
return [str(v) for v in tags["rtng"]]
|
|
547
|
+
|
|
548
|
+
def set_(tags, key, value):
|
|
549
|
+
if len(value) != 1 or value[0] not in ("0", "1", "2", "4"):
|
|
550
|
+
raise ValueError("explicit must be 1 (explicit), 2 (clean) or 0 (not rated)")
|
|
551
|
+
tags["rtng"] = [int(value[0])]
|
|
552
|
+
|
|
553
|
+
def delete(tags, key):
|
|
554
|
+
del tags["rtng"]
|
|
555
|
+
|
|
556
|
+
EasyMP4Tags.RegisterKey("itunesadvisory", get, set_, delete)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
_register_mp4_advisory()
|
|
560
|
+
|
|
561
|
+
|
|
538
562
|
_FIELD_KEYS = frozenset(f.key for f in FIELDS)
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
# --- In-file names (Advanced mode) ----------------------------------------------------------------
|
|
566
|
+
|
|
567
|
+
# ID3 frames / MP4 atoms that mutagen handles with its own code, so they can't be read from
|
|
568
|
+
# its registrations below.
|
|
569
|
+
_ID3_SPECIAL = {"comment": "COMM", "lyrics": "USLT", "movement": "MVIN", "movementtotal": "MVIN",
|
|
570
|
+
"date": "TDRC", "genre": "TCON", "tracknumber": "TRCK", "discnumber": "TPOS",
|
|
571
|
+
"originaldate": "TDOR", "albumartistsort": "TSO2",
|
|
572
|
+
# Production credits share one "involved people" frame, one role each.
|
|
573
|
+
"producer": "TIPL", "engineer": "TIPL", "mixer": "TIPL", "djmixer": "TIPL"}
|
|
574
|
+
_MP4_SPECIAL = {"compilation": "cpil", "itunesadvisory": "rtng", "tracknumber": "trkn", "discnumber": "disk",
|
|
575
|
+
"bpm": "tmpo", "movementtotal": "©mvc"}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def _closure_name(fn) -> str | None:
|
|
579
|
+
"""The frame or atom name a mutagen key function was registered with."""
|
|
580
|
+
for cell in getattr(fn, "__closure__", None) or ():
|
|
581
|
+
try:
|
|
582
|
+
value = cell.cell_contents
|
|
583
|
+
except ValueError:
|
|
584
|
+
continue
|
|
585
|
+
if isinstance(value, str) and value:
|
|
586
|
+
return value
|
|
587
|
+
return None
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def native_name(format_name: str, key: str) -> str | None:
|
|
591
|
+
"""How a file of ``format_name`` stores the tag ``key``: "TPE1", "©ART", "ARTIST",
|
|
592
|
+
"WM/AlbumArtist"... None when this format can't store it."""
|
|
593
|
+
key = key.lower()
|
|
594
|
+
if not is_tag_supported(format_name, key):
|
|
595
|
+
return None
|
|
596
|
+
if format_name in VORBIS_FORMATS:
|
|
597
|
+
return key.upper()
|
|
598
|
+
if format_name in ID3_FORMATS:
|
|
599
|
+
fn = EasyID3.Get.get(key)
|
|
600
|
+
name = _ID3_SPECIAL.get(key) or (_closure_name(fn) if fn else None)
|
|
601
|
+
return name or f"TXXX:{key.upper()}"
|
|
602
|
+
if format_name in MP4_FORMATS or format_name == "m4b":
|
|
603
|
+
fn = EasyMP4Tags.Get.get(key)
|
|
604
|
+
name = _MP4_SPECIAL.get(key) or (_closure_name(fn) if fn else None)
|
|
605
|
+
return name or f"----:com.apple.iTunes:{key.upper()}"
|
|
606
|
+
if format_name in APE_FORMATS:
|
|
607
|
+
return _APE_NAMES.get(key) or (key.title() if key in _FIELD_KEYS else key)
|
|
608
|
+
if format_name in ASF_FORMATS:
|
|
609
|
+
return _ASF_NAMES.get(key, key)
|
|
610
|
+
return None
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def native_names(format_name: str, keys) -> dict[str, str | None]:
|
|
614
|
+
"""``native_name`` for each key (None: this format can't store it)."""
|
|
615
|
+
return {k: native_name(format_name, k) for k in keys}
|
|
@@ -37,6 +37,7 @@ Settings (environment variables):
|
|
|
37
37
|
|
|
38
38
|
from __future__ import annotations
|
|
39
39
|
|
|
40
|
+
import contextlib
|
|
40
41
|
import logging
|
|
41
42
|
import os
|
|
42
43
|
import re
|
|
@@ -77,6 +78,8 @@ from codetta.core.health import _base_artist as base_artist
|
|
|
77
78
|
from codetta.core.health import fold as health_fold
|
|
78
79
|
from codetta.core.health import run as health_run
|
|
79
80
|
from codetta.core.describe import describe_file, describe_many
|
|
81
|
+
from codetta.core.fileinfo import file_info, folder_info
|
|
82
|
+
from codetta.core.logbuffer import shared_buffer
|
|
80
83
|
from codetta.core.plugins import ActionError, PluginManager
|
|
81
84
|
from codetta.core.index import LibraryIndex, parse_query
|
|
82
85
|
from codetta.core import changelog
|
|
@@ -96,11 +99,13 @@ from codetta.core.inbox import (
|
|
|
96
99
|
InboxStore,
|
|
97
100
|
)
|
|
98
101
|
from codetta.core.inbox import signature as inbox_signature
|
|
102
|
+
from codetta.core.library import DELETED
|
|
99
103
|
from codetta.core.library import INBOX as INBOX_ALIAS
|
|
100
104
|
from codetta.core.library import Library, LibraryPathError, TooManyFilesError, audio_files, count_contents
|
|
101
105
|
from codetta.core.organize import (
|
|
102
106
|
DEFAULT_PATTERN,
|
|
103
107
|
PRESETS as ORGANIZE_PRESETS,
|
|
108
|
+
SIDECAR_SUFFIXES,
|
|
104
109
|
Move,
|
|
105
110
|
PatternError,
|
|
106
111
|
Source,
|
|
@@ -176,7 +181,7 @@ from codetta.core.presets import (
|
|
|
176
181
|
apply_preset_to_folder,
|
|
177
182
|
slugify,
|
|
178
183
|
)
|
|
179
|
-
from codetta.core.tagmap import FIELDS, is_tag_supported
|
|
184
|
+
from codetta.core.tagmap import FIELDS, is_tag_supported, native_names
|
|
180
185
|
from codetta.core.undo import ArtStore, art_hashes, sha256, undo_change
|
|
181
186
|
from codetta.core.updates import DEFAULT_REPO, Fetcher, UpdateChecker, fetch_latest_release
|
|
182
187
|
from codetta.web.security import GuardMiddleware, SelectiveGZip
|
|
@@ -471,6 +476,19 @@ class PluginToggleIn(BaseModel):
|
|
|
471
476
|
enabled: bool
|
|
472
477
|
|
|
473
478
|
|
|
479
|
+
class FilesIn(BaseModel):
|
|
480
|
+
paths: list[Annotated[str, Field(max_length=MAX_PATH_CHARS)]] = Field(min_length=1, max_length=MAX_PATHS_PER_REQUEST)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class FilesMoveIn(FilesIn):
|
|
484
|
+
to: str = Field(max_length=MAX_PATH_CHARS) # a folder in the library ("" = the top)
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
class FileRenameIn(BaseModel):
|
|
488
|
+
path: str = Field(min_length=1, max_length=MAX_PATH_CHARS)
|
|
489
|
+
name: str = Field(min_length=1, max_length=255)
|
|
490
|
+
|
|
491
|
+
|
|
474
492
|
class FolderRenameIn(BaseModel):
|
|
475
493
|
path: str = Field(min_length=1, max_length=MAX_PATH_CHARS)
|
|
476
494
|
name: str = Field(min_length=1, max_length=255)
|
|
@@ -549,7 +567,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
549
567
|
"acoustid": settings.acoustid, "slskd": settings.slskd},
|
|
550
568
|
)
|
|
551
569
|
updates = UpdateChecker(VERSION, settings.update_repo, lambda: connections.enabled("updates"), fetch_release)
|
|
552
|
-
library = Library(settings.music_dir, settings.inbox_dir, settings.config_dir / "replaced")
|
|
570
|
+
library = Library(settings.music_dir, settings.inbox_dir, settings.config_dir / "replaced", settings.config_dir / "deleted")
|
|
553
571
|
_migrate_presets_folder(settings.config_dir)
|
|
554
572
|
store = PresetStore(settings.config_dir / "presets")
|
|
555
573
|
engine = MetadataEngine()
|
|
@@ -597,6 +615,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
597
615
|
pass
|
|
598
616
|
lib_index.start() # builds/refreshes the search index in the background
|
|
599
617
|
prune_replaced(settings.config_dir / "replaced") # upgrades' old albums, after 30 days
|
|
618
|
+
prune_replaced(settings.config_dir / "deleted") # "Recently deleted", after 30 days
|
|
600
619
|
watcher = threading.Thread(target=app.state.inbox_watch, name="codetta-inbox-watch", daemon=True)
|
|
601
620
|
watcher.start() # sleeps; only looks at the inbox if "check every 15 minutes" is on
|
|
602
621
|
app.state.soulseek_start() # carries on with downloads that were under way
|
|
@@ -721,7 +740,8 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
721
740
|
raise HTTPException(503, str(exc), headers={"Retry-After": "5"}) from exc
|
|
722
741
|
if account is None:
|
|
723
742
|
limiter.failed(client_key(request))
|
|
724
|
-
|
|
743
|
+
# Never the typed username: people sometimes type their password into that box.
|
|
744
|
+
log.warning("Failed sign-in from %s", client_key(request))
|
|
725
745
|
raise HTTPException(401, "Wrong username or password")
|
|
726
746
|
limiter.succeeded(client_key(request))
|
|
727
747
|
if needs_rehash(account.password_hash) and not accounts.managed_by_env:
|
|
@@ -1839,6 +1859,7 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
1839
1859
|
if time.time() - last_prune > 86400:
|
|
1840
1860
|
last_prune = time.time()
|
|
1841
1861
|
prune_replaced(settings.config_dir / "replaced")
|
|
1862
|
+
prune_replaced(settings.config_dir / "deleted")
|
|
1842
1863
|
if inbox.settings.watch and inbox.settings.folder and library.exists():
|
|
1843
1864
|
try:
|
|
1844
1865
|
inbox.sync(library)
|
|
@@ -2643,6 +2664,148 @@ def create_app(settings: Settings | None = None, fetch_release: Fetcher = fetch_
|
|
|
2643
2664
|
art_cache.clear()
|
|
2644
2665
|
return {"path": dest, "moved": len(pairs), "failed": len(failed)}
|
|
2645
2666
|
|
|
2667
|
+
# --- One file or folder at a time (the right-click / long-press menu) --------------------
|
|
2668
|
+
|
|
2669
|
+
def _join(folder: str, name: str) -> str:
|
|
2670
|
+
return f"{folder}/{name}" if folder else name
|
|
2671
|
+
|
|
2672
|
+
def _parent(rel: str) -> str:
|
|
2673
|
+
return rel.rsplit("/", 1)[0] if "/" in rel else ""
|
|
2674
|
+
|
|
2675
|
+
def entry_moves(rel: str, new_rel: str) -> list[Move]:
|
|
2676
|
+
"""Moves that put a file (with its .lrc) or a whole folder at ``new_rel``."""
|
|
2677
|
+
src = library.resolve(rel)
|
|
2678
|
+
if src.is_dir():
|
|
2679
|
+
moves = []
|
|
2680
|
+
for dirpath, _, names in os.walk(src):
|
|
2681
|
+
for n in sorted(names):
|
|
2682
|
+
r = library.relative(Path(dirpath) / n)
|
|
2683
|
+
moves.append(Move(r, new_rel + r[len(rel):], "move"))
|
|
2684
|
+
return moves
|
|
2685
|
+
if not src.is_file():
|
|
2686
|
+
raise HTTPException(404, f"“{rel.rsplit('/', 1)[-1]}” isn't there any more.")
|
|
2687
|
+
m = Move(rel, new_rel, "move")
|
|
2688
|
+
src_stem, dst_stem = os.path.splitext(rel)[0], os.path.splitext(new_rel)[0]
|
|
2689
|
+
for suffix in SIDECAR_SUFFIXES: # lyrics files follow their song
|
|
2690
|
+
if library.resolve(src_stem + suffix).is_file() and not os.path.lexists(library.resolve(dst_stem + suffix)):
|
|
2691
|
+
m.companions.append((src_stem + suffix, dst_stem + suffix))
|
|
2692
|
+
return [m]
|
|
2693
|
+
|
|
2694
|
+
def run_moves(moves: list[Move], kind: str, message: str, changes: list[dict]) -> dict:
|
|
2695
|
+
"""Do the moves (nothing is ever overwritten), log them as one undoable entry, refresh."""
|
|
2696
|
+
results = apply_moves(library.resolve, moves)
|
|
2697
|
+
pairs = [p for r in results if r.ok for p in r.moved]
|
|
2698
|
+
failed = [r for r in results if not r.ok]
|
|
2699
|
+
if pairs:
|
|
2700
|
+
activity.add(kind, message, ok=not failed, files=[b for _, b in pairs], changes=changes,
|
|
2701
|
+
errors=[{"path": r.src, "error": r.error or ""} for r in failed],
|
|
2702
|
+
undo={"type": "moves", "moves": [list(p) for p in pairs]})
|
|
2703
|
+
lib_index.mark_dirty([p for pair in pairs for p in pair if not p.startswith("@")])
|
|
2704
|
+
art_cache.clear()
|
|
2705
|
+
return {"moved": len([r for r in results if r.ok]), "failed": len(failed),
|
|
2706
|
+
"errors": [{"path": r.src, "error": r.error or ""} for r in failed][:20]}
|
|
2707
|
+
|
|
2708
|
+
def library_entries(paths: list[str]) -> list[str]:
|
|
2709
|
+
rels = [p.strip().strip("/") for p in _unique(paths)]
|
|
2710
|
+
for rel in rels:
|
|
2711
|
+
if not rel or rel.startswith("@"):
|
|
2712
|
+
raise HTTPException(422, "Choose files or folders inside your music folder.")
|
|
2713
|
+
library.resolve(rel) # rejects anything outside the library
|
|
2714
|
+
return rels
|
|
2715
|
+
|
|
2716
|
+
@app.post("/api/files/move")
|
|
2717
|
+
def move_entries(body: FilesMoveIn) -> dict:
|
|
2718
|
+
"""Move files and folders into another folder (like Organize: nothing is overwritten, one undo)."""
|
|
2719
|
+
require_library()
|
|
2720
|
+
to = body.to.strip().strip("/")
|
|
2721
|
+
if to.startswith("@") or not library.resolve(to).is_dir():
|
|
2722
|
+
raise HTTPException(404, "That folder isn't there any more.")
|
|
2723
|
+
moves = []
|
|
2724
|
+
rels = library_entries(body.paths)
|
|
2725
|
+
for rel in rels:
|
|
2726
|
+
if to == rel or to.startswith(rel + "/"):
|
|
2727
|
+
raise HTTPException(422, "A folder can't go inside itself.")
|
|
2728
|
+
if _parent(rel) != to:
|
|
2729
|
+
moves += entry_moves(rel, _join(to, rel.rsplit("/", 1)[-1]))
|
|
2730
|
+
where = f"“{to.rsplit('/', 1)[-1]}”" if to else "the top of your library"
|
|
2731
|
+
what = f"“{rels[0].rsplit('/', 1)[-1]}”" if len(rels) == 1 else f"{len(rels)} items"
|
|
2732
|
+
if not moves:
|
|
2733
|
+
return {"moved": 0, "failed": 0, "errors": []}
|
|
2734
|
+
return run_moves(moves, "organize", f"Moved {what} to {where}", [{"key": "folder", "old": _parent(rels[0]), "new": to}])
|
|
2735
|
+
|
|
2736
|
+
@app.post("/api/files/rename")
|
|
2737
|
+
def rename_entry(body: FileRenameIn) -> dict:
|
|
2738
|
+
"""Rename one file (its extension stays; its .lrc follows). Folders use /api/folders/rename."""
|
|
2739
|
+
require_library()
|
|
2740
|
+
(rel,) = library_entries([body.path])
|
|
2741
|
+
src = library.resolve(rel)
|
|
2742
|
+
if src.is_dir():
|
|
2743
|
+
return rename_folder(FolderRenameIn(path=rel, name=body.name))
|
|
2744
|
+
ext = src.suffix
|
|
2745
|
+
stem = body.name.strip()
|
|
2746
|
+
if ext and stem.lower().endswith(ext.lower()):
|
|
2747
|
+
stem = stem[: -len(ext)]
|
|
2748
|
+
new_name = safe_name(stem) + ext
|
|
2749
|
+
new_rel = _join(_parent(rel), new_name)
|
|
2750
|
+
if new_rel == rel:
|
|
2751
|
+
return {"path": rel, "moved": 0, "failed": 0, "errors": []}
|
|
2752
|
+
target = library.resolve(new_rel)
|
|
2753
|
+
if os.path.lexists(target) and not (new_rel.casefold() == rel.casefold() and target.samefile(src)):
|
|
2754
|
+
raise HTTPException(409, f"There's already a file called “{new_name}” here.")
|
|
2755
|
+
out = run_moves(entry_moves(rel, new_rel), "organize", f"Renamed “{src.name}” to “{new_name}”",
|
|
2756
|
+
[{"key": "name", "old": src.name, "new": new_name}])
|
|
2757
|
+
return {"path": new_rel if out["moved"] else rel, **out}
|
|
2758
|
+
|
|
2759
|
+
@app.post("/api/files/delete")
|
|
2760
|
+
def delete_entries(body: FilesIn) -> dict:
|
|
2761
|
+
"""Move files and folders to "Recently deleted" (kept 30 days in the config folder).
|
|
2762
|
+
Nothing is erased: Activity can put them back."""
|
|
2763
|
+
require_library()
|
|
2764
|
+
stamp = time.strftime("%Y%m%d-%H%M%S")
|
|
2765
|
+
rels = library_entries(body.paths)
|
|
2766
|
+
moves = [m for rel in rels for m in entry_moves(rel, f"{DELETED}/{stamp}/{rel}")]
|
|
2767
|
+
what = f"“{rels[0].rsplit('/', 1)[-1]}”" if len(rels) == 1 else f"{len(rels)} items"
|
|
2768
|
+
out = run_moves(moves, "delete", f"Deleted {what} (in Recently deleted for 30 days)",
|
|
2769
|
+
[{"key": "location", "old": _parent(rels[0]), "new": "(recently deleted)"}])
|
|
2770
|
+
for rel in rels: # a deleted folder's empty subfolders go too
|
|
2771
|
+
src = library.resolve(rel)
|
|
2772
|
+
if src.is_dir():
|
|
2773
|
+
for dirpath, _, _ in sorted(os.walk(src), key=lambda x: -len(x[0])):
|
|
2774
|
+
with contextlib.suppress(OSError):
|
|
2775
|
+
os.rmdir(dirpath)
|
|
2776
|
+
return out
|
|
2777
|
+
|
|
2778
|
+
@app.get("/api/files/info")
|
|
2779
|
+
def entry_info(path: str = Query(..., max_length=MAX_PATH_CHARS, description="File or folder, relative to the music folder")) -> dict:
|
|
2780
|
+
"""Get info: format, quality, size and dates of a file, or what a folder holds."""
|
|
2781
|
+
require_library()
|
|
2782
|
+
target = library.resolve(path)
|
|
2783
|
+
info = folder_info(target) if target.is_dir() else file_info(engine, target)
|
|
2784
|
+
return {"path": path.strip("/"), **info}
|
|
2785
|
+
|
|
2786
|
+
log_buffer = shared_buffer()
|
|
2787
|
+
|
|
2788
|
+
@app.get("/api/logs")
|
|
2789
|
+
def server_log(after: int = Query(0, ge=0, description="Only lines after this id")) -> dict:
|
|
2790
|
+
"""Advanced mode: Codetta's own recent log lines (memory only, the last 500), for the live view.
|
|
2791
|
+
No visitor records, and anything shaped like a secret is masked."""
|
|
2792
|
+
lines = log_buffer.since(after)
|
|
2793
|
+
return {"lines": lines, "last": lines[-1]["id"] if lines else after}
|
|
2794
|
+
|
|
2795
|
+
@app.get("/api/tagnames")
|
|
2796
|
+
def tag_names(format: str = Query(..., max_length=20, description="A file format, e.g. flac, mp3, m4a")) -> dict:
|
|
2797
|
+
"""Advanced mode: how this format stores each of Codetta's fields (None: it can't)."""
|
|
2798
|
+
return {"format": format, "names": native_names(format.lower(), [f.key for f in FIELDS])}
|
|
2799
|
+
|
|
2800
|
+
@app.get("/api/folders")
|
|
2801
|
+
def list_subfolders(path: str = Query("", max_length=MAX_PATH_CHARS, description="Folder, relative to the music folder")) -> dict:
|
|
2802
|
+
"""Just the subfolders of one folder (for the "Move to" picker): no tags are read."""
|
|
2803
|
+
require_library()
|
|
2804
|
+
if path.strip("/").startswith("@"):
|
|
2805
|
+
raise HTTPException(422, "Choose a folder inside your music folder.")
|
|
2806
|
+
listing = library.list_folder(path)
|
|
2807
|
+
return {"path": listing.path, "folders": [{"name": f.rsplit("/", 1)[-1], "path": f} for f in listing.folders]}
|
|
2808
|
+
|
|
2646
2809
|
def apply_per_file(per_file: dict[str, dict], message: str) -> tuple[list[str], list[dict]]:
|
|
2647
2810
|
"""Write different tag changes to each file (safe writes, a few at once) and log them as
|
|
2648
2811
|
one undoable activity entry. Returns (files done, failures)."""
|