v0.96.1: songs are named in Unicode NFC in the music folder, since Syncthing renames anything else under the library (a Bengali YouTube title lost its file that way); a song already renamed so is followed

This commit is contained in:
2026-11-17 22:21:29 -08:00
parent 9f2f9222dd
commit b78b6c5275
6 changed files with 106 additions and 4 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.96.0"
__version__ = "0.96.1"
+6 -1
View File
@@ -2931,7 +2931,12 @@ class MainWindow(QMainWindow):
def _on_track_missing(self, track):
"""A track's file is gone (moved/renamed outside lintunes). Offer to
relocate it manually; on success, repoint the track and resume."""
relocate it manually; on success, repoint the track and resume. One
renamed to its NFC spelling (Syncthing does that) is followed
without asking."""
if self._manager.repair_location(track):
QTimer.singleShot(0, self.player.retry_current)
return
box = QMessageBox(self)
box.setIcon(QMessageBox.Icon.Warning)
box.setWindowTitle("Can't play track")
+8
View File
@@ -1,5 +1,6 @@
import logging
import re
import unicodedata
import shutil
from datetime import datetime, timezone
from pathlib import Path
@@ -20,6 +21,13 @@ def is_audio_file(path: Path) -> bool:
def sanitize_component(name: str) -> str:
"""A safe file or folder name, in Unicode NFC (Round 130): Syncthing
renames any name that isn't NFC to its NFC spelling as it scans (except
on a Mac), so a song imported as "ঘর বাড়ি…" from a YouTube title was
renamed under the library seconds later and Identify's tag write found
nothing there. Naming it NFC to begin with leaves Syncthing nothing to
rename."""
name = unicodedata.normalize("NFC", name)
name = _UNSAFE_CHARS.sub("_", name).strip().rstrip(".")
return name or "Unknown"
+23 -2
View File
@@ -1,5 +1,6 @@
import logging
import secrets
import unicodedata
from datetime import datetime, timezone
from pathlib import Path
@@ -595,6 +596,22 @@ class LibraryManager(QObject):
self._schedule_save()
self.track_updated.emit(track_id)
def repair_location(self, track) -> bool:
"""A track whose file is missing but whose path's NFC spelling
exists is pointed at that (Round 130): Syncthing renamed it so,
under us. True when the track's file is (now) there."""
if track is None or not track.location:
return False
if Path(track.location).exists():
return True
nfc = unicodedata.normalize("NFC", track.location)
if nfc != track.location and Path(nfc).exists():
log.info("%s was renamed to its NFC spelling; following it",
track.location)
self.set_track_location(track.track_id, nfc)
return True
return False
def edit_track_fields(self, track_id: int, fields: dict):
"""Edit a track's metadata: write the changed tags to the audio file,
update the in-memory library, and record the change for undo.
@@ -779,6 +796,7 @@ class LibraryManager(QObject):
if k in tagging.EDITABLE_FIELDS}
if not writable or not track.location:
return True
self.repair_location(track)
try:
tagging.write_tags(track.location, writable)
return True
@@ -918,9 +936,12 @@ class LibraryManager(QObject):
return None
merged = {key: changed.get(key, getattr(track, key))
for key in self._ORGANIZE_FIELDS}
# Keep the exact on-disk basename: it's already valid here, and
# Keep the on-disk basename: it's already valid here, and
# re-sanitizing could gratuitously rename files that came from macOS.
dest = organized_destination(root, merged, src.name).with_name(src.name)
# Only its Unicode form changes, to NFC, which Syncthing would
# rename it to anyway (see file_importer.sanitize_component).
dest = organized_destination(root, merged, src.name).with_name(
unicodedata.normalize("NFC", src.name))
if dest == src:
return None
try: