diff --git a/src/ape/write.rs b/src/ape/write.rs index 2a2b8708..561d6ce0 100644 --- a/src/ape/write.rs +++ b/src/ape/write.rs @@ -1,8 +1,8 @@ #[cfg(feature = "ape")] -use crate::ape::tag::ape_tag::ApeTagRef; +use crate::ape::tag::ape_tag; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v1")] -use crate::id3::v1::tag::Id3v1TagRef; +use crate::id3::v1; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; @@ -12,9 +12,9 @@ use std::fs::File; pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { match tag.tag_type() { #[cfg(feature = "ape")] - TagType::Ape => Into::::into(tag).write_to(data), + TagType::Ape => Into::::into(tag).write_to(data), #[cfg(feature = "id3v1")] - TagType::Id3v1 => Into::::into(tag).write_to(data), + TagType::Id3v1 => Into::::into(tag).write_to(data), _ => Err(LoftyError::UnsupportedTag), } } diff --git a/src/id3/v2/flags.rs b/src/id3/v2/flags.rs index bc756368..e8f8b02c 100644 --- a/src/id3/v2/flags.rs +++ b/src/id3/v2/flags.rs @@ -12,7 +12,7 @@ pub struct Id3v2TagFlags { /// Indicates that the tag includes a footer /// /// NOTE: This will have no effect when writing - pub footer: bool, + pub footer: bool, // TODO: Should this be written? Seems useless, but it isn't much work. /// Whether or not to include a CRC-32 in the extended header /// /// This is calculated if the tag is written diff --git a/src/id3/v2/frame/mod.rs b/src/id3/v2/frame/mod.rs index e762e6d3..2d5f636f 100644 --- a/src/id3/v2/frame/mod.rs +++ b/src/id3/v2/frame/mod.rs @@ -240,7 +240,7 @@ pub struct FrameFlags { /// /// NOTE: While unsynchronized data is read, for the sake of simplicity, this flag has no effect when /// writing. There isn't much reason to write unsynchronized data. - pub unsynchronisation: bool, + pub unsynchronisation: bool, /* TODO: Maybe? This doesn't seem very useful, and it is wasted effort if one forgets to make this false when writing. */ /// Frame has a data length indicator /// /// The data length indicator is the size of the frame if the flags were all zeroed out. diff --git a/src/id3/v2/restrictions.rs b/src/id3/v2/restrictions.rs index 493d13c3..cf9d3fee 100644 --- a/src/id3/v2/restrictions.rs +++ b/src/id3/v2/restrictions.rs @@ -89,14 +89,11 @@ impl TagRestrictions { let restriction_flags = byte; // xx000000 - match ( - restriction_flags & 0x80 == 0x80, - restriction_flags & 0x40 == 0x40, - ) { - (false, false) => {}, // default - (false, true) => restrictions.size = TagSizeRestrictions::S_64F_128K, - (true, false) => restrictions.size = TagSizeRestrictions::S_32F_40K, - (true, true) => restrictions.size = TagSizeRestrictions::S_32F_4K, + match restriction_flags & 0x0C { + 64 => restrictions.size = TagSizeRestrictions::S_64F_128K, + 128 => restrictions.size = TagSizeRestrictions::S_32F_40K, + 192 => restrictions.size = TagSizeRestrictions::S_32F_4K, + _ => {}, // 0, default } // 00x00000 @@ -105,14 +102,11 @@ impl TagRestrictions { } // 000xx000 - match ( - restriction_flags & 0x10 == 0x10, - restriction_flags & 0x08 == 0x08, - ) { - (false, false) => {}, // default - (false, true) => restrictions.text_fields_size = TextSizeRestrictions::C_1024, - (true, false) => restrictions.text_fields_size = TextSizeRestrictions::C_128, - (true, true) => restrictions.text_fields_size = TextSizeRestrictions::C_30, + match restriction_flags & 0x18 { + 8 => restrictions.text_fields_size = TextSizeRestrictions::C_1024, + 16 => restrictions.text_fields_size = TextSizeRestrictions::C_128, + 24 => restrictions.text_fields_size = TextSizeRestrictions::C_30, + _ => {}, // 0, default } // 00000x00 @@ -121,14 +115,11 @@ impl TagRestrictions { } // 000000xx - match ( - restriction_flags & 0x02 == 0x02, - restriction_flags & 0x01 == 0x01, - ) { - (false, false) => {}, // default - (false, true) => restrictions.image_size = ImageSizeRestrictions::P_256, - (true, false) => restrictions.image_size = ImageSizeRestrictions::P_64, - (true, true) => restrictions.image_size = ImageSizeRestrictions::P_64_64, + match restriction_flags & 0x03 { + 1 => restrictions.image_size = ImageSizeRestrictions::P_256, + 2 => restrictions.image_size = ImageSizeRestrictions::P_64, + 3 => restrictions.image_size = ImageSizeRestrictions::P_64_64, + _ => {}, // 0, default } restrictions @@ -143,10 +134,7 @@ impl TagRestrictions { TagSizeRestrictions::S_128F_1M => {}, TagSizeRestrictions::S_64F_128K => byte |= 0x40, TagSizeRestrictions::S_32F_40K => byte |= 0x80, - TagSizeRestrictions::S_32F_4K => { - byte |= 0x80; - byte |= 0x40; - }, + TagSizeRestrictions::S_32F_4K => byte |= 0x0C, } if self.text_encoding { @@ -157,10 +145,7 @@ impl TagRestrictions { TextSizeRestrictions::None => {}, TextSizeRestrictions::C_1024 => byte |= 0x08, TextSizeRestrictions::C_128 => byte |= 0x10, - TextSizeRestrictions::C_30 => { - byte |= 0x10; - byte |= 0x08; - }, + TextSizeRestrictions::C_30 => byte |= 0x18, } if self.image_encoding { @@ -171,10 +156,7 @@ impl TagRestrictions { ImageSizeRestrictions::None => {}, ImageSizeRestrictions::P_256 => byte |= 0x01, ImageSizeRestrictions::P_64 => byte |= 0x02, - ImageSizeRestrictions::P_64_64 => { - byte |= 0x02; - byte |= 0x01; - }, + ImageSizeRestrictions::P_64_64 => byte |= 0x03, } byte diff --git a/src/iff/aiff/write.rs b/src/iff/aiff/write.rs index d60bf514..d08ff092 100644 --- a/src/iff/aiff/write.rs +++ b/src/iff/aiff/write.rs @@ -1,11 +1,6 @@ use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::id3::v2::{ - tag::{tag_frames, Id3v2TagRef}, - Id3v2TagFlags, -}; -#[cfg(feature = "aiff_text_chunks")] -use crate::iff::aiff::tag::AiffTextChunksRef; +use crate::id3::v2; use crate::types::item::ItemKey; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; @@ -16,7 +11,7 @@ use std::fs::File; pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { match tag.tag_type() { #[cfg(feature = "aiff_text_chunks")] - TagType::AiffText => AiffTextChunksRef::new( + TagType::AiffText => super::tag::AiffTextChunksRef::new( tag.get_string(&ItemKey::TrackTitle), tag.get_string(&ItemKey::TrackArtist), tag.get_string(&ItemKey::CopyrightMessage), @@ -25,7 +20,10 @@ pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { ) .write_to(data), #[cfg(feature = "id3v2")] - TagType::Id3v2 => Id3v2TagRef::new(Id3v2TagFlags::default(), tag_frames(tag)).write_to(data), + TagType::Id3v2 => { + v2::tag::Id3v2TagRef::new(v2::Id3v2TagFlags::default(), v2::tag::tag_frames(tag)) + .write_to(data) + }, _ => Err(LoftyError::UnsupportedTag), } } diff --git a/src/iff/wav/write.rs b/src/iff/wav/write.rs index d9ce1b2f..af17e3e8 100644 --- a/src/iff/wav/write.rs +++ b/src/iff/wav/write.rs @@ -1,11 +1,6 @@ use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::id3::v2::{ - tag::{tag_frames, Id3v2TagRef}, - Id3v2TagFlags, -}; -#[cfg(feature = "riff_info_list")] -use crate::iff::wav::tag::RiffInfoListRef; +use crate::id3::v2; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; @@ -15,9 +10,12 @@ use std::fs::File; pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { match tag.tag_type() { #[cfg(feature = "riff_info_list")] - TagType::RiffInfo => Into::::into(tag).write_to(data), + TagType::RiffInfo => Into::::into(tag).write_to(data), #[cfg(feature = "id3v2")] - TagType::Id3v2 => Id3v2TagRef::new(Id3v2TagFlags::default(), tag_frames(tag)).write_to(data), + TagType::Id3v2 => { + v2::tag::Id3v2TagRef::new(v2::Id3v2TagFlags::default(), v2::tag::tag_frames(tag)) + .write_to(data) + }, _ => Err(LoftyError::UnsupportedTag), } } diff --git a/src/mp3/write.rs b/src/mp3/write.rs index d24daa57..39f49803 100644 --- a/src/mp3/write.rs +++ b/src/mp3/write.rs @@ -1,13 +1,10 @@ #[cfg(feature = "ape")] -use crate::ape::tag::ape_tag::ApeTagRef; +use crate::ape::tag::ape_tag; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v1")] -use crate::id3::v1::tag::Id3v1TagRef; +use crate::id3::v1; #[cfg(feature = "id3v2")] -use crate::id3::v2::{ - tag::{tag_frames, Id3v2TagRef}, - Id3v2TagFlags, -}; +use crate::id3::v2; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; @@ -17,11 +14,14 @@ use std::fs::File; pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { match tag.tag_type() { #[cfg(feature = "ape")] - TagType::Ape => Into::::into(tag).write_to(data), + TagType::Ape => Into::::into(tag).write_to(data), #[cfg(feature = "id3v1")] - TagType::Id3v1 => Into::::into(tag).write_to(data), + TagType::Id3v1 => Into::::into(tag).write_to(data), #[cfg(feature = "id3v2")] - TagType::Id3v2 => Id3v2TagRef::new(Id3v2TagFlags::default(), tag_frames(tag)).write_to(data), + TagType::Id3v2 => { + v2::tag::Id3v2TagRef::new(v2::Id3v2TagFlags::default(), v2::tag::tag_frames(tag)) + .write_to(data) + }, _ => Err(LoftyError::UnsupportedTag), } } diff --git a/src/tag_utils.rs b/src/tag_utils.rs index 4746f57a..295c126e 100644 --- a/src/tag_utils.rs +++ b/src/tag_utils.rs @@ -15,10 +15,10 @@ use crate::iff::wav::tag::RiffInfoListRef; #[cfg(feature = "mp4_ilst")] use crate::mp4::ilst::IlstRef; #[cfg(feature = "vorbis_comments")] -use crate::ogg::{ - constants::{OPUSTAGS, VORBIS_COMMENT_HEAD}, - tag::VorbisCommentsRef, -}; +use crate::ogg::tag::VorbisCommentsRef; + +use crate::{ape, iff, mp3, mp4, ogg}; + use crate::types::file::FileType; use crate::types::item::ItemKey; use crate::types::tag::{Tag, TagType}; @@ -29,20 +29,18 @@ use std::io::Write; #[allow(unreachable_patterns)] pub(crate) fn write_tag(tag: &Tag, file: &mut File, file_type: FileType) -> Result<()> { match file_type { - FileType::AIFF => crate::iff::aiff::write::write_to(file, tag), - FileType::APE => crate::ape::write::write_to(file, tag), + FileType::AIFF => iff::aiff::write::write_to(file, tag), + FileType::APE => ape::write::write_to(file, tag), #[cfg(feature = "vorbis_comments")] - FileType::FLAC => { - crate::ogg::flac::write::write_to(file, &mut Into::::into(tag)) - }, - FileType::MP3 => crate::mp3::write::write_to(file, tag), + FileType::FLAC => ogg::flac::write::write_to(file, &mut Into::::into(tag)), + FileType::MP3 => mp3::write::write_to(file, tag), #[cfg(feature = "mp4_ilst")] - FileType::MP4 => crate::mp4::ilst::write::write_to(file, &mut Into::::into(tag)), + FileType::MP4 => mp4::ilst::write::write_to(file, &mut Into::::into(tag)), #[cfg(feature = "vorbis_comments")] - FileType::Opus => crate::ogg::write::write_to(file, tag, OPUSTAGS), + FileType::Opus => ogg::write::write_to(file, tag, ogg::constants::OPUSTAGS), #[cfg(feature = "vorbis_comments")] - FileType::Vorbis => crate::ogg::write::write_to(file, tag, VORBIS_COMMENT_HEAD), - FileType::WAV => crate::iff::wav::write::write_to(file, tag), + FileType::Vorbis => ogg::write::write_to(file, tag, ogg::constants::VORBIS_COMMENT_HEAD), + FileType::WAV => iff::wav::write::write_to(file, tag), _ => Err(LoftyError::UnsupportedTag), } }