Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Some encoders will only write a BOM to the frame's description, rather than to every string in the frame.
This was previously only supported in `SYLT` frames, and has been extended to `COMM` and `USLT`.
- **Vorbis Comments**: Parse `TRACKNUMBER` with respect to `ParseOptions::implicit_conversions` ([issue](https://github.com/Serial-ATA/lofty-rs/issues/540)) ([PR](https://github.com/Serial-ATA/lofty-rs/issues/542))
- **APE**: Fix disc number removal/writing ([issue](https://github.com/Serial-ATA/lofty-rs/issues/545)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/546))

### Removed

Expand Down
22 changes: 18 additions & 4 deletions lofty/src/ape/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ impl Accessor for ApeTag {
}

fn remove_disk_total(&mut self) {
let existing_track_number = self.track();
let existing_disk_number = self.disk();
self.remove("Disc");

if let Some(track) = existing_track_number {
self.insert(ApeItem::text("Disc", track.to_string()));
if let Some(disk) = existing_disk_number {
self.insert(ApeItem::text("Disc", disk.to_string()));
}
}

Expand Down Expand Up @@ -564,7 +564,7 @@ pub(crate) fn tagitems_into_ape(tag: &Tag) -> impl Iterator<Item = ApeItemRef<'_
.chain(create_apeitemref_for_number_pair(
tag.get_string(ItemKey::DiscNumber),
tag.get_string(ItemKey::DiscTotal),
"Disk",
"Disc",
))
}

Expand Down Expand Up @@ -947,4 +947,18 @@ mod tests {

assert_eq!(ape.len(), 1);
}

#[test_log::test]
fn remove_disk_total_preserves_disk_number() {
let mut ape = ApeTag::new();
ape.set_track(2);
ape.set_disk(3);
ape.set_disk_total(5);

ape.remove_disk_total();

assert_eq!(ape.disk(), Some(3));
assert!(ape.disk_total().is_none());
assert_eq!(ape.track(), Some(2));
}
}
44 changes: 42 additions & 2 deletions lofty/tests/files/wavpack.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{set_artist, temp_file, verify_artist};
use lofty::config::ParseOptions;
use lofty::ape::ApeTag;
use lofty::config::{ParseOptions, WriteOptions};
use lofty::file::FileType;
use lofty::prelude::*;
use lofty::probe::Probe;
use lofty::tag::TagType;
use lofty::tag::{Tag, TagType};

use std::io::Seek;

Expand Down Expand Up @@ -77,3 +78,42 @@ fn read_no_properties() {
fn read_no_tags() {
crate::no_tag_test!("tests/files/assets/minimal/full_test.wv");
}

#[test_log::test]
fn write_ape_disc_key() {
let mut file = crate::temp_file!("tests/files/assets/minimal/full_test.wv");
let mut tagged_file = Probe::new(&mut file)
.options(ParseOptions::new())
.guess_file_type()
.unwrap()
.read()
.unwrap();

// Create and insert a new Tag and set disk information
let mut tag = Tag::new(TagType::Ape);
tag.set_disk(3);
tag.set_disk_total(5);
tagged_file.insert_tag(tag);
file.rewind().unwrap();
tagged_file
.save_to(&mut file, WriteOptions::default())
.unwrap();

// Reread the file to get the actual APE tag
file.rewind().unwrap();
let reread_tagged_file = Probe::new(&mut file)
.options(ParseOptions::new())
.guess_file_type()
.unwrap()
.read()
.unwrap();
let tag_ref = reread_tagged_file.tag(TagType::Ape).unwrap();
let ape_tag: ApeTag = tag_ref.clone().into();

assert!(
ape_tag.get("Disc").is_some(),
"APE tag should contain `Disc` key with disk information"
);
assert_eq!(ape_tag.disk(), Some(3));
assert_eq!(ape_tag.disk_total(), Some(5));
}