Skip to content

Commit

Permalink
remove discnumber from filename unless multidisc
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 11, 2023
1 parent b1c98dd commit c4c184c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rose/cache/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ def update_cache_for_release(c: Config, release_dir: Path) -> Path:
logger.debug(f"Assigning id={release_id} to release {release_dir.name}")
release_dir = _rename_with_uuid(release_dir, release_id)

# Fetch all track tags from disk.
track_tags: list[tuple[os.DirEntry[str], AudioFile]] = []
for f in os.scandir(release_dir):
# Skip non-music files.
if not any(f.name.endswith(ext) for ext in SUPPORTED_EXTENSIONS):
continue
if any(f.name.endswith(ext) for ext in SUPPORTED_EXTENSIONS):
track_tags.append((f, AudioFile.from_file(Path(f.path))))

tags = AudioFile.from_file(Path(f.path))
# Calculate whether this is a multidisc release or not. This will affect the virtual
# filename formatting.
multidisc = len({t.disc_number for _, t in track_tags}) > 1

for f, tags in track_tags:
# If this is the first track, upsert the release.
if release is None:
logger.debug("Upserting release from first track's tags")
Expand Down Expand Up @@ -210,7 +216,7 @@ def update_cache_for_release(c: Config, release_dir: Path) -> Path:
filepath = _rename_with_uuid(filepath, track_id)

virtual_filename = ""
if tags.disc_number:
if multidisc and tags.disc_number:
virtual_filename += f"{tags.disc_number:0>2}-"
if tags.track_number:
virtual_filename += f"{tags.track_number:0>2}. "
Expand Down

0 comments on commit c4c184c

Please sign in to comment.