sane-tag-music: handle edge-cases in tag -> path logic
This commit is contained in:
@@ -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':
|
||||
|
Reference in New Issue
Block a user