codetta 0.8.1__py3-none-any.whl
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/CHANGELOG.md +153 -0
- codetta/__init__.py +8 -0
- codetta/__main__.py +5 -0
- codetta/cli/__init__.py +0 -0
- codetta/cli/__main__.py +59 -0
- codetta/cli/run.py +129 -0
- codetta/core/__init__.py +0 -0
- codetta/core/acoustid.py +225 -0
- codetta/core/activity.py +161 -0
- codetta/core/artwork.py +238 -0
- codetta/core/auth.py +362 -0
- codetta/core/avatar.py +92 -0
- codetta/core/changelog.py +51 -0
- codetta/core/connections.py +159 -0
- codetta/core/describe.py +69 -0
- codetta/core/engine.py +470 -0
- codetta/core/health.py +520 -0
- codetta/core/inbox.py +195 -0
- codetta/core/index.py +672 -0
- codetta/core/library.py +177 -0
- codetta/core/musicbrainz.py +662 -0
- codetta/core/notifications.py +77 -0
- codetta/core/onboarding.py +39 -0
- codetta/core/organize.py +490 -0
- codetta/core/plugins.py +183 -0
- codetta/core/presets.py +452 -0
- codetta/core/providers.py +203 -0
- codetta/core/rawtags.py +135 -0
- codetta/core/slskd.py +650 -0
- codetta/core/tagmap.py +538 -0
- codetta/core/undo.py +186 -0
- codetta/core/updates.py +132 -0
- codetta/plugins/__init__.py +63 -0
- codetta/plugins/builtin/__init__.py +3 -0
- codetta/plugins/builtin/tidy.py +70 -0
- codetta/web/__init__.py +0 -0
- codetta/web/app.py +2909 -0
- codetta/web/security.py +170 -0
- codetta/web/static/app.css +2684 -0
- codetta/web/static/app.js +5694 -0
- codetta/web/static/apple-touch-icon.png +0 -0
- codetta/web/static/fonts/LICENSE-Inter.txt +93 -0
- codetta/web/static/fonts/LICENSE-SchibstedGrotesk.txt +93 -0
- codetta/web/static/fonts/inter-cyrillic.woff2 +0 -0
- codetta/web/static/fonts/schibsted-grotesk.woff2 +0 -0
- codetta/web/static/icon.svg +1 -0
- codetta/web/static/icons/codetta-dark.png +0 -0
- codetta/web/static/icons/codetta-dark.svg +1 -0
- codetta/web/static/icons/codetta-dark.webp +0 -0
- codetta/web/static/icons/codetta-light.png +0 -0
- codetta/web/static/icons/codetta-light.svg +1 -0
- codetta/web/static/icons/codetta-light.webp +0 -0
- codetta/web/static/icons/codetta.png +0 -0
- codetta/web/static/icons/codetta.svg +1 -0
- codetta/web/static/icons/codetta.webp +0 -0
- codetta/web/static/index.html +473 -0
- codetta/web/static/theme.js +12 -0
- codetta-0.8.1.dist-info/METADATA +282 -0
- codetta-0.8.1.dist-info/RECORD +63 -0
- codetta-0.8.1.dist-info/WHEEL +5 -0
- codetta-0.8.1.dist-info/entry_points.txt +2 -0
- codetta-0.8.1.dist-info/licenses/LICENSE +661 -0
- codetta-0.8.1.dist-info/top_level.txt +1 -0
codetta/core/tagmap.py
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
"""One shared tag vocabulary across every audio format.
|
|
2
|
+
|
|
3
|
+
FLAC, OGG Vorbis and Opus store tags as free-form "Vorbis comments", so any
|
|
4
|
+
name works (``MOOD=Chill``). MP3 (ID3) and M4A (MP4 atoms) only understand a
|
|
5
|
+
fixed set of fields, and mutagen's "easy" interface leaves out many tags that
|
|
6
|
+
Navidrome / OpenSubsonic clients display (mood, release type, label, credits,
|
|
7
|
+
multi-artist lists, ...).
|
|
8
|
+
|
|
9
|
+
Importing this module registers those missing names with mutagen, using the
|
|
10
|
+
same storage locations MusicBrainz Picard uses, which is what Navidrome (via
|
|
11
|
+
TagLib) reads. After that, ``engine.update_tags(path, {"mood": "Chill"})``
|
|
12
|
+
works the same on every format.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
|
|
19
|
+
from mutagen._vorbis import is_valid_key as _is_valid_vorbis_key
|
|
20
|
+
from mutagen.apev2 import TEXT as _APE_TEXT
|
|
21
|
+
from mutagen.apev2 import is_valid_apev2_key
|
|
22
|
+
from mutagen.asf import ASFBoolAttribute, ASFUnicodeAttribute
|
|
23
|
+
from mutagen.easyid3 import EasyID3
|
|
24
|
+
from mutagen.easymp4 import EasyMP4Tags
|
|
25
|
+
from mutagen.id3 import COMM, MVIN, TIPL, USLT
|
|
26
|
+
|
|
27
|
+
# Formats grouped by how they store tags. Each family shares one mapping.
|
|
28
|
+
VORBIS_FORMATS = frozenset({"flac", "ogg", "opus", "oggflac", "speex"}) # free-form comments
|
|
29
|
+
ID3_FORMATS = frozenset({"mp3", "mp2", "tta", "wav", "aiff", "dsf"}) # ID3 frames
|
|
30
|
+
ID3_CONTAINERS = frozenset({"wav", "aiff", "dsf"}) # ID3 inside another container (no "easy" class)
|
|
31
|
+
APE_FORMATS = frozenset({"wavpack"}) # APEv2 items
|
|
32
|
+
ASF_FORMATS = frozenset({"wma"}) # ASF attributes
|
|
33
|
+
MP4_FORMATS = frozenset({"m4a"})
|
|
34
|
+
|
|
35
|
+
# Old mutagen names that now duplicate one of our names (same underlying
|
|
36
|
+
# field). They are hidden when reading so each value shows up once.
|
|
37
|
+
_ID3_ALIASES = {
|
|
38
|
+
"organization": "label",
|
|
39
|
+
"musicbrainz_albumtype": "releasetype",
|
|
40
|
+
"musicbrainz_albumstatus": "releasestatus",
|
|
41
|
+
}
|
|
42
|
+
HIDDEN_ALIASES: dict[str, dict[str, str]] = {
|
|
43
|
+
**{fmt: _ID3_ALIASES for fmt in ID3_FORMATS},
|
|
44
|
+
"m4a": {
|
|
45
|
+
"musicbrainz_albumtype": "releasetype",
|
|
46
|
+
"musicbrainz_albumstatus": "releasestatus",
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class Field:
|
|
53
|
+
"""A well-known tag, as shown in the editor."""
|
|
54
|
+
|
|
55
|
+
key: str
|
|
56
|
+
label: str
|
|
57
|
+
group: str
|
|
58
|
+
multi: bool = False # commonly holds several values (e.g. two artists)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# The editor's fields, in display order. Any other tag a file has still shows
|
|
62
|
+
# up (under "Custom"); this list just gives the common ones a home and a label.
|
|
63
|
+
FIELDS: tuple[Field, ...] = (
|
|
64
|
+
Field("title", "Title", "Basics"),
|
|
65
|
+
Field("artist", "Artist", "Basics", multi=True),
|
|
66
|
+
Field("album", "Album", "Basics"),
|
|
67
|
+
Field("albumartist", "Album artist", "Basics"),
|
|
68
|
+
Field("tracknumber", "Track", "Basics"),
|
|
69
|
+
Field("discnumber", "Disc", "Basics"),
|
|
70
|
+
Field("date", "Date", "Basics"),
|
|
71
|
+
Field("genre", "Genre", "Basics", multi=True),
|
|
72
|
+
Field("artists", "Artists (all)", "Credits", multi=True),
|
|
73
|
+
Field("albumartists", "Album artists (all)", "Credits", multi=True),
|
|
74
|
+
Field("composer", "Composer", "Credits", multi=True),
|
|
75
|
+
Field("lyricist", "Lyricist", "Credits", multi=True),
|
|
76
|
+
Field("producer", "Producer", "Credits", multi=True),
|
|
77
|
+
Field("engineer", "Engineer", "Credits", multi=True),
|
|
78
|
+
Field("mixer", "Mixer", "Credits", multi=True),
|
|
79
|
+
Field("djmixer", "DJ mixer", "Credits", multi=True),
|
|
80
|
+
Field("arranger", "Arranger", "Credits", multi=True),
|
|
81
|
+
Field("conductor", "Conductor", "Credits", multi=True),
|
|
82
|
+
Field("releasetype", "Release type", "Release"),
|
|
83
|
+
Field("releasestatus", "Release status", "Release"),
|
|
84
|
+
Field("label", "Label", "Release", multi=True),
|
|
85
|
+
Field("catalognumber", "Catalog number", "Release"),
|
|
86
|
+
Field("barcode", "Barcode", "Release"),
|
|
87
|
+
Field("media", "Media", "Release"),
|
|
88
|
+
Field("originaldate", "Original date", "Release"),
|
|
89
|
+
Field("releasecountry", "Release country", "Release"),
|
|
90
|
+
Field("discsubtitle", "Disc subtitle", "Release"),
|
|
91
|
+
Field("compilation", "Compilation (1 = yes)", "Release"),
|
|
92
|
+
Field("titlesort", "Title sort", "Sorting"),
|
|
93
|
+
Field("artistsort", "Artist sort", "Sorting"),
|
|
94
|
+
Field("albumsort", "Album sort", "Sorting"),
|
|
95
|
+
Field("albumartistsort", "Album artist sort", "Sorting"),
|
|
96
|
+
Field("composersort", "Composer sort", "Sorting"),
|
|
97
|
+
# Classical. Keys follow how Vorbis comments store them (as Picard writes):
|
|
98
|
+
# MOVEMENTNAME is the name, MOVEMENT the number.
|
|
99
|
+
Field("work", "Work", "Classical"),
|
|
100
|
+
Field("movementname", "Movement", "Classical"),
|
|
101
|
+
Field("movement", "Movement number", "Classical"),
|
|
102
|
+
Field("movementtotal", "Movement count", "Classical"),
|
|
103
|
+
Field("showmovement", "Show movement (1 = yes)", "Classical"),
|
|
104
|
+
Field("lyrics", "Lyrics", "Lyrics"), # plain text or synced LRC ("[01:23.45] line")
|
|
105
|
+
Field("subtitle", "Subtitle", "More"),
|
|
106
|
+
Field("mood", "Mood", "More", multi=True),
|
|
107
|
+
Field("bpm", "BPM", "More"),
|
|
108
|
+
Field("isrc", "ISRC", "More"),
|
|
109
|
+
Field("language", "Language", "More"),
|
|
110
|
+
Field("copyright", "Copyright", "More"),
|
|
111
|
+
Field("grouping", "Grouping", "More"),
|
|
112
|
+
Field("comment", "Comment", "More"),
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def is_tag_supported(format_name: str, key: str) -> bool:
|
|
117
|
+
"""Can a file of ``format_name`` store a tag called ``key``?"""
|
|
118
|
+
key = key.lower()
|
|
119
|
+
if format_name in VORBIS_FORMATS:
|
|
120
|
+
return bool(key) and _is_valid_vorbis_key(key)
|
|
121
|
+
if format_name in ID3_FORMATS:
|
|
122
|
+
return key in EasyID3.valid_keys
|
|
123
|
+
if format_name in MP4_FORMATS:
|
|
124
|
+
return key in EasyMP4Tags.Set
|
|
125
|
+
if format_name in APE_FORMATS:
|
|
126
|
+
name = _APE_NAMES.get(key, key) # reserved names are blocked in any case ("id3" too)
|
|
127
|
+
return is_valid_apev2_key(name) and name.upper() not in ("ID3", "TAG", "OGGS", "MP+")
|
|
128
|
+
if format_name in ASF_FORMATS:
|
|
129
|
+
return 0 < len(key) <= 255 and key.isprintable() and _asf_name(key) not in _ASF_SYSTEM
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def tag_view(audio, format_name: str, create: bool = False):
|
|
134
|
+
"""The file's tags as a mapping of Codetta tag names -> lists of strings.
|
|
135
|
+
|
|
136
|
+
For most formats that's mutagen's own (easy) tag object. ID3-in-a-container
|
|
137
|
+
formats (WAV, AIFF, DSF), APEv2 and ASF get a small adapter here, so the
|
|
138
|
+
engine treats every format the same way. ``create`` adds empty tags first.
|
|
139
|
+
"""
|
|
140
|
+
if audio.tags is None:
|
|
141
|
+
if not create:
|
|
142
|
+
return {}
|
|
143
|
+
audio.add_tags()
|
|
144
|
+
if format_name in ID3_CONTAINERS:
|
|
145
|
+
view = EasyID3()
|
|
146
|
+
view._EasyID3__id3 = audio.tags # EasyID3 is a thin layer over an ID3 object
|
|
147
|
+
return view
|
|
148
|
+
if format_name in APE_FORMATS:
|
|
149
|
+
return _APEView(audio.tags)
|
|
150
|
+
if format_name in ASF_FORMATS:
|
|
151
|
+
return _ASFView(audio.tags)
|
|
152
|
+
return audio.tags
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class _View:
|
|
156
|
+
"""Minimal dict-like base: keys(), items(), get/set/delete by Codetta name."""
|
|
157
|
+
|
|
158
|
+
def keys(self): # pragma: no cover - overridden
|
|
159
|
+
raise NotImplementedError
|
|
160
|
+
|
|
161
|
+
def items(self):
|
|
162
|
+
out = []
|
|
163
|
+
for key in self.keys():
|
|
164
|
+
try:
|
|
165
|
+
out.append((key, self[key]))
|
|
166
|
+
except KeyError:
|
|
167
|
+
continue
|
|
168
|
+
return out
|
|
169
|
+
|
|
170
|
+
def __contains__(self, key):
|
|
171
|
+
try:
|
|
172
|
+
self[key]
|
|
173
|
+
except KeyError:
|
|
174
|
+
return False
|
|
175
|
+
return True
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# --- APEv2 (WavPack) ---------------------------------------------------------
|
|
179
|
+
|
|
180
|
+
# APEv2 item names are case-insensitive. Standard names where they differ from
|
|
181
|
+
# ours (as Picard writes them); everything else uses our name.
|
|
182
|
+
_APE_NAMES = {
|
|
183
|
+
"tracknumber": "Track",
|
|
184
|
+
"discnumber": "Disc",
|
|
185
|
+
"date": "Year",
|
|
186
|
+
"albumartist": "Album Artist",
|
|
187
|
+
"releasetype": "MUSICBRAINZ_ALBUMTYPE",
|
|
188
|
+
"releasestatus": "MUSICBRAINZ_ALBUMSTATUS",
|
|
189
|
+
}
|
|
190
|
+
_FROM_APE = {v.lower(): k for k, v in _APE_NAMES.items()}
|
|
191
|
+
_FIELD_KEYS = None # filled in below, once FIELDS exists
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class _APEView(_View):
|
|
195
|
+
def __init__(self, tags):
|
|
196
|
+
self.tags = tags
|
|
197
|
+
|
|
198
|
+
def keys(self):
|
|
199
|
+
return [_FROM_APE.get(k.lower(), k.lower()) for k in self.tags.keys() if self.tags[k].kind == _APE_TEXT]
|
|
200
|
+
|
|
201
|
+
def _name(self, key):
|
|
202
|
+
if key in _APE_NAMES:
|
|
203
|
+
return _APE_NAMES[key]
|
|
204
|
+
return key.title() if key in _FIELD_KEYS else key # "Title", "Genre"... like other taggers
|
|
205
|
+
|
|
206
|
+
def __getitem__(self, key):
|
|
207
|
+
value = self.tags.get(self._name(key))
|
|
208
|
+
if value is None or value.kind != _APE_TEXT:
|
|
209
|
+
raise KeyError(key)
|
|
210
|
+
return list(value)
|
|
211
|
+
|
|
212
|
+
def __setitem__(self, key, values):
|
|
213
|
+
self.tags[self._name(key)] = list(values)
|
|
214
|
+
|
|
215
|
+
def __delitem__(self, key):
|
|
216
|
+
del self.tags[self._name(key)]
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
# --- ASF (WMA) -----------------------------------------------------------------
|
|
220
|
+
|
|
221
|
+
# Codetta name -> ASF attribute, following Picard.
|
|
222
|
+
_ASF_NAMES = {
|
|
223
|
+
"title": "Title",
|
|
224
|
+
"artist": "Author",
|
|
225
|
+
"album": "WM/AlbumTitle",
|
|
226
|
+
"albumartist": "WM/AlbumArtist",
|
|
227
|
+
"tracknumber": "WM/TrackNumber",
|
|
228
|
+
"discnumber": "WM/PartOfSet",
|
|
229
|
+
"date": "WM/Year",
|
|
230
|
+
"genre": "WM/Genre",
|
|
231
|
+
"artists": "WM/ARTISTS",
|
|
232
|
+
"composer": "WM/Composer",
|
|
233
|
+
"lyricist": "WM/Writer",
|
|
234
|
+
"conductor": "WM/Conductor",
|
|
235
|
+
"producer": "WM/Producer",
|
|
236
|
+
"label": "WM/Publisher",
|
|
237
|
+
"catalognumber": "WM/CatalogNo",
|
|
238
|
+
"barcode": "WM/Barcode",
|
|
239
|
+
"isrc": "WM/ISRC",
|
|
240
|
+
"media": "WM/Media",
|
|
241
|
+
"mood": "WM/Mood",
|
|
242
|
+
"bpm": "WM/BeatsPerMinute",
|
|
243
|
+
"language": "WM/Language",
|
|
244
|
+
"copyright": "Copyright",
|
|
245
|
+
"grouping": "WM/ContentGroupDescription",
|
|
246
|
+
"comment": "Description",
|
|
247
|
+
"discsubtitle": "WM/SetSubTitle",
|
|
248
|
+
"compilation": "WM/IsCompilation",
|
|
249
|
+
"originaldate": "WM/OriginalReleaseTime",
|
|
250
|
+
"releasetype": "MusicBrainz/Album Type",
|
|
251
|
+
"releasestatus": "MusicBrainz/Album Status",
|
|
252
|
+
"releasecountry": "MusicBrainz/Album Release Country",
|
|
253
|
+
"titlesort": "WM/TitleSortOrder",
|
|
254
|
+
"artistsort": "WM/ArtistSortOrder",
|
|
255
|
+
"albumsort": "WM/AlbumSortOrder",
|
|
256
|
+
"albumartistsort": "WM/AlbumArtistSortOrder",
|
|
257
|
+
"composersort": "WM/ComposerSortOrder",
|
|
258
|
+
"work": "WM/Work",
|
|
259
|
+
"subtitle": "WM/SubTitle",
|
|
260
|
+
"lyrics": "WM/Lyrics",
|
|
261
|
+
"script": "WM/Script",
|
|
262
|
+
"musicbrainz_trackid": "MusicBrainz/Track Id",
|
|
263
|
+
"musicbrainz_releasetrackid": "MusicBrainz/Release Track Id",
|
|
264
|
+
"musicbrainz_albumid": "MusicBrainz/Album Id",
|
|
265
|
+
"musicbrainz_artistid": "MusicBrainz/Artist Id",
|
|
266
|
+
"musicbrainz_albumartistid": "MusicBrainz/Album Artist Id",
|
|
267
|
+
"musicbrainz_releasegroupid": "MusicBrainz/Release Group Id",
|
|
268
|
+
"musicbrainz_workid": "MusicBrainz/Work Id",
|
|
269
|
+
}
|
|
270
|
+
_FROM_ASF = {v.lower(): k for k, v in _ASF_NAMES.items()}
|
|
271
|
+
# Technical attributes written by encoders: never shown or edited as tags.
|
|
272
|
+
_ASF_SYSTEM = frozenset(n.lower() for n in (
|
|
273
|
+
"WM/Picture", "WMFSDKVersion", "WMFSDKNeeded", "IsVBR", "DeviceConformanceTemplate",
|
|
274
|
+
"WM/MediaPrimaryClassID", "WM/WMContentID", "WM/WMCollectionID", "WM/WMCollectionGroupID",
|
|
275
|
+
"WM/EncodingTime", "WM/ToolName", "WM/ToolVersion", "WM/UniqueFileIdentifier",
|
|
276
|
+
))
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _asf_name(key: str) -> str:
|
|
280
|
+
return _ASF_NAMES.get(key, key).lower()
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class _ASFView(_View):
|
|
284
|
+
def __init__(self, tags):
|
|
285
|
+
self.tags = tags
|
|
286
|
+
|
|
287
|
+
def _native(self, key):
|
|
288
|
+
"""The attribute name actually used in this file (names are case-insensitive)."""
|
|
289
|
+
wanted = _asf_name(key)
|
|
290
|
+
for name in self.tags.keys():
|
|
291
|
+
if name.lower() == wanted:
|
|
292
|
+
return name
|
|
293
|
+
return _ASF_NAMES.get(key, key)
|
|
294
|
+
|
|
295
|
+
@staticmethod
|
|
296
|
+
def _text(attr):
|
|
297
|
+
if isinstance(attr, ASFBoolAttribute):
|
|
298
|
+
return "1" if attr.value else "0"
|
|
299
|
+
value = attr.value
|
|
300
|
+
return value if isinstance(value, str) else str(value) if isinstance(value, int) else None
|
|
301
|
+
|
|
302
|
+
def keys(self):
|
|
303
|
+
out = []
|
|
304
|
+
for name in self.tags.keys():
|
|
305
|
+
if name.lower() in _ASF_SYSTEM:
|
|
306
|
+
continue
|
|
307
|
+
if any(self._text(a) is not None for a in self.tags[name]):
|
|
308
|
+
out.append(_FROM_ASF.get(name.lower(), name.lower()))
|
|
309
|
+
return out
|
|
310
|
+
|
|
311
|
+
def __getitem__(self, key):
|
|
312
|
+
name = self._native(key)
|
|
313
|
+
if name.lower() in _ASF_SYSTEM or name not in self.tags.keys():
|
|
314
|
+
raise KeyError(key)
|
|
315
|
+
values = [t for t in (self._text(a) for a in self.tags[name]) if t is not None]
|
|
316
|
+
if not values:
|
|
317
|
+
raise KeyError(key)
|
|
318
|
+
return values
|
|
319
|
+
|
|
320
|
+
def __setitem__(self, key, values):
|
|
321
|
+
self.tags[self._native(key)] = [ASFUnicodeAttribute(v) for v in values]
|
|
322
|
+
|
|
323
|
+
def __delitem__(self, key):
|
|
324
|
+
del self.tags[self._native(key)]
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
# --- MP3 (ID3) ---------------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
# Plain text frames / user-defined TXXX frames.
|
|
330
|
+
EasyID3.RegisterTextKey("label", "TPUB")
|
|
331
|
+
EasyID3.RegisterTXXXKey("releasetype", "MusicBrainz Album Type")
|
|
332
|
+
EasyID3.RegisterTXXXKey("releasestatus", "MusicBrainz Album Status")
|
|
333
|
+
EasyID3.RegisterTXXXKey("artists", "ARTISTS")
|
|
334
|
+
EasyID3.RegisterTXXXKey("albumartists", "ALBUMARTISTS")
|
|
335
|
+
EasyID3.RegisterTextKey("subtitle", "TIT3")
|
|
336
|
+
EasyID3.RegisterTextKey("movementname", "MVNM")
|
|
337
|
+
EasyID3.RegisterTXXXKey("work", "WORK")
|
|
338
|
+
EasyID3.RegisterTXXXKey("showmovement", "SHOWMOVEMENT")
|
|
339
|
+
EasyID3.RegisterTXXXKey("script", "SCRIPT")
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _register_id3_movement() -> None:
|
|
343
|
+
"""``movement`` / ``movementtotal`` share the MVIN frame ("2/4")."""
|
|
344
|
+
|
|
345
|
+
def parts(id3):
|
|
346
|
+
frame = id3.get("MVIN")
|
|
347
|
+
text = str(frame.text[0]) if frame and frame.text else ""
|
|
348
|
+
number, _, total = text.partition("/")
|
|
349
|
+
return number.strip(), total.strip()
|
|
350
|
+
|
|
351
|
+
def write(id3, number, total):
|
|
352
|
+
id3.delall("MVIN")
|
|
353
|
+
if number or total:
|
|
354
|
+
id3.add(MVIN(encoding=3, text=[f"{number}/{total}" if total else number]))
|
|
355
|
+
|
|
356
|
+
def make(index):
|
|
357
|
+
def get(id3, key):
|
|
358
|
+
value = parts(id3)[index]
|
|
359
|
+
if not value:
|
|
360
|
+
raise KeyError(key)
|
|
361
|
+
return [value]
|
|
362
|
+
|
|
363
|
+
def set_(id3, key, value):
|
|
364
|
+
if len(value) != 1:
|
|
365
|
+
raise ValueError(f"{key} takes a single value")
|
|
366
|
+
current = list(parts(id3))
|
|
367
|
+
current[index] = value[0].strip()
|
|
368
|
+
write(id3, *current)
|
|
369
|
+
|
|
370
|
+
def delete(id3, key):
|
|
371
|
+
current = list(parts(id3))
|
|
372
|
+
current[index] = ""
|
|
373
|
+
write(id3, *current)
|
|
374
|
+
|
|
375
|
+
return get, set_, delete
|
|
376
|
+
|
|
377
|
+
EasyID3.RegisterKey("movement", *make(0))
|
|
378
|
+
EasyID3.RegisterKey("movementtotal", *make(1))
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
_register_id3_movement()
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _register_id3_comment() -> None:
|
|
385
|
+
"""``comment`` -> COMM frame with an empty description."""
|
|
386
|
+
|
|
387
|
+
def keys(id3):
|
|
388
|
+
# Leave other comments alone (e.g. iTunes' "iTunNORM" volume data).
|
|
389
|
+
return [k for k in id3.keys() if k.startswith("COMM:") and id3[k].desc == ""]
|
|
390
|
+
|
|
391
|
+
def get(id3, key):
|
|
392
|
+
values = [text for k in keys(id3) for text in id3[k].text]
|
|
393
|
+
if not values:
|
|
394
|
+
raise KeyError(key)
|
|
395
|
+
return values
|
|
396
|
+
|
|
397
|
+
def delete(id3, key):
|
|
398
|
+
for k in keys(id3):
|
|
399
|
+
del id3[k]
|
|
400
|
+
|
|
401
|
+
def set_(id3, key, value):
|
|
402
|
+
delete(id3, key)
|
|
403
|
+
id3.add(COMM(encoding=3, lang="eng", desc="", text=list(value)))
|
|
404
|
+
|
|
405
|
+
EasyID3.RegisterKey("comment", get, set_, delete)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _register_id3_credit(key: str, role: str) -> None:
|
|
409
|
+
"""Credits like engineer/mixer live in the TIPL "involved people" frame.
|
|
410
|
+
|
|
411
|
+
TIPL holds [role, name] pairs, e.g. [["engineer", "Ann"], ["mix", "Bob"]].
|
|
412
|
+
Each Codetta tag reads and writes only the pairs for its own role.
|
|
413
|
+
"""
|
|
414
|
+
|
|
415
|
+
def people(id3):
|
|
416
|
+
frame = id3.get("TIPL")
|
|
417
|
+
return list(frame.people) if frame else []
|
|
418
|
+
|
|
419
|
+
def get(id3, k):
|
|
420
|
+
names = [name for r, name in people(id3) if r == role]
|
|
421
|
+
if not names:
|
|
422
|
+
raise KeyError(k)
|
|
423
|
+
return names
|
|
424
|
+
|
|
425
|
+
def set_(id3, k, value):
|
|
426
|
+
others = [[r, name] for r, name in people(id3) if r != role]
|
|
427
|
+
pairs = others + [[role, v] for v in value]
|
|
428
|
+
id3.delall("TIPL")
|
|
429
|
+
if pairs:
|
|
430
|
+
id3.add(TIPL(encoding=3, people=pairs))
|
|
431
|
+
|
|
432
|
+
def delete(id3, k):
|
|
433
|
+
set_(id3, k, [])
|
|
434
|
+
|
|
435
|
+
EasyID3.RegisterKey(key, get, set_, delete)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
_register_id3_comment()
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def _register_id3_lyrics() -> None:
|
|
442
|
+
"""``lyrics`` -> the USLT frame with an empty description (what Picard,
|
|
443
|
+
Navidrome and most players use; synced LRC text works here too)."""
|
|
444
|
+
|
|
445
|
+
def keys(id3):
|
|
446
|
+
return [k for k in id3.keys() if k.startswith("USLT:") and id3[k].desc == ""]
|
|
447
|
+
|
|
448
|
+
def get(id3, key):
|
|
449
|
+
values = [id3[k].text for k in keys(id3) if id3[k].text]
|
|
450
|
+
if not values:
|
|
451
|
+
raise KeyError(key)
|
|
452
|
+
return values
|
|
453
|
+
|
|
454
|
+
def delete(id3, key):
|
|
455
|
+
for k in keys(id3):
|
|
456
|
+
del id3[k]
|
|
457
|
+
|
|
458
|
+
def set_(id3, key, value):
|
|
459
|
+
delete(id3, key)
|
|
460
|
+
id3.add(USLT(encoding=3, lang="eng", desc="", text="\n".join(value)))
|
|
461
|
+
|
|
462
|
+
EasyID3.RegisterKey("lyrics", get, set_, delete)
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
_register_id3_lyrics()
|
|
466
|
+
for _key, _role in {
|
|
467
|
+
"engineer": "engineer",
|
|
468
|
+
"mixer": "mix",
|
|
469
|
+
"producer": "producer",
|
|
470
|
+
"djmixer": "DJ-mix",
|
|
471
|
+
}.items():
|
|
472
|
+
_register_id3_credit(_key, _role)
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
# --- M4A (MP4 atoms) -----------------------------------------------------------
|
|
476
|
+
|
|
477
|
+
EasyMP4Tags.RegisterTextKey("composer", "\xa9wrt")
|
|
478
|
+
EasyMP4Tags.RegisterTextKey("work", "\xa9wrk")
|
|
479
|
+
EasyMP4Tags.RegisterTextKey("lyrics", "\xa9lyr")
|
|
480
|
+
EasyMP4Tags.RegisterTextKey("movementname", "\xa9mvn")
|
|
481
|
+
EasyMP4Tags.RegisterIntKey("movement", "\xa9mvi", min_value=0, max_value=65535)
|
|
482
|
+
EasyMP4Tags.RegisterIntKey("movementtotal", "\xa9mvc", min_value=0, max_value=65535)
|
|
483
|
+
EasyMP4Tags.RegisterIntKey("showmovement", "shwm", min_value=0, max_value=1)
|
|
484
|
+
|
|
485
|
+
# Everything else uses iTunes-style "freeform" atoms
|
|
486
|
+
# (----:com.apple.iTunes:NAME), as Picard does.
|
|
487
|
+
for _key, _atom_name in {
|
|
488
|
+
"artists": "ARTISTS",
|
|
489
|
+
"albumartists": "ALBUMARTISTS",
|
|
490
|
+
"originaldate": "ORIGINALDATE",
|
|
491
|
+
"discsubtitle": "DISCSUBTITLE",
|
|
492
|
+
"releasetype": "MusicBrainz Album Type",
|
|
493
|
+
"releasestatus": "MusicBrainz Album Status",
|
|
494
|
+
"label": "LABEL",
|
|
495
|
+
"catalognumber": "CATALOGNUMBER",
|
|
496
|
+
"barcode": "BARCODE",
|
|
497
|
+
"isrc": "ISRC",
|
|
498
|
+
"media": "MEDIA",
|
|
499
|
+
"mood": "MOOD",
|
|
500
|
+
"lyricist": "LYRICIST",
|
|
501
|
+
"conductor": "CONDUCTOR",
|
|
502
|
+
"arranger": "ARRANGER",
|
|
503
|
+
"engineer": "ENGINEER",
|
|
504
|
+
"mixer": "MIXER",
|
|
505
|
+
"producer": "PRODUCER",
|
|
506
|
+
"djmixer": "DJMIXER",
|
|
507
|
+
"language": "LANGUAGE",
|
|
508
|
+
"subtitle": "SUBTITLE",
|
|
509
|
+
"script": "SCRIPT",
|
|
510
|
+
# mutagen already knows the album/artist/track IDs; these complete Picard's set.
|
|
511
|
+
"musicbrainz_releasetrackid": "MusicBrainz Release Track Id",
|
|
512
|
+
"musicbrainz_releasegroupid": "MusicBrainz Release Group Id",
|
|
513
|
+
"musicbrainz_workid": "MusicBrainz Work Id",
|
|
514
|
+
}.items():
|
|
515
|
+
EasyMP4Tags.RegisterFreeformKey(_key, _atom_name)
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def _register_mp4_compilation() -> None:
|
|
519
|
+
"""``compilation`` -> the boolean ``cpil`` atom. Values are "1" or "0"."""
|
|
520
|
+
|
|
521
|
+
def get(tags, key):
|
|
522
|
+
return ["1" if tags["cpil"] else "0"]
|
|
523
|
+
|
|
524
|
+
def set_(tags, key, value):
|
|
525
|
+
if len(value) != 1 or value[0] not in ("0", "1"):
|
|
526
|
+
raise ValueError("compilation must be '1' or '0'")
|
|
527
|
+
tags["cpil"] = value[0] == "1"
|
|
528
|
+
|
|
529
|
+
def delete(tags, key):
|
|
530
|
+
del tags["cpil"]
|
|
531
|
+
|
|
532
|
+
EasyMP4Tags.RegisterKey("compilation", get, set_, delete)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
_register_mp4_compilation()
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
_FIELD_KEYS = frozenset(f.key for f in FIELDS)
|