2021-06-30 05:00:40 +00:00
|
|
|
#![cfg(feature = "default")]
|
|
|
|
|
2021-07-24 19:54:51 +00:00
|
|
|
use lofty::{Id3Format, OggTag, Tag, TagType, ToAnyTag, OggFormat, AudioTagEdit};
|
|
|
|
|
|
|
|
use std::io::Cursor;
|
2020-10-27 15:00:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inner() {
|
2021-07-24 19:54:51 +00:00
|
|
|
// Create a new flac OggTag
|
|
|
|
let mut flac_data = Cursor::new(std::fs::read("tests/assets/a.flac").unwrap());
|
|
|
|
let mut flac_tag = OggTag::read_from(&mut flac_data, &OggFormat::Flac).unwrap();
|
2021-04-07 02:33:39 +00:00
|
|
|
|
|
|
|
// Set the title of the flac tag
|
2021-07-24 19:54:51 +00:00
|
|
|
flac_tag.set_title("Foo title");
|
2021-04-07 02:33:39 +00:00
|
|
|
|
2021-07-24 19:54:51 +00:00
|
|
|
// Turn the VorbisTag into an Id3v2Tag
|
|
|
|
let id3tag = flac_tag.to_dyn_tag(TagType::Id3v2(Id3Format::Mp3));
|
2021-04-07 02:33:39 +00:00
|
|
|
|
2021-07-24 19:54:51 +00:00
|
|
|
// Write the Id3v2Tag to `a.mp3`
|
2021-04-03 00:47:44 +00:00
|
|
|
id3tag
|
2021-04-06 20:37:31 +00:00
|
|
|
.write_to_path("tests/assets/a.mp3")
|
2021-04-03 00:47:44 +00:00
|
|
|
.expect("Fail to write!");
|
2020-10-27 15:00:22 +00:00
|
|
|
|
2021-04-07 02:33:39 +00:00
|
|
|
// Read from `a.mp3`
|
2021-07-24 19:54:51 +00:00
|
|
|
let id3tag_reload = Tag::new()
|
2021-04-22 22:01:09 +00:00
|
|
|
.read_from_path("tests/assets/a.mp3")
|
2021-04-03 00:47:44 +00:00
|
|
|
.expect("Fail to read!");
|
2021-04-07 02:33:39 +00:00
|
|
|
|
|
|
|
// Confirm title still matches
|
2021-07-24 19:54:51 +00:00
|
|
|
assert_eq!(id3tag_reload.title(), Some("Foo title"));
|
2020-10-27 15:24:54 +00:00
|
|
|
|
2021-07-24 19:54:51 +00:00
|
|
|
// Convert Id3v2Tag to id3::Tag
|
2021-04-03 00:47:44 +00:00
|
|
|
let mut id3tag_inner: id3::Tag = id3tag_reload.into();
|
2021-04-07 02:33:39 +00:00
|
|
|
|
|
|
|
// Create timestamp and change date_recorded
|
2021-04-03 00:47:44 +00:00
|
|
|
let timestamp = id3::Timestamp {
|
|
|
|
year: 2013,
|
2021-04-23 02:57:47 +00:00
|
|
|
month: Some(2_u8),
|
|
|
|
day: Some(5_u8),
|
|
|
|
hour: Some(6_u8),
|
2021-04-03 00:47:44 +00:00
|
|
|
minute: None,
|
|
|
|
second: None,
|
|
|
|
};
|
2021-06-29 18:45:57 +00:00
|
|
|
|
2021-04-14 16:17:38 +00:00
|
|
|
id3tag_inner.set_date_recorded(timestamp);
|
2021-04-07 02:33:39 +00:00
|
|
|
|
|
|
|
// Write id3::Tag to `a.mp3`
|
2021-04-03 00:47:44 +00:00
|
|
|
id3tag_inner
|
2021-04-06 20:37:31 +00:00
|
|
|
.write_to_path("tests/assets/a.mp3", id3::Version::Id3v24)
|
2021-04-03 00:47:44 +00:00
|
|
|
.expect("Fail to write!");
|
2020-10-27 15:24:54 +00:00
|
|
|
|
2021-04-07 02:33:39 +00:00
|
|
|
// Read from `a.mp3`
|
2021-04-06 20:37:31 +00:00
|
|
|
let id3tag_reload = id3::Tag::read_from_path("tests/assets/a.mp3").expect("Fail to read!");
|
2021-04-07 02:33:39 +00:00
|
|
|
|
|
|
|
// Confirm timestamp still matches
|
2021-04-03 00:47:44 +00:00
|
|
|
assert_eq!(id3tag_reload.date_recorded(), Some(timestamp));
|
2020-10-27 15:00:22 +00:00
|
|
|
}
|