2021-12-05 22:02:22 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! temp_file {
|
|
|
|
($path:tt) => {{
|
|
|
|
let mut file = tempfile::tempfile().unwrap();
|
|
|
|
file.write_all(&std::fs::read($path).unwrap()).unwrap();
|
|
|
|
|
2023-02-01 01:07:54 +00:00
|
|
|
file.rewind().unwrap();
|
2021-12-05 22:02:22 +00:00
|
|
|
|
|
|
|
file
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:41:24 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! verify_artist {
|
|
|
|
($file:ident, $method:ident, $expected_value:literal, $item_count:expr) => {{
|
|
|
|
println!("VERIFY: Expecting `{}` to have {} items, with an artist of \"{}\"", stringify!($method), $item_count, $expected_value);
|
|
|
|
|
|
|
|
verify_artist!($file, $method(), $expected_value, $item_count)
|
|
|
|
}};
|
|
|
|
($file:ident, $method:ident, $arg:path, $expected_value:literal, $item_count:expr) => {{
|
|
|
|
println!("VERIFY: Expecting `{}` to have {} items, with an artist of \"{}\"", stringify!($arg), $item_count, $expected_value);
|
|
|
|
|
|
|
|
verify_artist!($file, $method($arg), $expected_value, $item_count)
|
|
|
|
}};
|
|
|
|
($file:ident, $method:ident($($arg:path)?), $expected_value:literal, $item_count:expr) => {{
|
2022-07-24 20:12:14 +00:00
|
|
|
assert!($file.$method($($arg)?).is_some());
|
2021-09-06 14:41:24 +00:00
|
|
|
|
2022-07-24 20:12:14 +00:00
|
|
|
let tag = $file.$method($($arg)?).unwrap();
|
2021-09-06 14:41:24 +00:00
|
|
|
|
|
|
|
assert_eq!(tag.item_count(), $item_count);
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-04-13 18:01:48 +00:00
|
|
|
tag.get(&lofty::prelude::ItemKey::TrackArtist),
|
|
|
|
Some(&lofty::tag::TagItem::new(
|
|
|
|
lofty::prelude::ItemKey::TrackArtist,
|
|
|
|
lofty::tag::ItemValue::Text(String::from($expected_value))
|
2021-09-06 14:41:24 +00:00
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
tag
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! set_artist {
|
|
|
|
($tagged_file:ident, $method:ident, $expected_value:literal, $item_count:expr => $file_write:ident, $new_value:literal) => {
|
|
|
|
let tag = verify_artist!($tagged_file, $method, $expected_value, $item_count);
|
|
|
|
println!(
|
|
|
|
"WRITE: Writing artist \"{}\" to {}\n",
|
|
|
|
$new_value,
|
|
|
|
stringify!($method)
|
|
|
|
);
|
|
|
|
set_artist!($file_write, $new_value, tag)
|
|
|
|
};
|
|
|
|
($tagged_file:ident, $method:ident, $arg:path, $expected_value:literal, $item_count:expr => $file_write:ident, $new_value:literal) => {
|
|
|
|
let tag = verify_artist!($tagged_file, $method, $arg, $expected_value, $item_count);
|
|
|
|
println!(
|
|
|
|
"WRITE: Writing artist \"{}\" to {}\n",
|
|
|
|
$new_value,
|
|
|
|
stringify!($arg)
|
|
|
|
);
|
|
|
|
set_artist!($file_write, $new_value, tag)
|
|
|
|
};
|
|
|
|
($file_write:ident, $new_value:literal, $tag:ident) => {
|
2024-04-13 18:01:48 +00:00
|
|
|
$tag.insert_unchecked(lofty::tag::TagItem::new(
|
|
|
|
lofty::prelude::ItemKey::TrackArtist,
|
|
|
|
lofty::tag::ItemValue::Text(String::from($new_value)),
|
2022-01-08 12:42:28 +00:00
|
|
|
));
|
2021-09-06 14:41:24 +00:00
|
|
|
|
2023-02-01 01:07:54 +00:00
|
|
|
$file_write.rewind().unwrap();
|
2021-12-05 22:02:22 +00:00
|
|
|
|
2024-04-13 16:50:28 +00:00
|
|
|
$tag.save_to(&mut $file_write, lofty::config::WriteOptions::default())
|
2024-04-03 05:40:04 +00:00
|
|
|
.unwrap();
|
2021-09-06 14:41:24 +00:00
|
|
|
};
|
|
|
|
}
|
2021-10-01 23:30:51 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! remove_tag {
|
2021-12-05 22:02:22 +00:00
|
|
|
($path:tt, $tag_type:path) => {
|
|
|
|
let mut file = temp_file!($path);
|
2021-10-01 23:30:51 +00:00
|
|
|
|
2024-04-14 17:08:08 +00:00
|
|
|
let tagged_file = lofty::probe::Probe::new(&mut file)
|
2024-04-13 16:50:28 +00:00
|
|
|
.options(lofty::config::ParseOptions::new().read_properties(false))
|
2022-09-24 06:34:22 +00:00
|
|
|
.guess_file_type()
|
|
|
|
.unwrap()
|
|
|
|
.read()
|
|
|
|
.unwrap();
|
2022-07-24 20:12:14 +00:00
|
|
|
assert!(tagged_file.tag($tag_type).is_some());
|
2021-10-01 23:30:51 +00:00
|
|
|
|
2023-02-01 01:07:54 +00:00
|
|
|
file.rewind().unwrap();
|
2021-12-05 22:02:22 +00:00
|
|
|
|
2022-02-03 03:10:04 +00:00
|
|
|
$tag_type.remove_from(&mut file).unwrap();
|
2021-10-01 23:30:51 +00:00
|
|
|
|
2023-02-01 01:07:54 +00:00
|
|
|
file.rewind().unwrap();
|
2021-11-21 20:18:19 +00:00
|
|
|
|
2024-04-14 17:08:08 +00:00
|
|
|
let tagged_file = lofty::probe::Probe::new(&mut file)
|
2024-04-13 16:50:28 +00:00
|
|
|
.options(lofty::config::ParseOptions::new().read_properties(false))
|
2022-09-24 06:34:22 +00:00
|
|
|
.guess_file_type()
|
|
|
|
.unwrap()
|
|
|
|
.read()
|
|
|
|
.unwrap();
|
2022-07-24 20:12:14 +00:00
|
|
|
assert!(tagged_file.tag($tag_type).is_none());
|
2021-10-01 23:30:51 +00:00
|
|
|
};
|
|
|
|
}
|