Skip to content

incorrect disc number handling in ape tag writer #545

Closed

Description

@AyaseFile

Reproducer

use std::path::Path;

use lofty::prelude::*;
use lofty::tag::{ItemKey, TagType};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    {
        let mut ape_tag = lofty::ape::ApeTag::new();
        ape_tag.set_track(2);
        ape_tag.set_track_total(10);
        ape_tag.set_disk(3);
        ape_tag.set_disk_total(5);
        println!("before `remove_disk_total`:");
        println!(
            "- Track: {}/{}",
            ape_tag.track().unwrap_or(0),
            ape_tag.track_total().unwrap_or(0)
        );
        println!(
            "- Disk: {}/{}",
            ape_tag.disk().unwrap_or(0),
            ape_tag.disk_total().unwrap_or(0)
        );
        ape_tag.remove_disk_total();
        println!("after `remove_disk_total`:");
        println!(
            "- Track: {}/{}",
            ape_tag.track().unwrap_or(0),
            ape_tag.track_total().unwrap_or(0)
        );
        println!(
            "- Disk: {}/{}",
            ape_tag.disk().unwrap_or(0),
            ape_tag.disk_total().unwrap_or(0)
        );
    }
    {
        let test_file = Path::new("test.wv");
        let mut tagged_file = lofty::read_from_path(test_file)?;
        if let Some(tag) = tagged_file.tag_mut(TagType::Ape) {
            tag.insert_text(ItemKey::DiscNumber, "3".to_string());
            tag.insert_text(ItemKey::DiscTotal, "5".to_string());
            tagged_file.save_to_path(test_file, Default::default())?;
        }
    }
    Ok(())
}

Summary

There are two bugs in the APE tag writer related to disc number handling:

  • Incorrect logic in remove_disk_total: The method incorrectly preserves the track number instead of the disc number.
  • Incorrect key written to file: The writer uses the key "Disk" instead of the correct "Disc". This was verified on WavPack files using FFmpeg and Picard.

Expected behavior

The output of the reproducer code should be:

before `remove_disk_total`:
- Track: 2/10
- Disk: 3/5
after `remove_disk_total`:
- Track: 2/10
- Disk: 3/0

After writing to the WavPack file, inspecting it with ffprobe -i <any_wavpack_file>.wv should show the correct metadata, including a Disc tag with the value 3/5.

Assets

No response

Activity

  1. added
    bug
    on Sep 13, 2025
  2. changed the title [-]fix: incorrect disc number handling in ape tag writer[/-] [+]incorrect disc number handling in ape tag writer[/+] on Sep 13, 2025
  3. added this to the 0.23.0 milestone on Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions