sane-tag-music: --trackno "" fix-tags FOO can be used to clear FOOs track number field

This commit is contained in:
Colin 2024-06-13 08:22:57 +00:00
parent 330a64d820
commit 999a173001

View File

@ -22,8 +22,8 @@ then this updates the tags on-disk to reflect their path.
DIRECTORY: specify `.` to scan the entire library.
options:
--dry-run: only show what would be done, don't actually do it.
--verbose
--dry-run: only show what would be done, don't actually do it.
--verbose
--album ALBUM manually specify the tag, rather than guessing from path.
--album-artist ARTIST often combined with DIRECTORY to tag an entire artist or album.
--artist ARTIST
@ -31,7 +31,7 @@ options:
--trackno TRACK_NUMBER
fix-tags options:
--force: apply path-based tag to each file, even those which already have tags (only for fix-tags)
--force: apply path-based tag to each file, even those which already have tags (only for fix-tags)
"""
from dataclasses import dataclass
@ -118,6 +118,10 @@ class Tags:
return f"artist:{self.artist}/{self.albumartist}, album:{self.album}, title:{self.title}, trackno:{self.tracknumber}"
def union(self, fallback: 'Tags') -> 'Tags':
"""
substitute any tags missing tags in `self` with those from `fallback`.
i.e. `self` takes precedence over `fallback`.
"""
def merge_field(primary: list[str], secondary: list[str]) -> list[str]:
# primary_lower = [i.lower() for i in primary]
# return primary + [i for i in secondary if i.lower() not in primary_lower]
@ -159,6 +163,9 @@ class Tags:
if v.count("/") == 1:
trackno, last = v.split("/")
try:
if int(trackno) == int(last) == 1:
# track 1/1: useless; clear the field
self.tracknumber[i] = ''
if int(trackno) <= int(last):
self.tracknumber[i] = trackno.lstrip('0')
except: pass
@ -401,9 +408,14 @@ class Tagger:
path_tags = Tags.from_path(path_)
additional_tags = self.manual_tags.union(path_tags)
if self.force:
# additional_tags overrule old_tags
new_tags = additional_tags.union(old_tags)
else:
# old_tags overrule additional_tags
new_tags = old_tags.union(additional_tags)
if additional_tags.tracknumber == [""]:
# special case that `--trackno ""` can be used to delete the track number without `--force`ing all fields
new_tags.tracknumber = []
new_tags = new_tags.union(self.manual_tags)
new_tags.trim_fields()
new_tags.cleanup_trackno()