diff --git a/src/logic/ape/constants.rs b/src/ape/constants.rs similarity index 100% rename from src/logic/ape/constants.rs rename to src/ape/constants.rs diff --git a/src/logic/ape/mod.rs b/src/ape/mod.rs similarity index 81% rename from src/logic/ape/mod.rs rename to src/ape/mod.rs index 947bad15..d83845eb 100644 --- a/src/logic/ape/mod.rs +++ b/src/ape/mod.rs @@ -1,21 +1,32 @@ +//! APE specific items +//! +//! ## File notes +//! +//! It is possible for an `APE` file to contain an `ID3v2` tag. For the sake of data preservation, +//! this tag will be read, but **cannot** be written. The only tags allowed by spec are `APEv1/2` and +//! `ID3v1`. mod constants; -pub(crate) mod properties; -pub(crate) mod read; +mod properties; +mod read; pub(crate) mod tag; pub(crate) mod write; +pub use crate::ape::properties::ApeProperties; +#[cfg(feature = "ape")] +pub use { + crate::types::picture::APE_PICTURE_TYPES, + tag::{ape_tag::ApeTag, item::ApeItem}, +}; + use crate::error::Result; #[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1Tag; +use crate::id3::v1::tag::Id3v1Tag; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::tag_methods; +use crate::id3::v2::tag::Id3v2Tag; +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::{Tag, TagType}; -use properties::ApeProperties; -#[cfg(feature = "ape")] -use tag::ape_tag::ApeTag; use std::io::{Read, Seek}; diff --git a/src/logic/ape/properties.rs b/src/ape/properties.rs similarity index 100% rename from src/logic/ape/properties.rs rename to src/ape/properties.rs diff --git a/src/logic/ape/read.rs b/src/ape/read.rs similarity index 94% rename from src/logic/ape/read.rs rename to src/ape/read.rs index d3bc568e..292fcdfa 100644 --- a/src/logic/ape/read.rs +++ b/src/ape/read.rs @@ -2,13 +2,13 @@ use super::constants::APE_PREAMBLE; #[cfg(feature = "ape")] use super::tag::{ape_tag::ApeTag, read::read_ape_tag}; use super::{ApeFile, ApeProperties}; +use crate::ape::tag::read_ape_header; use crate::error::{LoftyError, Result}; -use crate::logic::ape::tag::read_ape_header; #[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1Tag; +use crate::id3::v1::tag::Id3v1Tag; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::{read::parse_id3v2, tag::Id3v2Tag}; -use crate::logic::id3::{find_id3v1, find_id3v2, find_lyrics3v2}; +use crate::id3::v2::{read::parse_id3v2, tag::Id3v2Tag}; +use crate::id3::{find_id3v1, find_id3v2, find_lyrics3v2}; use std::io::{Read, Seek, SeekFrom}; diff --git a/src/logic/ape/tag/ape_tag.rs b/src/ape/tag/ape_tag.rs similarity index 95% rename from src/logic/ape/tag/ape_tag.rs rename to src/ape/tag/ape_tag.rs index 1fe77df7..37b01078 100644 --- a/src/logic/ape/tag/ape_tag.rs +++ b/src/ape/tag/ape_tag.rs @@ -1,5 +1,5 @@ +use crate::ape::tag::item::{ApeItem, ApeItemRef}; use crate::error::Result; -use crate::logic::ape::tag::item::{ApeItem, ApeItemRef}; use crate::types::item::{ItemKey, ItemValue, TagItem}; use crate::types::tag::{Accessor, Tag, TagType}; @@ -199,7 +199,7 @@ impl From for ApeTag { } } -pub(in crate::logic) struct ApeTagRef<'a> { +pub(crate) struct ApeTagRef<'a> { pub(crate) read_only: bool, pub(super) items: Box> + 'a>, } @@ -239,7 +239,7 @@ mod tests { use crate::ape::{ApeItem, ApeTag}; use crate::{ItemValue, Tag, TagType}; - use crate::logic::ape::tag::read_ape_header; + use crate::ape::tag::read_ape_header; use std::io::{Cursor, Read}; #[test] @@ -300,7 +300,7 @@ mod tests { let mut reader = Cursor::new(tag); let header = read_ape_header(&mut reader, false).unwrap(); - let parsed_tag = crate::logic::ape::tag::read::read_ape_tag(&mut reader, header).unwrap(); + let parsed_tag = crate::ape::tag::read::read_ape_tag(&mut reader, header).unwrap(); assert_eq!(expected_tag.items().len(), parsed_tag.items().len()); @@ -321,11 +321,11 @@ mod tests { let mut reader = Cursor::new(tag_bytes); let header = read_ape_header(&mut reader, false).unwrap(); - let ape = crate::logic::ape::tag::read::read_ape_tag(&mut reader, header).unwrap(); + let ape = crate::ape::tag::read::read_ape_tag(&mut reader, header).unwrap(); let tag: Tag = ape.into(); - crate::logic::test_utils::verify_tag(&tag, true, true); + crate::tag_utils::test_utils::verify_tag(&tag, true, true); } #[test] @@ -337,7 +337,7 @@ mod tests { ); } - let tag = crate::logic::test_utils::create_tag(TagType::Ape); + let tag = crate::tag_utils::test_utils::create_tag(TagType::Ape); let ape_tag: ApeTag = tag.into(); diff --git a/src/logic/ape/tag/item.rs b/src/ape/tag/item.rs similarity index 95% rename from src/logic/ape/tag/item.rs rename to src/ape/tag/item.rs index af8b76a3..02514f85 100644 --- a/src/logic/ape/tag/item.rs +++ b/src/ape/tag/item.rs @@ -1,5 +1,5 @@ +use crate::ape::constants::INVALID_KEYS; use crate::error::{LoftyError, Result}; -use crate::logic::ape::constants::INVALID_KEYS; use crate::types::item::{ItemValue, ItemValueRef, TagItem}; use crate::types::tag::TagType; @@ -80,7 +80,7 @@ impl TryFrom for ApeItem { } } -pub(in crate::logic) struct ApeItemRef<'a> { +pub(crate) struct ApeItemRef<'a> { pub read_only: bool, pub key: &'a str, pub value: ItemValueRef<'a>, diff --git a/src/logic/ape/tag/mod.rs b/src/ape/tag/mod.rs similarity index 95% rename from src/logic/ape/tag/mod.rs rename to src/ape/tag/mod.rs index 4f4a4208..d1e81491 100644 --- a/src/logic/ape/tag/mod.rs +++ b/src/ape/tag/mod.rs @@ -3,9 +3,9 @@ pub(crate) mod ape_tag; #[cfg(feature = "ape")] pub(crate) mod item; #[cfg(feature = "ape")] -pub(in crate::logic) mod read; +pub(crate) mod read; #[cfg(feature = "ape")] -pub(in crate::logic) mod write; +mod write; use crate::error::{LoftyError, Result}; diff --git a/src/logic/ape/tag/read.rs b/src/ape/tag/read.rs similarity index 97% rename from src/logic/ape/tag/read.rs rename to src/ape/tag/read.rs index 767727b4..2444b1c0 100644 --- a/src/logic/ape/tag/read.rs +++ b/src/ape/tag/read.rs @@ -1,6 +1,6 @@ use super::{ape_tag::ApeTag, item::ApeItem, ApeHeader}; +use crate::ape::constants::INVALID_KEYS; use crate::error::{LoftyError, Result}; -use crate::logic::ape::constants::INVALID_KEYS; use crate::types::item::ItemValue; use std::io::{Read, Seek, SeekFrom}; diff --git a/src/logic/ape/tag/write.rs b/src/ape/tag/write.rs similarity index 95% rename from src/logic/ape/tag/write.rs rename to src/ape/tag/write.rs index 8c9b7a77..05ee958a 100644 --- a/src/logic/ape/tag/write.rs +++ b/src/ape/tag/write.rs @@ -1,8 +1,8 @@ use super::read::read_ape_tag; +use crate::ape::constants::APE_PREAMBLE; +use crate::ape::tag::ape_tag::ApeTagRef; use crate::error::{LoftyError, Result}; -use crate::logic::ape::constants::APE_PREAMBLE; -use crate::logic::ape::tag::ape_tag::ApeTagRef; -use crate::logic::id3::{find_id3v1, find_id3v2, find_lyrics3v2}; +use crate::id3::{find_id3v1, find_id3v2, find_lyrics3v2}; use crate::probe::Probe; use crate::types::file::FileType; use crate::types::item::ItemValueRef; @@ -10,11 +10,11 @@ use crate::types::item::ItemValueRef; use std::fs::File; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; -use crate::logic::ape::tag::read_ape_header; +use crate::ape::tag::read_ape_header; use byteorder::{LittleEndian, WriteBytesExt}; #[allow(clippy::shadow_unrelated)] -pub(in crate::logic) fn write_to(data: &mut File, tag: &mut ApeTagRef) -> Result<()> { +pub(crate) fn write_to(data: &mut File, tag: &mut ApeTagRef) -> Result<()> { let probe = Probe::new(data).guess_file_type()?; match probe.file_type() { diff --git a/src/logic/ape/write.rs b/src/ape/write.rs similarity index 72% rename from src/logic/ape/write.rs rename to src/ape/write.rs index e045deb0..2a2b8708 100644 --- a/src/logic/ape/write.rs +++ b/src/ape/write.rs @@ -1,15 +1,15 @@ -use crate::error::{LoftyError, Result}; #[cfg(feature = "ape")] -use crate::logic::ape::tag::ape_tag::ApeTagRef; +use crate::ape::tag::ape_tag::ApeTagRef; +use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1TagRef; +use crate::id3::v1::tag::Id3v1TagRef; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; use std::fs::File; #[allow(unused_variables)] -pub(in crate::logic) fn write_to(data: &mut File, tag: &Tag) -> Result<()> { +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), diff --git a/src/error.rs b/src/error.rs index a7ecb9e2..20b5a453 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,8 @@ -use ogg_pager::PageError; use std::fmt::{Display, Formatter}; -/// Result of tag operations +use ogg_pager::PageError; + +/// Alias for `Result` pub type Result = std::result::Result; /// Errors that could occur within Lofty @@ -21,7 +22,7 @@ pub enum LoftyError { // Picture related errors #[cfg(feature = "id3v2")] - /// Arises when an invalid picture format is parsed. Only applicable to [`Id3v2Version::V2`](crate::logic::id3::v2::Id3v2Version) + /// Arises when an invalid picture format is parsed. Only applicable to [`Id3v2Version::V2`](crate::id3::v2::Id3v2Version) BadPictureFormat(String), /// Provided an invalid picture NotAPicture, diff --git a/src/logic/id3/mod.rs b/src/id3/mod.rs similarity index 86% rename from src/logic/id3/mod.rs rename to src/id3/mod.rs index a3dbc3b3..18b97513 100644 --- a/src/logic/id3/mod.rs +++ b/src/id3/mod.rs @@ -1,6 +1,11 @@ +//! ID3 specific items +//! +//! ID3 does things differently than other tags, making working with them a little more effort than other formats. +//! Check the other modules for important notes and/or warnings. + #[cfg(feature = "id3v1")] -pub(crate) mod v1; -pub(crate) mod v2; +pub mod v1; +pub mod v2; use crate::error::{LoftyError, Result}; use v2::{read_id3v2_header, Id3v2Header}; @@ -37,10 +42,7 @@ where } #[cfg(feature = "id3v1")] -pub(in crate::logic) fn find_id3v1( - data: &mut R, - read: bool, -) -> Result<(bool, Option)> +pub(crate) fn find_id3v1(data: &mut R, read: bool) -> Result<(bool, Option)> where R: Read + Seek, { @@ -74,7 +76,7 @@ where } #[cfg(not(feature = "id3v1"))] -pub(in crate::logic) fn find_id3v1(data: &mut R, _read: bool) -> Result<(bool, Option<()>)> +pub(in crate::tag_utils) fn find_id3v1(data: &mut R, _read: bool) -> Result<(bool, Option<()>)> where R: Read + Seek, { diff --git a/src/logic/id3/v1/constants.rs b/src/id3/v1/constants.rs similarity index 100% rename from src/logic/id3/v1/constants.rs rename to src/id3/v1/constants.rs diff --git a/src/id3/v1/mod.rs b/src/id3/v1/mod.rs new file mode 100644 index 00000000..1ba39fd1 --- /dev/null +++ b/src/id3/v1/mod.rs @@ -0,0 +1,23 @@ +//! ID3v1 items +//! +//! # ID3v1 notes +//! +//! See also: [Id3v1Tag] +//! +//! ## Genres +//! +//! ID3v1 stores the genre in a single byte ranging from 0 to 192 (inclusive). +//! All possible genres have been stored in the [`GENRES`] constant. +//! +//! ## Track Numbers +//! +//! ID3v1 stores the track number in a non-zero byte. +//! A track number of 0 will be treated as an empty field. +//! Additionally, there is no track total field. +pub(crate) mod constants; +pub(crate) mod read; +pub(crate) mod tag; +pub(crate) mod write; + +pub use crate::id3::v1::constants::GENRES; +pub use crate::id3::v1::tag::Id3v1Tag; diff --git a/src/logic/id3/v1/read.rs b/src/id3/v1/read.rs similarity index 100% rename from src/logic/id3/v1/read.rs rename to src/id3/v1/read.rs diff --git a/src/logic/id3/v1/tag.rs b/src/id3/v1/tag.rs similarity index 95% rename from src/logic/id3/v1/tag.rs rename to src/id3/v1/tag.rs index 678c8c9c..c41b6026 100644 --- a/src/logic/id3/v1/tag.rs +++ b/src/id3/v1/tag.rs @@ -1,5 +1,5 @@ use crate::error::Result; -use crate::logic::id3::v1::constants::GENRES; +use crate::id3::v1::constants::GENRES; use crate::types::item::{ItemKey, ItemValue, TagItem}; use crate::types::tag::{Accessor, Tag, TagType}; @@ -173,7 +173,7 @@ impl From for Id3v1Tag { } } -pub(in crate::logic) struct Id3v1TagRef<'a> { +pub(crate) struct Id3v1TagRef<'a> { pub title: Option<&'a str>, pub artist: Option<&'a str>, pub album: Option<&'a str>, @@ -263,7 +263,7 @@ mod tests { .read_exact(&mut tag) .unwrap(); - let parsed_tag = crate::logic::id3::v1::read::parse_id3v1(tag); + let parsed_tag = crate::id3::v1::read::parse_id3v1(tag); assert_eq!(expected_tag, parsed_tag); } @@ -276,16 +276,16 @@ mod tests { .read_exact(&mut tag_bytes) .unwrap(); - let id3v1 = crate::logic::id3::v1::read::parse_id3v1(tag_bytes); + let id3v1 = crate::id3::v1::read::parse_id3v1(tag_bytes); let tag: Tag = id3v1.into(); - crate::logic::test_utils::verify_tag(&tag, true, true); + crate::tag_utils::test_utils::verify_tag(&tag, true, true); } #[test] fn tag_to_id3v1() { - let tag = crate::logic::test_utils::create_tag(TagType::Id3v1); + let tag = crate::tag_utils::test_utils::create_tag(TagType::Id3v1); let id3v1_tag: Id3v1Tag = tag.into(); diff --git a/src/logic/id3/v1/write.rs b/src/id3/v1/write.rs similarity index 93% rename from src/logic/id3/v1/write.rs rename to src/id3/v1/write.rs index 695b2eba..f628deb3 100644 --- a/src/logic/id3/v1/write.rs +++ b/src/id3/v1/write.rs @@ -1,6 +1,6 @@ use super::tag::Id3v1TagRef; use crate::error::{LoftyError, Result}; -use crate::logic::id3::find_id3v1; +use crate::id3::find_id3v1; use crate::probe::Probe; use crate::types::file::FileType; @@ -10,7 +10,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::WriteBytesExt; #[allow(clippy::shadow_unrelated)] -pub(in crate::logic) fn write_id3v1(writer: &mut File, tag: &Id3v1TagRef) -> Result<()> { +pub(crate) fn write_id3v1(writer: &mut File, tag: &Id3v1TagRef) -> Result<()> { let probe = Probe::new(writer).guess_file_type()?; match probe.file_type() { diff --git a/src/logic/id3/v2/flags.rs b/src/id3/v2/flags.rs similarity index 100% rename from src/logic/id3/v2/flags.rs rename to src/id3/v2/flags.rs diff --git a/src/logic/id3/v2/frame/content.rs b/src/id3/v2/frame/content.rs similarity index 93% rename from src/logic/id3/v2/frame/content.rs rename to src/id3/v2/frame/content.rs index b594159c..dbcec898 100644 --- a/src/logic/id3/v2/frame/content.rs +++ b/src/id3/v2/frame/content.rs @@ -1,14 +1,14 @@ use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::frame::{EncodedTextFrame, FrameValue, LanguageFrame}; -use crate::logic::id3::v2::util::text_utils::{decode_text, TextEncoding}; -use crate::logic::id3::v2::Id3v2Version; +use crate::id3::v2::frame::{EncodedTextFrame, FrameValue, LanguageFrame}; +use crate::id3::v2::util::text_utils::{decode_text, TextEncoding}; +use crate::id3::v2::Id3v2Version; use crate::types::picture::Picture; use std::io::Read; use byteorder::ReadBytesExt; -pub(crate) fn parse_content( +pub(super) fn parse_content( content: &mut &[u8], id: &str, version: Id3v2Version, diff --git a/src/logic/id3/v2/frame/header.rs b/src/id3/v2/frame/header.rs similarity index 95% rename from src/logic/id3/v2/frame/header.rs rename to src/id3/v2/frame/header.rs index c3304349..e563bd61 100644 --- a/src/logic/id3/v2/frame/header.rs +++ b/src/id3/v2/frame/header.rs @@ -1,7 +1,7 @@ use super::FrameFlags; use crate::error::{LoftyError, Result}; +use crate::id3::v2::util::upgrade::{upgrade_v2, upgrade_v3}; use crate::id3::v2::FrameID; -use crate::logic::id3::v2::util::upgrade::{upgrade_v2, upgrade_v3}; use std::io::Read; @@ -52,7 +52,7 @@ where let id_str = std::str::from_utf8(&frame_header[..4]).map_err(|_| LoftyError::BadFrameID)?; let (id, size) = if synchsafe { - let size = crate::logic::id3::v2::unsynch_u32(u32::from_be_bytes([ + let size = crate::id3::v2::unsynch_u32(u32::from_be_bytes([ frame_header[4], frame_header[5], frame_header[6], diff --git a/src/logic/id3/v2/frame/mod.rs b/src/id3/v2/frame/mod.rs similarity index 98% rename from src/logic/id3/v2/frame/mod.rs rename to src/id3/v2/frame/mod.rs index 94e4de56..1c468743 100644 --- a/src/logic/id3/v2/frame/mod.rs +++ b/src/id3/v2/frame/mod.rs @@ -1,11 +1,11 @@ -pub(in crate::logic::id3::v2) mod content; +mod content; mod header; -pub(in crate::logic::id3::v2) mod read; +pub(super) mod read; use super::util::text_utils::TextEncoding; use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::util::text_utils::encode_text; -use crate::logic::id3::v2::util::upgrade::{upgrade_v2, upgrade_v3}; +use crate::id3::v2::util::text_utils::encode_text; +use crate::id3::v2::util::upgrade::{upgrade_v2, upgrade_v3}; use crate::types::item::{ItemKey, ItemValue, TagItem}; use crate::types::picture::Picture; use crate::types::tag::TagType; diff --git a/src/logic/id3/v2/frame/read.rs b/src/id3/v2/frame/read.rs similarity index 91% rename from src/logic/id3/v2/frame/read.rs rename to src/id3/v2/frame/read.rs index 8ac47e00..ef85fadf 100644 --- a/src/logic/id3/v2/frame/read.rs +++ b/src/id3/v2/frame/read.rs @@ -1,9 +1,9 @@ use super::header::{parse_header, parse_v2_header}; use super::Frame; use crate::error::{LoftyError, Result}; +use crate::id3::v2::frame::content::parse_content; use crate::id3::v2::FrameValue; -use crate::logic::id3::v2::frame::content::parse_content; -use crate::logic::id3::v2::Id3v2Version; +use crate::id3::v2::Id3v2Version; use std::io::Read; @@ -28,7 +28,7 @@ impl Frame { reader.read_exact(&mut content)?; if flags.unsynchronisation { - content = crate::logic::id3::v2::util::unsynch_content(content.as_slice())?; + content = crate::id3::v2::util::unsynch_content(content.as_slice())?; } if flags.compression { diff --git a/src/logic/id3/v2/items/encapsulated_object.rs b/src/id3/v2/items/encapsulated_object.rs similarity index 96% rename from src/logic/id3/v2/items/encapsulated_object.rs rename to src/id3/v2/items/encapsulated_object.rs index c8ce5b28..6f6af3cb 100644 --- a/src/logic/id3/v2/items/encapsulated_object.rs +++ b/src/id3/v2/items/encapsulated_object.rs @@ -1,5 +1,5 @@ use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::util::text_utils::{decode_text, encode_text, TextEncoding}; +use crate::id3::v2::util::text_utils::{decode_text, encode_text, TextEncoding}; use std::io::{Cursor, Read}; diff --git a/src/id3/v2/items/mod.rs b/src/id3/v2/items/mod.rs new file mode 100644 index 00000000..9cbf11b0 --- /dev/null +++ b/src/id3/v2/items/mod.rs @@ -0,0 +1,4 @@ +pub(super) mod encapsulated_object; +#[cfg(feature = "id3v2_restrictions")] +pub(super) mod restrictions; +pub(super) mod sync_text; diff --git a/src/logic/id3/v2/items/restrictions.rs b/src/id3/v2/items/restrictions.rs similarity index 100% rename from src/logic/id3/v2/items/restrictions.rs rename to src/id3/v2/items/restrictions.rs diff --git a/src/logic/id3/v2/items/sync_text.rs b/src/id3/v2/items/sync_text.rs similarity index 98% rename from src/logic/id3/v2/items/sync_text.rs rename to src/id3/v2/items/sync_text.rs index 4b95ff19..c9256fba 100644 --- a/src/logic/id3/v2/items/sync_text.rs +++ b/src/id3/v2/items/sync_text.rs @@ -3,8 +3,8 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::util::text_utils; -use crate::logic::id3::v2::util::text_utils::{ +use crate::id3::v2::util::text_utils; +use crate::id3::v2::util::text_utils::{ decode_text, encode_text, read_to_terminator, utf16_decode, TextEncoding, }; diff --git a/src/logic/id3/v2/mod.rs b/src/id3/v2/mod.rs similarity index 81% rename from src/logic/id3/v2/mod.rs rename to src/id3/v2/mod.rs index 20c0ad30..86a2dc9b 100644 --- a/src/logic/id3/v2/mod.rs +++ b/src/id3/v2/mod.rs @@ -1,20 +1,48 @@ -pub(crate) mod flags; +//! ID3v2 items and utilities +//! +//! ## Important notes +//! +//! See: +//! +//! * [Id3v2Tag] +//! * [Frame] +mod flags; #[cfg(feature = "id3v2")] -pub(crate) mod frame; +mod frame; #[cfg(feature = "id3v2")] -pub(crate) mod items; +mod items; #[cfg(feature = "id3v2")] pub(crate) mod read; #[cfg(feature = "id3v2")] pub(crate) mod tag; pub(crate) mod util; #[cfg(feature = "id3v2")] -pub(in crate::logic) mod write; +pub(crate) mod write; + +#[cfg(feature = "id3v2")] +pub use frame::{EncodedTextFrame, Frame, FrameFlags, FrameID, FrameValue, LanguageFrame}; +#[cfg(feature = "id3v2")] +pub use items::{ + encapsulated_object::{GEOBInformation, GeneralEncapsulatedObject}, + sync_text::{SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat}, +}; +#[cfg(feature = "id3v2")] +pub use tag::Id3v2Tag; +pub use util::text_utils::TextEncoding; +#[cfg(feature = "id3v2")] +pub use util::upgrade::{upgrade_v2, upgrade_v3}; + +#[cfg(feature = "id3v2")] +pub use flags::Id3v2TagFlags; +#[cfg(not(feature = "id3v2"))] +use flags::Id3v2TagFlags; + +#[cfg(feature = "id3v2_restrictions")] +pub use crate::id3::v2::items::restrictions::*; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2_restrictions")] -use crate::logic::id3::v2::items::restrictions::TagRestrictions; -use flags::Id3v2TagFlags; +use crate::id3::v2::items::restrictions::TagRestrictions; use std::io::Read; diff --git a/src/logic/id3/v2/read.rs b/src/id3/v2/read.rs similarity index 100% rename from src/logic/id3/v2/read.rs rename to src/id3/v2/read.rs diff --git a/src/logic/id3/v2/tag.rs b/src/id3/v2/tag.rs similarity index 96% rename from src/logic/id3/v2/tag.rs rename to src/id3/v2/tag.rs index 0f2d09c1..77166e1a 100644 --- a/src/logic/id3/v2/tag.rs +++ b/src/id3/v2/tag.rs @@ -4,7 +4,7 @@ use super::frame::{Frame, FrameID, FrameValue}; use super::util::text_utils::TextEncoding; use super::Id3v2Version; use crate::error::Result; -use crate::logic::id3::v2::frame::FrameRef; +use crate::id3::v2::frame::FrameRef; use crate::types::item::{ItemKey, ItemValue, TagItem}; use crate::types::tag::{Accessor, Tag, TagType}; @@ -300,7 +300,7 @@ pub(crate) struct Id3v2TagRef<'a> { } impl<'a> Id3v2TagRef<'a> { - pub(in crate::logic) fn write_to(&mut self, file: &mut File) -> Result<()> { + pub(crate) fn write_to(&mut self, file: &mut File) -> Result<()> { super::write::write_id3v2(file, self) } } @@ -333,7 +333,7 @@ mod tests { use crate::id3::v2::{Frame, FrameFlags, FrameValue, Id3v2Tag, LanguageFrame, TextEncoding}; use crate::{Tag, TagType}; - use crate::logic::id3::v2::read_id3v2_header; + use crate::id3::v2::read_id3v2_header; use std::io::Read; #[test] @@ -439,7 +439,7 @@ mod tests { let mut reader = std::io::Cursor::new(&tag[..]); let header = read_id3v2_header(&mut reader).unwrap(); - let parsed_tag = crate::logic::id3::v2::read::parse_id3v2(&mut reader, header).unwrap(); + let parsed_tag = crate::id3::v2::read::parse_id3v2(&mut reader, header).unwrap(); assert_eq!(expected_tag, parsed_tag); } @@ -456,11 +456,11 @@ mod tests { let mut reader = std::io::Cursor::new(&tag_bytes[..]); let header = read_id3v2_header(&mut reader).unwrap(); - let id3v2 = crate::logic::id3::v2::read::parse_id3v2(&mut reader, header).unwrap(); + let id3v2 = crate::id3::v2::read::parse_id3v2(&mut reader, header).unwrap(); let tag: Tag = id3v2.into(); - crate::logic::test_utils::verify_tag(&tag, true, true); + crate::tag_utils::test_utils::verify_tag(&tag, true, true); } #[test] @@ -481,7 +481,7 @@ mod tests { ); } - let tag = crate::logic::test_utils::create_tag(TagType::Id3v2); + let tag = crate::tag_utils::test_utils::create_tag(TagType::Id3v2); let id3v2_tag: Id3v2Tag = tag.into(); diff --git a/src/logic/id3/v2/util/mod.rs b/src/id3/v2/util/mod.rs similarity index 94% rename from src/logic/id3/v2/util/mod.rs rename to src/id3/v2/util/mod.rs index 04920cf6..e769f173 100644 --- a/src/logic/id3/v2/util/mod.rs +++ b/src/id3/v2/util/mod.rs @@ -6,7 +6,7 @@ pub(crate) mod upgrade; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -pub(crate) fn unsynch_content(content: &[u8]) -> Result> { +pub(in crate::id3::v2) fn unsynch_content(content: &[u8]) -> Result> { let mut unsynch_content = Vec::new(); let mut discard = false; diff --git a/src/logic/id3/v2/util/text_utils.rs b/src/id3/v2/util/text_utils.rs similarity index 100% rename from src/logic/id3/v2/util/text_utils.rs rename to src/id3/v2/util/text_utils.rs diff --git a/src/logic/id3/v2/util/upgrade.rs b/src/id3/v2/util/upgrade.rs similarity index 73% rename from src/logic/id3/v2/util/upgrade.rs rename to src/id3/v2/util/upgrade.rs index 4f8b48a5..028778b3 100644 --- a/src/logic/id3/v2/util/upgrade.rs +++ b/src/id3/v2/util/upgrade.rs @@ -1,23 +1,39 @@ +use std::collections::HashMap; + macro_rules! gen_upgrades { - (V2 => [$($($v2_key:tt)|* => $id3v24_from_v2:tt),+]; V3 => [$($($v3_key:tt)|* => $id3v24_from_v3:tt),+]) => { + (V2 => [$($($v2_key:literal)|* => $id3v24_from_v2:literal),+]; V3 => [$($($v3_key:literal)|* => $id3v24_from_v3:literal),+]) => { + lazy_static::lazy_static! { + static ref V2KEYS: HashMap<&'static str, &'static str> = { + let mut map = HashMap::new(); + $( + $( + map.insert($v2_key, $id3v24_from_v2); + )+ + )+ + map + }; + } + + lazy_static::lazy_static! { + static ref V3KEYS: HashMap<&'static str, &'static str> = { + let mut map = HashMap::new(); + $( + $( + map.insert($v3_key, $id3v24_from_v3); + )+ + )+ + map + }; + } + /// Upgrade an ID3v2.2 key to an ID3v2.4 key pub fn upgrade_v2(key: &str) -> Option<&'static str> { - match key { - $( - $($v2_key)|* => Some($id3v24_from_v2), - )+ - _ => None - } + V2KEYS.get(key).map(|s| *s) } /// Upgrade an ID3v2.3 key to an ID3v2.4 key pub fn upgrade_v3(key: &str) -> Option<&'static str> { - match key { - $( - $($v3_key)|* => Some($id3v24_from_v3), - )+ - _ => None - } + V3KEYS.get(key).map(|s| *s) } } } diff --git a/src/logic/id3/v2/write/chunk_file.rs b/src/id3/v2/write/chunk_file.rs similarity index 91% rename from src/logic/id3/v2/write/chunk_file.rs rename to src/id3/v2/write/chunk_file.rs index 24e3f2cb..3f1f4898 100644 --- a/src/logic/id3/v2/write/chunk_file.rs +++ b/src/id3/v2/write/chunk_file.rs @@ -1,12 +1,12 @@ use crate::error::Result; -use crate::logic::iff::chunk::Chunks; +use crate::iff::chunk::Chunks; use std::fs::File; use std::io::{Read, Seek, SeekFrom, Write}; use byteorder::{ByteOrder, WriteBytesExt}; -pub(in crate::logic::id3::v2) fn write_to_chunk_file(data: &mut File, tag: &[u8]) -> Result<()> +pub(in crate::id3::v2) fn write_to_chunk_file(data: &mut File, tag: &[u8]) -> Result<()> where B: ByteOrder, { diff --git a/src/logic/id3/v2/write/frame.rs b/src/id3/v2/write/frame.rs similarity index 94% rename from src/logic/id3/v2/write/frame.rs rename to src/id3/v2/write/frame.rs index 2c27184a..361b32f6 100644 --- a/src/logic/id3/v2/write/frame.rs +++ b/src/id3/v2/write/frame.rs @@ -1,13 +1,13 @@ use crate::error::{LoftyError, Result}; +use crate::id3::v2::frame::{FrameFlags, FrameRef, FrameValueRef}; +use crate::id3::v2::synch_u32; use crate::id3::v2::Id3v2Version; -use crate::logic::id3::v2::frame::{FrameFlags, FrameRef, FrameValueRef}; -use crate::logic::id3::v2::synch_u32; use std::io::Write; use byteorder::{BigEndian, WriteBytesExt}; -pub(in crate::logic::id3::v2) fn create_items<'a, W>( +pub(in crate::id3::v2) fn create_items<'a, W>( writer: &mut W, frames: &mut dyn Iterator>, ) -> Result<()> diff --git a/src/logic/id3/v2/write/mod.rs b/src/id3/v2/write/mod.rs similarity index 91% rename from src/logic/id3/v2/write/mod.rs rename to src/id3/v2/write/mod.rs index 639b7928..429f55a8 100644 --- a/src/logic/id3/v2/write/mod.rs +++ b/src/id3/v2/write/mod.rs @@ -3,8 +3,8 @@ mod frame; use super::Id3v2TagFlags; use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::tag::Id3v2TagRef; -use crate::logic::id3::{find_id3v2, v2::synch_u32}; +use crate::id3::v2::tag::Id3v2TagRef; +use crate::id3::{find_id3v2, v2::synch_u32}; use crate::probe::Probe; use crate::types::file::FileType; @@ -14,7 +14,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{BigEndian, ByteOrder, LittleEndian, WriteBytesExt}; #[allow(clippy::shadow_unrelated)] -pub(in crate::logic) fn write_id3v2(data: &mut File, tag: &mut Id3v2TagRef) -> Result<()> { +pub(crate) fn write_id3v2(data: &mut File, tag: &mut Id3v2TagRef) -> Result<()> { let probe = Probe::new(data).guess_file_type()?; match probe.file_type() { @@ -48,10 +48,7 @@ pub(in crate::logic) fn write_id3v2(data: &mut File, tag: &mut Id3v2TagRef) -> R } // Formats such as WAV and AIFF store the ID3v2 tag in an 'ID3 ' chunk rather than at the beginning of the file -pub(in crate::logic) fn write_id3v2_to_chunk_file( - data: &mut File, - tag: &mut Id3v2TagRef, -) -> Result<()> +fn write_id3v2_to_chunk_file(data: &mut File, tag: &mut Id3v2TagRef) -> Result<()> where B: ByteOrder, { diff --git a/src/logic/iff/aiff/mod.rs b/src/iff/aiff/mod.rs similarity index 95% rename from src/logic/iff/aiff/mod.rs rename to src/iff/aiff/mod.rs index 08decb41..3fab2061 100644 --- a/src/logic/iff/aiff/mod.rs +++ b/src/iff/aiff/mod.rs @@ -2,12 +2,12 @@ mod properties; mod read; #[cfg(feature = "aiff_text_chunks")] pub(crate) mod tag; -pub(in crate::logic) mod write; +pub(crate) mod write; use crate::error::Result; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::tag_methods; +use crate::id3::v2::tag::Id3v2Tag; +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::{Tag, TagType}; diff --git a/src/logic/iff/aiff/properties.rs b/src/iff/aiff/properties.rs similarity index 100% rename from src/logic/iff/aiff/properties.rs rename to src/iff/aiff/properties.rs diff --git a/src/logic/iff/aiff/read.rs b/src/iff/aiff/read.rs similarity index 91% rename from src/logic/iff/aiff/read.rs rename to src/iff/aiff/read.rs index ae370928..d589fb03 100644 --- a/src/logic/iff/aiff/read.rs +++ b/src/iff/aiff/read.rs @@ -3,15 +3,15 @@ use super::tag::AiffTextChunks; use super::AiffFile; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::iff::chunk::Chunks; +use crate::id3::v2::tag::Id3v2Tag; +use crate::iff::chunk::Chunks; use crate::types::properties::FileProperties; use std::io::{Read, Seek, SeekFrom}; use byteorder::BigEndian; -pub(in crate::logic::iff) fn verify_aiff(data: &mut R) -> Result<()> +pub(in crate::iff) fn verify_aiff(data: &mut R) -> Result<()> where R: Read + Seek, { @@ -25,7 +25,7 @@ where Ok(()) } -pub(in crate::logic) fn read_from(data: &mut R, read_properties: bool) -> Result +pub(crate) fn read_from(data: &mut R, read_properties: bool) -> Result where R: Read + Seek, { diff --git a/src/logic/iff/aiff/tag.rs b/src/iff/aiff/tag.rs similarity index 96% rename from src/logic/iff/aiff/tag.rs rename to src/iff/aiff/tag.rs index a12475ba..8dddd8e7 100644 --- a/src/logic/iff/aiff/tag.rs +++ b/src/iff/aiff/tag.rs @@ -1,5 +1,5 @@ use crate::error::Result; -use crate::logic::iff::chunk::Chunks; +use crate::iff::chunk::Chunks; use crate::types::item::{ItemKey, ItemValue, TagItem}; use crate::types::tag::{Accessor, Tag, TagType}; @@ -146,12 +146,12 @@ impl<'a> Into> for &'a Tag { } impl<'a> AiffTextChunksRef<'a> { - pub(in crate::logic) fn write_to(&self, file: &mut File) -> Result<()> { + pub(crate) fn write_to(&self, file: &mut File) -> Result<()> { write_to(file, self) } } -pub(in crate::logic) fn write_to(data: &mut File, tag: &AiffTextChunksRef) -> Result<()> { +pub(crate) fn write_to(data: &mut File, tag: &AiffTextChunksRef) -> Result<()> { fn write_chunk(writer: &mut Vec, key: &str, value: Option<&str>) { if let Some(val) = value { if let Ok(len) = u32::try_from(val.len()) { diff --git a/src/logic/iff/aiff/write.rs b/src/iff/aiff/write.rs similarity index 85% rename from src/logic/iff/aiff/write.rs rename to src/iff/aiff/write.rs index 6987e7c8..2831c86b 100644 --- a/src/logic/iff/aiff/write.rs +++ b/src/iff/aiff/write.rs @@ -1,8 +1,8 @@ use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2TagRef; +use crate::id3::v2::tag::Id3v2TagRef; #[cfg(feature = "aiff_text_chunks")] -use crate::logic::iff::aiff::tag::AiffTextChunksRef; +use crate::iff::aiff::tag::AiffTextChunksRef; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; diff --git a/src/logic/iff/chunk.rs b/src/iff/chunk.rs similarity index 92% rename from src/logic/iff/chunk.rs rename to src/iff/chunk.rs index 5cd8c828..9de5dde5 100644 --- a/src/logic/iff/chunk.rs +++ b/src/iff/chunk.rs @@ -1,16 +1,16 @@ use crate::error::Result; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::read::parse_id3v2; +use crate::id3::v2::read::parse_id3v2; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; +use crate::id3::v2::tag::Id3v2Tag; use std::io::{Read, Seek, SeekFrom}; use std::marker::PhantomData; -use crate::logic::id3::v2::read_id3v2_header; +use crate::id3::v2::read_id3v2_header; use byteorder::{ByteOrder, ReadBytesExt}; -pub(in crate::logic) struct Chunks +pub(crate) struct Chunks where B: ByteOrder, { diff --git a/src/iff/mod.rs b/src/iff/mod.rs new file mode 100644 index 00000000..7c3d4eae --- /dev/null +++ b/src/iff/mod.rs @@ -0,0 +1,13 @@ +//! WAV/AIFF specific items +pub(crate) mod aiff; +pub(crate) mod chunk; +pub(crate) mod wav; + +pub use crate::iff::aiff::AiffFile; +pub use crate::iff::wav::WavFile; + +#[cfg(feature = "aiff_text_chunks")] +pub use crate::iff::aiff::tag::AiffTextChunks; +#[cfg(feature = "riff_info_list")] +pub use crate::iff::wav::tag::RiffInfoList; +pub use wav::{WavFormat, WavProperties}; diff --git a/src/logic/iff/wav/mod.rs b/src/iff/wav/mod.rs similarity index 92% rename from src/logic/iff/wav/mod.rs rename to src/iff/wav/mod.rs index d34e7e3e..714443b1 100644 --- a/src/logic/iff/wav/mod.rs +++ b/src/iff/wav/mod.rs @@ -1,17 +1,18 @@ -pub(crate) mod properties; +mod properties; mod read; #[cfg(feature = "riff_info_list")] pub(crate) mod tag; -pub(in crate::logic) mod write; +pub(crate) mod write; + +pub use crate::iff::wav::properties::{WavFormat, WavProperties}; use crate::error::Result; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::tag_methods; +use crate::id3::v2::tag::Id3v2Tag; +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::{Tag, TagType}; -use properties::WavProperties; #[cfg(feature = "riff_info_list")] use tag::RiffInfoList; diff --git a/src/logic/iff/wav/properties.rs b/src/iff/wav/properties.rs similarity index 100% rename from src/logic/iff/wav/properties.rs rename to src/iff/wav/properties.rs diff --git a/src/logic/iff/wav/read.rs b/src/iff/wav/read.rs similarity index 92% rename from src/logic/iff/wav/read.rs rename to src/iff/wav/read.rs index e6c3d862..1e007dc4 100644 --- a/src/logic/iff/wav/read.rs +++ b/src/iff/wav/read.rs @@ -4,14 +4,14 @@ use super::tag::RiffInfoList; use super::WavFile; use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::iff::chunk::Chunks; +use crate::id3::v2::tag::Id3v2Tag; +use crate::iff::chunk::Chunks; use std::io::{Read, Seek, SeekFrom}; use byteorder::{LittleEndian, ReadBytesExt}; -pub(in crate::logic::iff) fn verify_wav(data: &mut T) -> Result<()> +pub(in crate::iff) fn verify_wav(data: &mut T) -> Result<()> where T: Read + Seek, { @@ -29,7 +29,7 @@ where Ok(()) } -pub(in crate::logic) fn read_from(data: &mut R, read_properties: bool) -> Result +pub(crate) fn read_from(data: &mut R, read_properties: bool) -> Result where R: Read + Seek, { diff --git a/src/logic/iff/wav/tag/mod.rs b/src/iff/wav/tag/mod.rs similarity index 96% rename from src/logic/iff/wav/tag/mod.rs rename to src/iff/wav/tag/mod.rs index 83392c0d..42101efd 100644 --- a/src/logic/iff/wav/tag/mod.rs +++ b/src/iff/wav/tag/mod.rs @@ -1,5 +1,5 @@ -pub(in crate::logic::iff::wav) mod read; -pub(in crate::logic::iff::wav) mod write; +pub(super) mod read; +mod write; use crate::error::Result; use crate::types::item::{ItemKey, ItemValue, TagItem}; @@ -243,12 +243,12 @@ mod tests { let tag: Tag = riff_info.into(); - crate::logic::test_utils::verify_tag(&tag, true, false); + crate::tag_utils::test_utils::verify_tag(&tag, true, false); } #[test] fn tag_to_riff_info() { - let tag = crate::logic::test_utils::create_tag(TagType::RiffInfo); + let tag = crate::tag_utils::test_utils::create_tag(TagType::RiffInfo); let riff_info: RiffInfoList = tag.into(); diff --git a/src/logic/iff/wav/tag/read.rs b/src/iff/wav/tag/read.rs similarity index 90% rename from src/logic/iff/wav/tag/read.rs rename to src/iff/wav/tag/read.rs index e8f80f6c..dae1f56e 100644 --- a/src/logic/iff/wav/tag/read.rs +++ b/src/iff/wav/tag/read.rs @@ -1,12 +1,12 @@ use super::RiffInfoList; use crate::error::{LoftyError, Result}; -use crate::logic::iff::chunk::Chunks; +use crate::iff::chunk::Chunks; use std::io::{Read, Seek, SeekFrom}; use byteorder::LittleEndian; -pub(in crate::logic::iff::wav) fn parse_riff_info( +pub(in crate::iff::wav) fn parse_riff_info( data: &mut R, end: u64, tag: &mut RiffInfoList, diff --git a/src/logic/iff/wav/tag/write.rs b/src/iff/wav/tag/write.rs similarity index 95% rename from src/logic/iff/wav/tag/write.rs rename to src/iff/wav/tag/write.rs index d80d1e57..da6479cb 100644 --- a/src/logic/iff/wav/tag/write.rs +++ b/src/iff/wav/tag/write.rs @@ -1,14 +1,14 @@ use super::RiffInfoListRef; use crate::error::{LoftyError, Result}; -use crate::logic::iff::chunk::Chunks; -use crate::logic::iff::wav::read::verify_wav; +use crate::iff::chunk::Chunks; +use crate::iff::wav::read::verify_wav; use std::fs::File; use std::io::{Read, Seek, SeekFrom, Write}; use byteorder::{LittleEndian, WriteBytesExt}; -pub(in crate::logic::iff::wav) fn write_riff_info( +pub(in crate::iff::wav) fn write_riff_info( data: &mut File, tag: &mut RiffInfoListRef, ) -> Result<()> { diff --git a/src/logic/iff/wav/write.rs b/src/iff/wav/write.rs similarity index 85% rename from src/logic/iff/wav/write.rs rename to src/iff/wav/write.rs index dc88b89e..65873e05 100644 --- a/src/logic/iff/wav/write.rs +++ b/src/iff/wav/write.rs @@ -1,8 +1,8 @@ use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2TagRef; +use crate::id3::v2::tag::Id3v2TagRef; #[cfg(feature = "riff_info_list")] -use crate::logic::iff::wav::tag::RiffInfoListRef; +use crate::iff::wav::tag::RiffInfoListRef; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; diff --git a/src/lib.rs b/src/lib.rs index b41eb549..32d040eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,9 +150,15 @@ clippy::single_match_else )] +pub mod ape; mod error; -pub(crate) mod logic; +pub mod id3; +pub mod iff; +pub mod mp3; +pub mod mp4; +pub mod ogg; mod probe; +pub(crate) mod tag_utils; mod types; pub use crate::error::{LoftyError, Result}; @@ -174,133 +180,3 @@ pub use crate::types::picture::{MimeType, Picture, PictureType}; pub use crate::types::picture::PictureInformation; pub use probe::{read_from, read_from_path}; - -#[cfg(any(feature = "id3v1", feature = "id3v2"))] -pub mod id3 { - //! ID3 specific items - //! - //! ID3 does things differently than other tags, making working with them a little more effort than other formats. - //! Check the other modules for important notes and/or warnings. - - #[cfg(feature = "id3v2")] - pub mod v2 { - //! ID3v2 items and utilities - //! - //! ## Important notes - //! - //! See: - //! - //! * [Id3v2Tag] - //! * [Frame] - - pub use { - crate::logic::id3::v2::flags::Id3v2TagFlags, - crate::logic::id3::v2::frame::{ - EncodedTextFrame, Frame, FrameFlags, FrameID, FrameValue, LanguageFrame, - }, - crate::logic::id3::v2::items::encapsulated_object::{ - GEOBInformation, GeneralEncapsulatedObject, - }, - crate::logic::id3::v2::items::sync_text::{ - SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat, - }, - crate::logic::id3::v2::tag::Id3v2Tag, - crate::logic::id3::v2::util::text_utils::TextEncoding, - crate::logic::id3::v2::util::upgrade::{upgrade_v2, upgrade_v3}, - crate::logic::id3::v2::Id3v2Version, - }; - - #[cfg(feature = "id3v2_restrictions")] - pub use crate::logic::id3::v2::items::restrictions::*; - } - - #[cfg(feature = "id3v1")] - pub mod v1 { - //! ID3v1 items - //! - //! # ID3v1 notes - //! - //! See also: [Id3v1Tag] - //! - //! ## Genres - //! - //! ID3v1 stores the genre in a single byte ranging from 0 to 192 (inclusive). - //! All possible genres have been stored in the [`GENRES`] constant. - //! - //! ## Track Numbers - //! - //! ID3v1 stores the track number in a non-zero byte. - //! A track number of 0 will be treated as an empty field. - //! Additionally, there is no track total field. - pub use crate::logic::id3::v1::constants::GENRES; - pub use crate::logic::id3::v1::tag::Id3v1Tag; - } -} - -pub mod ape { - //! APE specific items - //! - //! ## File notes - //! - //! It is possible for an `APE` file to contain an `ID3v2` tag. For the sake of data preservation, - //! this tag will be read, but **cannot** be written. The only tags allowed by spec are `APEv1/2` and - //! `ID3v1`. - pub use crate::logic::ape::{properties::ApeProperties, ApeFile}; - #[cfg(feature = "ape")] - pub use crate::{ - logic::ape::tag::{ape_tag::ApeTag, item::ApeItem}, - types::picture::APE_PICTURE_TYPES, - }; -} - -pub mod mp3 { - //! MP3 specific items - pub use crate::logic::mp3::header::{ChannelMode, Layer, MpegVersion}; - pub use crate::logic::mp3::{properties::Mp3Properties, Mp3File}; -} - -pub mod mp4 { - //! MP4 specific items - //! - //! ## File notes - //! - //! The only supported tag format is [`Ilst`]. - #[cfg(feature = "mp4_ilst")] - pub use crate::logic::mp4::{ - ilst::{ - atom::{Atom, AtomData}, - Ilst, - }, - AtomIdent, - }; - pub use crate::logic::mp4::{ - properties::{Mp4Codec, Mp4Properties}, - Mp4File, - }; -} - -pub mod ogg { - //! OPUS/FLAC/Vorbis specific items - //! - //! ## File notes - //! - //! The only supported tag format is [`VorbisComments`] - pub use crate::logic::ogg::flac::FlacFile; - pub use crate::logic::ogg::opus::{properties::OpusProperties, OpusFile}; - #[cfg(feature = "vorbis_comments")] - pub use crate::logic::ogg::tag::VorbisComments; - pub use crate::logic::ogg::vorbis::{properties::VorbisProperties, VorbisFile}; -} - -pub mod iff { - //! WAV/AIFF specific items - pub use crate::logic::iff::aiff::AiffFile; - pub use crate::logic::iff::wav::WavFile; - - #[cfg(feature = "aiff_text_chunks")] - pub use crate::logic::iff::aiff::tag::AiffTextChunks; - #[cfg(feature = "riff_info_list")] - pub use crate::logic::iff::wav::tag::RiffInfoList; - - pub use crate::logic::iff::wav::properties::{WavFormat, WavProperties}; -} diff --git a/src/logic/id3/v1/mod.rs b/src/logic/id3/v1/mod.rs deleted file mode 100644 index 49f8ec60..00000000 --- a/src/logic/id3/v1/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub(crate) mod constants; -pub(in crate::logic) mod read; -pub(crate) mod tag; -pub(in crate::logic) mod write; diff --git a/src/logic/id3/v2/items/mod.rs b/src/logic/id3/v2/items/mod.rs deleted file mode 100644 index 7c48e453..00000000 --- a/src/logic/id3/v2/items/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub(crate) mod encapsulated_object; -#[cfg(feature = "id3v2_restrictions")] -pub(crate) mod restrictions; -pub(crate) mod sync_text; diff --git a/src/logic/iff/mod.rs b/src/logic/iff/mod.rs deleted file mode 100644 index effa7927..00000000 --- a/src/logic/iff/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub(crate) mod aiff; -pub(in crate::logic) mod chunk; -pub(crate) mod wav; diff --git a/src/logic/mp3/constants.rs b/src/mp3/constants.rs similarity index 100% rename from src/logic/mp3/constants.rs rename to src/mp3/constants.rs diff --git a/src/logic/mp3/header.rs b/src/mp3/header.rs similarity index 100% rename from src/logic/mp3/header.rs rename to src/mp3/header.rs diff --git a/src/logic/mp3/mod.rs b/src/mp3/mod.rs similarity index 88% rename from src/logic/mp3/mod.rs rename to src/mp3/mod.rs index 6432a939..45e640c8 100644 --- a/src/logic/mp3/mod.rs +++ b/src/mp3/mod.rs @@ -1,21 +1,24 @@ +//! MP3 specific items mod constants; pub(crate) mod header; -pub(crate) mod properties; -pub(crate) mod read; -pub(in crate::logic) mod write; +mod properties; +mod read; +pub(crate) mod write; + +pub use header::{ChannelMode, Layer, MpegVersion}; +pub use properties::Mp3Properties; -use crate::error::Result; #[cfg(feature = "ape")] -use crate::logic::ape::tag::ape_tag::ApeTag; +use crate::ape::tag::ape_tag::ApeTag; +use crate::error::Result; #[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1Tag; +use crate::id3::v1::tag::Id3v1Tag; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2Tag; -use crate::logic::tag_methods; +use crate::id3::v2::tag::Id3v2Tag; +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::{Tag, TagType}; -use properties::Mp3Properties; use std::io::{Read, Seek}; diff --git a/src/logic/mp3/properties.rs b/src/mp3/properties.rs similarity index 100% rename from src/logic/mp3/properties.rs rename to src/mp3/properties.rs diff --git a/src/logic/mp3/read.rs b/src/mp3/read.rs similarity index 89% rename from src/logic/mp3/read.rs rename to src/mp3/read.rs index 89863d28..bc10c29b 100644 --- a/src/logic/mp3/read.rs +++ b/src/mp3/read.rs @@ -1,16 +1,16 @@ use super::header::{verify_frame_sync, Header, XingHeader}; use super::{Mp3File, Mp3Properties}; +#[cfg(feature = "ape")] +use crate::ape::tag::ape_tag::ApeTag; +use crate::ape::tag::read_ape_header; use crate::error::{LoftyError, Result}; +#[cfg(feature = "id3v1")] +use crate::id3::v1::tag::Id3v1Tag; +#[cfg(feature = "id3v2")] +use crate::id3::v2::read::parse_id3v2; +use crate::id3::v2::read_id3v2_header; #[cfg(feature = "id3v2")] use crate::id3::v2::Id3v2Tag; -#[cfg(feature = "ape")] -use crate::logic::ape::tag::ape_tag::ApeTag; -use crate::logic::ape::tag::read_ape_header; -#[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1Tag; -#[cfg(feature = "id3v2")] -use crate::logic::id3::v2::read::parse_id3v2; -use crate::logic::id3::v2::read_id3v2_header; use std::io::{Read, Seek, SeekFrom}; @@ -85,7 +85,7 @@ where #[cfg(feature = "id3v1")] { - id3v1_tag = Some(crate::logic::id3::v1::read::parse_id3v1(id3v1_read)); + id3v1_tag = Some(crate::id3::v1::read::parse_id3v1(id3v1_read)); } continue; @@ -105,9 +105,7 @@ where #[cfg(feature = "ape")] { - ape_tag = Some(crate::logic::ape::tag::read::read_ape_tag( - data, ape_header, - )?); + ape_tag = Some(crate::ape::tag::read::read_ape_tag(data, ape_header)?); } continue; diff --git a/src/logic/mp3/write.rs b/src/mp3/write.rs similarity index 82% rename from src/logic/mp3/write.rs rename to src/mp3/write.rs index 2bd9dd42..62d10c06 100644 --- a/src/logic/mp3/write.rs +++ b/src/mp3/write.rs @@ -1,10 +1,10 @@ -use crate::error::{LoftyError, Result}; #[cfg(feature = "ape")] -use crate::logic::ape::tag::ape_tag::ApeTagRef; +use crate::ape::tag::ape_tag::ApeTagRef; +use crate::error::{LoftyError, Result}; #[cfg(feature = "id3v1")] -use crate::logic::id3::v1::tag::Id3v1TagRef; +use crate::id3::v1::tag::Id3v1TagRef; #[cfg(feature = "id3v2")] -use crate::logic::id3::v2::tag::Id3v2TagRef; +use crate::id3::v2::tag::Id3v2TagRef; #[allow(unused_imports)] use crate::types::tag::{Tag, TagType}; diff --git a/src/logic/mp4/atom_info.rs b/src/mp4/atom_info.rs similarity index 100% rename from src/logic/mp4/atom_info.rs rename to src/mp4/atom_info.rs diff --git a/src/logic/mp4/ilst/atom.rs b/src/mp4/ilst/atom.rs similarity index 98% rename from src/logic/mp4/ilst/atom.rs rename to src/mp4/ilst/atom.rs index 15ec6b27..1131c81d 100644 --- a/src/logic/mp4/ilst/atom.rs +++ b/src/mp4/ilst/atom.rs @@ -1,4 +1,4 @@ -use crate::logic::mp4::AtomIdent; +use crate::mp4::AtomIdent; use crate::types::picture::Picture; #[derive(Debug, PartialEq, Clone)] diff --git a/src/logic/mp4/ilst/mod.rs b/src/mp4/ilst/mod.rs similarity index 96% rename from src/logic/mp4/ilst/mod.rs rename to src/mp4/ilst/mod.rs index 1dfda72b..8a84de1a 100644 --- a/src/logic/mp4/ilst/mod.rs +++ b/src/mp4/ilst/mod.rs @@ -1,6 +1,6 @@ -pub(crate) mod atom; -pub(in crate::logic::mp4) mod read; -pub(in crate::logic) mod write; +pub(super) mod atom; +pub(super) mod read; +pub(crate) mod write; use super::AtomIdent; use crate::error::Result; @@ -221,7 +221,7 @@ pub(crate) struct IlstRef<'a> { } impl<'a> IlstRef<'a> { - pub(in crate::logic) fn write_to(&mut self, file: &mut File) -> Result<()> { + pub(crate) fn write_to(&mut self, file: &mut File) -> Result<()> { write::write_to(file, self) } } @@ -355,7 +355,7 @@ mod tests { let tag: Tag = ilst.into(); - crate::logic::test_utils::verify_tag(&tag, false, true); + crate::tag_utils::test_utils::verify_tag(&tag, false, true); } #[test] @@ -368,7 +368,7 @@ mod tests { assert_eq!(atom.data(), &data); } - let tag = crate::logic::test_utils::create_tag(TagType::Mp4Ilst); + let tag = crate::tag_utils::test_utils::create_tag(TagType::Mp4Ilst); let ilst: Ilst = tag.into(); diff --git a/src/logic/mp4/ilst/read.rs b/src/mp4/ilst/read.rs similarity index 96% rename from src/logic/mp4/ilst/read.rs rename to src/mp4/ilst/read.rs index a14771fb..2b6aefcc 100644 --- a/src/logic/mp4/ilst/read.rs +++ b/src/mp4/ilst/read.rs @@ -1,8 +1,8 @@ use super::{Atom, AtomData, AtomIdent, Ilst}; use crate::error::{LoftyError, Result}; -use crate::logic::id3::v2::util::text_utils::utf16_decode; -use crate::logic::mp4::atom_info::AtomInfo; -use crate::logic::mp4::read::skip_unneeded; +use crate::id3::v2::util::text_utils::utf16_decode; +use crate::mp4::atom_info::AtomInfo; +use crate::mp4::read::skip_unneeded; use crate::types::picture::{MimeType, Picture, PictureType}; use std::borrow::Cow; diff --git a/src/logic/mp4/ilst/write.rs b/src/mp4/ilst/write.rs similarity index 96% rename from src/logic/mp4/ilst/write.rs rename to src/mp4/ilst/write.rs index db338432..bf062303 100644 --- a/src/logic/mp4/ilst/write.rs +++ b/src/mp4/ilst/write.rs @@ -1,9 +1,9 @@ use super::{AtomDataRef, IlstRef}; use crate::error::{LoftyError, Result}; -use crate::logic::mp4::ilst::{AtomIdentRef, AtomRef}; -use crate::logic::mp4::moov::Moov; -use crate::logic::mp4::read::nested_atom; -use crate::logic::mp4::read::verify_mp4; +use crate::mp4::ilst::{AtomIdentRef, AtomRef}; +use crate::mp4::moov::Moov; +use crate::mp4::read::nested_atom; +use crate::mp4::read::verify_mp4; use crate::types::picture::MimeType; use crate::types::picture::Picture; @@ -12,7 +12,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{BigEndian, WriteBytesExt}; -pub(in crate::logic) fn write_to(data: &mut File, tag: &mut IlstRef) -> Result<()> { +pub(in crate) fn write_to(data: &mut File, tag: &mut IlstRef) -> Result<()> { verify_mp4(data)?; let moov = Moov::find(data)?; diff --git a/src/logic/mp4/mod.rs b/src/mp4/mod.rs similarity index 85% rename from src/logic/mp4/mod.rs rename to src/mp4/mod.rs index e02c79c2..5e21af1d 100644 --- a/src/logic/mp4/mod.rs +++ b/src/mp4/mod.rs @@ -1,19 +1,29 @@ +//! MP4 specific items +//! +//! ## File notes +//! +//! The only supported tag format is [`Ilst`]. mod atom_info; #[cfg(feature = "mp4_ilst")] pub(crate) mod ilst; mod moov; -pub(crate) mod properties; +mod properties; mod read; mod trak; -use crate::logic::tag_methods; +pub use crate::mp4::properties::{Mp4Codec, Mp4Properties}; +#[cfg(feature = "mp4_ilst")] +pub use crate::mp4::{ + atom_info::AtomIdent, + ilst::{ + atom::{Atom, AtomData}, + Ilst, + }, +}; + +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::{FileProperties, Result, TagType}; -#[cfg(feature = "mp4_ilst")] -pub use atom_info::AtomIdent; -#[cfg(feature = "mp4_ilst")] -use ilst::Ilst; -use properties::Mp4Properties; use std::io::{Read, Seek}; diff --git a/src/logic/mp4/moov.rs b/src/mp4/moov.rs similarity index 100% rename from src/logic/mp4/moov.rs rename to src/mp4/moov.rs diff --git a/src/logic/mp4/properties.rs b/src/mp4/properties.rs similarity index 100% rename from src/logic/mp4/properties.rs rename to src/mp4/properties.rs diff --git a/src/logic/mp4/read.rs b/src/mp4/read.rs similarity index 96% rename from src/logic/mp4/read.rs rename to src/mp4/read.rs index 21d9ec34..d2423236 100644 --- a/src/logic/mp4/read.rs +++ b/src/mp4/read.rs @@ -6,7 +6,7 @@ use crate::error::{LoftyError, Result}; use std::io::{Read, Seek, SeekFrom}; -pub(in crate::logic::mp4) fn verify_mp4(data: &mut R) -> Result +pub(in crate::mp4) fn verify_mp4(data: &mut R) -> Result where R: Read + Seek, { diff --git a/src/logic/mp4/trak.rs b/src/mp4/trak.rs similarity index 100% rename from src/logic/mp4/trak.rs rename to src/mp4/trak.rs diff --git a/src/logic/ogg/constants.rs b/src/ogg/constants.rs similarity index 100% rename from src/logic/ogg/constants.rs rename to src/ogg/constants.rs diff --git a/src/logic/ogg/flac/block.rs b/src/ogg/flac/block.rs similarity index 91% rename from src/logic/ogg/flac/block.rs rename to src/ogg/flac/block.rs index 1c57db77..1fbf75fe 100644 --- a/src/logic/ogg/flac/block.rs +++ b/src/ogg/flac/block.rs @@ -15,7 +15,7 @@ pub(super) struct Block { } impl Block { - pub(in crate::logic::ogg) fn read(data: &mut R) -> Result + pub(in crate::ogg) fn read(data: &mut R) -> Result where R: Read + Seek, { diff --git a/src/logic/ogg/flac/mod.rs b/src/ogg/flac/mod.rs similarity index 96% rename from src/logic/ogg/flac/mod.rs rename to src/ogg/flac/mod.rs index 84dbe239..a170063b 100644 --- a/src/logic/ogg/flac/mod.rs +++ b/src/ogg/flac/mod.rs @@ -2,12 +2,12 @@ mod block; mod properties; mod read; #[cfg(feature = "vorbis_comments")] -pub(in crate::logic) mod write; +pub(crate) mod write; #[cfg(feature = "vorbis_comments")] use super::tag::VorbisComments; use crate::error::Result; -use crate::logic::tag_methods; +use crate::tag_utils::tag_methods; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::TagType; diff --git a/src/logic/ogg/flac/properties.rs b/src/ogg/flac/properties.rs similarity index 100% rename from src/logic/ogg/flac/properties.rs rename to src/ogg/flac/properties.rs diff --git a/src/logic/ogg/flac/read.rs b/src/ogg/flac/read.rs similarity index 96% rename from src/logic/ogg/flac/read.rs rename to src/ogg/flac/read.rs index c03025e9..7d0b0ca6 100644 --- a/src/logic/ogg/flac/read.rs +++ b/src/ogg/flac/read.rs @@ -2,7 +2,7 @@ use super::block::Block; use super::FlacFile; use crate::error::{LoftyError, Result}; #[cfg(feature = "vorbis_comments")] -use crate::logic::ogg::{read::read_comments, tag::VorbisComments}; +use crate::ogg::{read::read_comments, tag::VorbisComments}; #[cfg(feature = "vorbis_comments")] use crate::types::picture::Picture; use crate::types::properties::FileProperties; diff --git a/src/logic/ogg/flac/write.rs b/src/ogg/flac/write.rs similarity index 95% rename from src/logic/ogg/flac/write.rs rename to src/ogg/flac/write.rs index f5087705..d0214791 100644 --- a/src/logic/ogg/flac/write.rs +++ b/src/ogg/flac/write.rs @@ -1,8 +1,8 @@ use super::block::Block; use super::read::verify_flac; use crate::error::{LoftyError, Result}; -use crate::logic::ogg::tag::VorbisCommentsRef; -use crate::logic::ogg::write::create_comments; +use crate::ogg::tag::VorbisCommentsRef; +use crate::ogg::write::create_comments; use crate::types::picture::{Picture, PictureInformation}; use std::fs::File; @@ -10,7 +10,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{LittleEndian, WriteBytesExt}; -pub(in crate::logic) fn write_to(data: &mut File, tag: &mut VorbisCommentsRef) -> Result<()> { +pub(in crate) fn write_to(data: &mut File, tag: &mut VorbisCommentsRef) -> Result<()> { let stream_info = verify_flac(data)?; let stream_info_end = stream_info.end as usize; diff --git a/src/logic/ogg/mod.rs b/src/ogg/mod.rs similarity index 77% rename from src/logic/ogg/mod.rs rename to src/ogg/mod.rs index fe0bffde..7d58d763 100644 --- a/src/logic/ogg/mod.rs +++ b/src/ogg/mod.rs @@ -1,13 +1,23 @@ +//! OPUS/FLAC/Vorbis specific items +//! +//! ## File notes +//! +//! The only supported tag format is [`VorbisComments`] pub(crate) mod constants; -pub(crate) mod read; -#[cfg(feature = "vorbis_comments")] -pub(crate) mod write; - pub(crate) mod flac; pub(crate) mod opus; +pub(crate) mod read; #[cfg(feature = "vorbis_comments")] pub(crate) mod tag; pub(crate) mod vorbis; +#[cfg(feature = "vorbis_comments")] +pub(crate) mod write; + +pub use crate::ogg::flac::FlacFile; +pub use crate::ogg::opus::{properties::OpusProperties, OpusFile}; +#[cfg(feature = "vorbis_comments")] +pub use crate::ogg::tag::VorbisComments; +pub use crate::ogg::vorbis::{properties::VorbisProperties, VorbisFile}; use crate::{LoftyError, Result}; @@ -16,7 +26,7 @@ use std::io::{Read, Seek}; use ogg_pager::Page; #[cfg(feature = "vorbis_comments")] -pub fn page_from_packet(packet: &mut [u8]) -> Result> { +pub(self) fn page_from_packet(packet: &mut [u8]) -> Result> { let mut pages: Vec = Vec::new(); let reader = &mut &packet[..]; diff --git a/src/logic/ogg/opus/mod.rs b/src/ogg/opus/mod.rs similarity index 96% rename from src/logic/ogg/opus/mod.rs rename to src/ogg/opus/mod.rs index 55cf67fb..e5de6044 100644 --- a/src/logic/ogg/opus/mod.rs +++ b/src/ogg/opus/mod.rs @@ -1,4 +1,4 @@ -pub(crate) mod properties; +pub(super) mod properties; #[cfg(feature = "vorbis_comments")] pub(super) mod write; @@ -6,7 +6,7 @@ use super::find_last_page; #[cfg(feature = "vorbis_comments")] use super::tag::VorbisComments; use crate::error::Result; -use crate::logic::ogg::constants::{OPUSHEAD, OPUSTAGS}; +use crate::ogg::constants::{OPUSHEAD, OPUSTAGS}; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::TagType; diff --git a/src/logic/ogg/opus/properties.rs b/src/ogg/opus/properties.rs similarity index 96% rename from src/logic/ogg/opus/properties.rs rename to src/ogg/opus/properties.rs index 661e0094..eb4c6a25 100644 --- a/src/logic/ogg/opus/properties.rs +++ b/src/ogg/opus/properties.rs @@ -82,10 +82,7 @@ impl OpusProperties { } } -pub(in crate::logic::ogg) fn read_properties( - data: &mut R, - first_page: &Page, -) -> Result +pub(in crate::ogg) fn read_properties(data: &mut R, first_page: &Page) -> Result where R: Read + Seek, { diff --git a/src/logic/ogg/opus/write.rs b/src/ogg/opus/write.rs similarity index 95% rename from src/logic/ogg/opus/write.rs rename to src/ogg/opus/write.rs index 60332ca5..2660f238 100644 --- a/src/logic/ogg/opus/write.rs +++ b/src/ogg/opus/write.rs @@ -5,7 +5,7 @@ use std::io::{Read, Seek, SeekFrom, Write}; use ogg_pager::Page; -pub(in crate::logic) fn write_to( +pub(crate) fn write_to( data: &mut File, writer: &mut Vec, ser: u32, diff --git a/src/logic/ogg/read.rs b/src/ogg/read.rs similarity index 100% rename from src/logic/ogg/read.rs rename to src/ogg/read.rs diff --git a/src/logic/ogg/tag.rs b/src/ogg/tag.rs similarity index 95% rename from src/logic/ogg/tag.rs rename to src/ogg/tag.rs index 599c127d..0c22f581 100644 --- a/src/logic/ogg/tag.rs +++ b/src/ogg/tag.rs @@ -1,5 +1,5 @@ use crate::error::{LoftyError, Result}; -use crate::logic::ogg::constants::{OPUSHEAD, VORBIS_IDENT_HEAD}; +use crate::ogg::constants::{OPUSHEAD, VORBIS_IDENT_HEAD}; use crate::probe::Probe; use crate::types::file::FileType; use crate::types::item::{ItemKey, ItemValue, TagItem}; @@ -253,7 +253,7 @@ mod tests { let mut reader = std::io::Cursor::new(&tag[..]); let mut parsed_tag = VorbisComments::default(); - crate::logic::ogg::read::read_comments(&mut reader, &mut parsed_tag).unwrap(); + crate::ogg::read::read_comments(&mut reader, &mut parsed_tag).unwrap(); assert_eq!(expected_tag, parsed_tag); } @@ -269,16 +269,16 @@ mod tests { let mut reader = std::io::Cursor::new(&tag_bytes[..]); let mut vorbis_comments = VorbisComments::default(); - crate::logic::ogg::read::read_comments(&mut reader, &mut vorbis_comments).unwrap(); + crate::ogg::read::read_comments(&mut reader, &mut vorbis_comments).unwrap(); let tag: Tag = vorbis_comments.into(); - crate::logic::test_utils::verify_tag(&tag, true, true); + crate::tag_utils::test_utils::verify_tag(&tag, true, true); } #[test] fn tag_to_vorbis_comments() { - let tag = crate::logic::test_utils::create_tag(TagType::VorbisComments); + let tag = crate::tag_utils::test_utils::create_tag(TagType::VorbisComments); let vorbis_comments: VorbisComments = tag.into(); diff --git a/src/logic/ogg/vorbis/mod.rs b/src/ogg/vorbis/mod.rs similarity index 94% rename from src/logic/ogg/vorbis/mod.rs rename to src/ogg/vorbis/mod.rs index eb9e8eaa..9ad9eb6f 100644 --- a/src/logic/ogg/vorbis/mod.rs +++ b/src/ogg/vorbis/mod.rs @@ -1,12 +1,12 @@ -pub(crate) mod properties; +pub(super) mod properties; #[cfg(feature = "vorbis_comments")] -pub(in crate::logic::ogg) mod write; +pub(in crate::ogg) mod write; use super::find_last_page; #[cfg(feature = "vorbis_comments")] use super::tag::VorbisComments; use crate::error::Result; -use crate::logic::ogg::constants::{VORBIS_COMMENT_HEAD, VORBIS_IDENT_HEAD}; +use crate::ogg::constants::{VORBIS_COMMENT_HEAD, VORBIS_IDENT_HEAD}; use crate::types::file::{AudioFile, FileType, TaggedFile}; use crate::types::properties::FileProperties; use crate::types::tag::TagType; diff --git a/src/logic/ogg/vorbis/properties.rs b/src/ogg/vorbis/properties.rs similarity index 98% rename from src/logic/ogg/vorbis/properties.rs rename to src/ogg/vorbis/properties.rs index 8fb20c72..2b71571e 100644 --- a/src/logic/ogg/vorbis/properties.rs +++ b/src/ogg/vorbis/properties.rs @@ -106,7 +106,7 @@ impl VorbisProperties { } } -pub(in crate::logic::ogg) fn read_properties( +pub(in crate::ogg) fn read_properties( data: &mut R, first_page: &Page, ) -> Result diff --git a/src/logic/ogg/vorbis/write.rs b/src/ogg/vorbis/write.rs similarity index 97% rename from src/logic/ogg/vorbis/write.rs rename to src/ogg/vorbis/write.rs index 556ba18c..45a5b75b 100644 --- a/src/logic/ogg/vorbis/write.rs +++ b/src/ogg/vorbis/write.rs @@ -1,5 +1,5 @@ use crate::error::{LoftyError, Result}; -use crate::logic::ogg::constants::VORBIS_SETUP_HEAD; +use crate::ogg::constants::VORBIS_SETUP_HEAD; use std::fs::File; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; @@ -7,7 +7,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{LittleEndian, ReadBytesExt}; use ogg_pager::Page; -pub(in crate::logic) fn write_to( +pub(crate) fn write_to( data: &mut File, writer: &mut Vec, first_md_content: Vec, diff --git a/src/logic/ogg/write.rs b/src/ogg/write.rs similarity index 92% rename from src/logic/ogg/write.rs rename to src/ogg/write.rs index 8d0059ca..87e8faa6 100644 --- a/src/logic/ogg/write.rs +++ b/src/ogg/write.rs @@ -1,8 +1,8 @@ use super::{page_from_packet, verify_signature}; use crate::error::{LoftyError, Result}; -use crate::logic::ogg::constants::OPUSTAGS; -use crate::logic::ogg::constants::VORBIS_COMMENT_HEAD; -use crate::logic::ogg::tag::VorbisCommentsRef; +use crate::ogg::constants::OPUSTAGS; +use crate::ogg::constants::VORBIS_COMMENT_HEAD; +use crate::ogg::tag::VorbisCommentsRef; use crate::types::picture::PictureInformation; use crate::types::tag::{Tag, TagType}; @@ -13,8 +13,9 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use ogg_pager::Page; -pub(in crate::logic) fn write_to(data: &mut File, tag: &Tag, sig: &[u8]) -> Result<()> { +pub(in crate) fn write_to(data: &mut File, tag: &Tag, sig: &[u8]) -> Result<()> { match tag.tag_type() { + #[cfg(feature = "vorbis_comments")] TagType::VorbisComments => write(data, &mut Into::::into(tag), sig), _ => Err(LoftyError::UnsupportedTag), } diff --git a/src/probe.rs b/src/probe.rs index 8e30bee3..57c67004 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -1,13 +1,13 @@ +use crate::ape::ApeFile; use crate::error::{LoftyError, Result}; -use crate::logic::ape::ApeFile; -use crate::logic::iff::aiff::AiffFile; -use crate::logic::iff::wav::WavFile; -use crate::logic::mp3::header::verify_frame_sync; -use crate::logic::mp3::Mp3File; -use crate::logic::mp4::Mp4File; -use crate::logic::ogg::flac::FlacFile; -use crate::logic::ogg::opus::OpusFile; -use crate::logic::ogg::vorbis::VorbisFile; +use crate::iff::aiff::AiffFile; +use crate::iff::wav::WavFile; +use crate::mp3::header::verify_frame_sync; +use crate::mp3::Mp3File; +use crate::mp4::Mp4File; +use crate::ogg::flac::FlacFile; +use crate::ogg::opus::OpusFile; +use crate::ogg::vorbis::VorbisFile; use crate::types::file::{AudioFile, FileType, TaggedFile}; use std::fs::File; diff --git a/src/logic/mod.rs b/src/tag_utils.rs similarity index 72% rename from src/logic/mod.rs rename to src/tag_utils.rs index 86fa92f9..5723f70a 100644 --- a/src/logic/mod.rs +++ b/src/tag_utils.rs @@ -1,48 +1,45 @@ -pub(crate) mod ape; -pub(crate) mod id3; -pub(crate) mod iff; -pub(crate) mod mp3; -pub(crate) mod mp4; -pub(crate) mod ogg; - use crate::error::{LoftyError, Result}; -use crate::types::file::FileType; -use crate::types::tag::Tag; #[cfg(feature = "mp4_ilst")] -use mp4::ilst::IlstRef; +use crate::mp4::ilst::IlstRef; #[cfg(feature = "vorbis_comments")] -use ogg::{ +use crate::ogg::{ constants::{OPUSTAGS, VORBIS_COMMENT_HEAD}, tag::VorbisCommentsRef, }; +use crate::types::file::FileType; +use crate::types::tag::Tag; use std::fs::File; #[allow(unreachable_patterns)] pub(crate) fn write_tag(tag: &Tag, file: &mut File, file_type: FileType) -> Result<()> { match file_type { - FileType::AIFF => iff::aiff::write::write_to(file, tag), - FileType::APE => ape::write::write_to(file, tag), + FileType::AIFF => crate::iff::aiff::write::write_to(file, tag), + FileType::APE => crate::ape::write::write_to(file, tag), #[cfg(feature = "vorbis_comments")] - FileType::FLAC => ogg::flac::write::write_to(file, &mut Into::::into(tag)), - FileType::MP3 => mp3::write::write_to(file, tag), + FileType::FLAC => { + crate::ogg::flac::write::write_to(file, &mut Into::::into(tag)) + }, + FileType::MP3 => crate::mp3::write::write_to(file, tag), #[cfg(feature = "mp4_ilst")] - FileType::MP4 => mp4::ilst::write::write_to(file, &mut Into::::into(tag)), + FileType::MP4 => crate::mp4::ilst::write::write_to(file, &mut Into::::into(tag)), #[cfg(feature = "vorbis_comments")] - FileType::Opus => ogg::write::write_to(file, tag, OPUSTAGS), + FileType::Opus => crate::ogg::write::write_to(file, tag, OPUSTAGS), #[cfg(feature = "vorbis_comments")] - FileType::Vorbis => ogg::write::write_to(file, tag, VORBIS_COMMENT_HEAD), - FileType::WAV => iff::wav::write::write_to(file, tag), + FileType::Vorbis => crate::ogg::write::write_to(file, tag, VORBIS_COMMENT_HEAD), + FileType::WAV => crate::iff::wav::write::write_to(file, tag), _ => Err(LoftyError::UnsupportedTag), } } macro_rules! tag_methods { - ($( - $(#[$attr:meta])?; - $display_name:tt, - $name:ident, - $ty:ty);* + ( + $( + $(#[$attr:meta])?; + $display_name:tt, + $name:ident, + $ty:ty + );* ) => { paste::paste! { $( @@ -68,11 +65,11 @@ macro_rules! tag_methods { } } -pub(in crate::logic) use tag_methods; +pub(crate) use tag_methods; #[cfg(test)] // Used for tag conversion tests -mod test_utils { +pub(crate) mod test_utils { use crate::{ItemKey, Tag, TagType}; pub(crate) fn create_tag(tag_type: TagType) -> Tag { diff --git a/src/types/file.rs b/src/types/file.rs index 7bf16efe..172f35e5 100644 --- a/src/types/file.rs +++ b/src/types/file.rs @@ -283,7 +283,7 @@ impl FileType { } pub(crate) fn from_buffer_inner(buf: &[u8]) -> Result<(Option, u32)> { - use crate::logic::id3::v2::unsynch_u32; + use crate::id3::v2::unsynch_u32; if buf.is_empty() { return Err(LoftyError::EmptyFile); @@ -306,7 +306,7 @@ impl FileType { } fn quick_type_guess(buf: &[u8]) -> Option { - use crate::logic::mp3::header::verify_frame_sync; + use crate::mp3::header::verify_frame_sync; match buf.first().unwrap() { 77 if buf.starts_with(b"MAC") => Some(Self::APE), diff --git a/src/types/item.rs b/src/types/item.rs index 486c295e..809e75b4 100644 --- a/src/types/item.rs +++ b/src/types/item.rs @@ -610,7 +610,7 @@ impl TagItem { pub(crate) fn re_map(&self, tag_type: TagType) -> Option<()> { #[cfg(feature = "id3v1")] if tag_type == TagType::Id3v1 { - use crate::logic::id3::v1::constants::VALID_ITEMKEYS; + use crate::id3::v1::constants::VALID_ITEMKEYS; return VALID_ITEMKEYS.contains(&self.item_key).then(|| ()); } diff --git a/src/types/picture.rs b/src/types/picture.rs index fd7c8ea8..4285ab63 100644 --- a/src/types/picture.rs +++ b/src/types/picture.rs @@ -1,6 +1,6 @@ use crate::{LoftyError, Result}; #[cfg(feature = "id3v2")] -use {crate::logic::id3::v2::util::text_utils::TextEncoding, crate::logic::id3::v2::Id3v2Version}; +use {crate::id3::v2::util::text_utils::TextEncoding, crate::id3::v2::Id3v2Version}; use std::borrow::Cow; #[cfg(any(feature = "vorbis_comments", feature = "ape", feature = "id3v2"))] @@ -587,13 +587,9 @@ impl Picture { data.write_u8(self.pic_type.as_u8())?; match &self.description { - Some(description) => { - data.write_all(&*crate::logic::id3::v2::util::text_utils::encode_text( - description, - text_encoding, - true, - ))? - }, + Some(description) => data.write_all( + &*crate::id3::v2::util::text_utils::encode_text(description, text_encoding, true), + )?, None => data.write_u8(0)?, } @@ -643,18 +639,14 @@ impl Picture { }, } } else { - (crate::logic::id3::v2::util::text_utils::decode_text( - &mut cursor, - TextEncoding::UTF8, - true, - )?) - .map_or(MimeType::None, |mime_type| MimeType::from_str(&*mime_type)) + (crate::id3::v2::util::text_utils::decode_text(&mut cursor, TextEncoding::UTF8, true)?) + .map_or(MimeType::None, |mime_type| MimeType::from_str(&*mime_type)) }; let picture_type = PictureType::from_u8(cursor.read_u8()?); let description = - crate::logic::id3::v2::util::text_utils::decode_text(&mut cursor, encoding, true)? + crate::id3::v2::util::text_utils::decode_text(&mut cursor, encoding, true)? .map(Cow::from); let mut data = Vec::new(); diff --git a/src/types/tag.rs b/src/types/tag.rs index c76ef276..98171171 100644 --- a/src/types/tag.rs +++ b/src/types/tag.rs @@ -289,7 +289,7 @@ impl Tag { match probe.file_type() { Some(file_type) => { if file_type.supports_tag_type(self.tag_type()) { - crate::logic::write_tag(self, probe.into_inner(), file_type) + crate::tag_utils::write_tag(self, probe.into_inner(), file_type) } else { Err(LoftyError::UnsupportedTag) } @@ -354,7 +354,7 @@ impl TagType { if file_type.supports_tag_type(self) { let file = probe.into_inner(); - return crate::logic::write_tag(&Tag::new(*self), file, file_type).is_ok(); + return crate::tag_utils::write_tag(&Tag::new(*self), file, file_type).is_ok(); } } }