From 79c8521f3800afdd42c5834d66d7840d5769f339 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 9 Jul 2024 00:01:41 +0000 Subject: [PATCH] sane-tag-music: handle edge-cases in tag -> path logic --- pkgs/additional/sane-scripts/src/sane-tag-music | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/additional/sane-scripts/src/sane-tag-music b/pkgs/additional/sane-scripts/src/sane-tag-music index 823c2cca7..ddd99feeb 100755 --- a/pkgs/additional/sane-scripts/src/sane-tag-music +++ b/pkgs/additional/sane-scripts/src/sane-tag-music @@ -78,6 +78,9 @@ def loose_compare_lists(a: list[str], b: list[str]) -> bool: def clean_for_fs(a: str, single_field: bool=False) -> str: preserve = 'abcdefghijklmnopqrstuvwxyz0123456789._-' + # ampersand, like: PLS&TY; &I + a = a.replace("&", "And") + a = a.replace("é", "e") a = a.replace(" ", ".") if single_field: a = a.replace("-", ".") @@ -213,14 +216,16 @@ class Tags: def to_path(self, ext: str) -> str | None: artist = self.albumartist or self.artist - if not (artist and self.album and self.tracknumber and self.title and ext): + is_single = self.album in [self.albumartist, self.artist] + if not (artist and self.album and self.title and (self.tracknumber or is_single) and ext): return None artist = clean_for_fs(artist[0], single_field=False) - album = clean_for_fs(self.album[0], single_field=True) - trackno = clean_for_fs(self.tracknumber[0], single_field=True) + album = "Singles" if is_single else clean_for_fs(self.album[0], single_field=True) + trackno = self.tracknumber and clean_for_fs(self.tracknumber[0], single_field=True) title_ext = clean_for_fs(self.title[0] + f".{ext}", single_field=True) - return f"{artist}/{album}/{trackno}-{title_ext}" + trackno_prefix = f"{trackno}-" if trackno else "" + return f"{artist}/{album}/{trackno_prefix}{title_ext}" @staticmethod def from_path(p: str) -> 'Tags':