This commit is contained in:
Serial 2022-01-25 14:42:32 -05:00
parent 15daf36c0d
commit 4eb168a8ea
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
8 changed files with 57 additions and 81 deletions

View file

@ -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::<ApeTagRef>::into(tag).write_to(data),
TagType::Ape => Into::<ape_tag::ApeTagRef>::into(tag).write_to(data),
#[cfg(feature = "id3v1")]
TagType::Id3v1 => Into::<Id3v1TagRef>::into(tag).write_to(data),
TagType::Id3v1 => Into::<v1::tag::Id3v1TagRef>::into(tag).write_to(data),
_ => Err(LoftyError::UnsupportedTag),
}
}

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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),
}
}

View file

@ -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::<RiffInfoListRef>::into(tag).write_to(data),
TagType::RiffInfo => Into::<super::tag::RiffInfoListRef>::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),
}
}

View file

@ -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::<ApeTagRef>::into(tag).write_to(data),
TagType::Ape => Into::<ape_tag::ApeTagRef>::into(tag).write_to(data),
#[cfg(feature = "id3v1")]
TagType::Id3v1 => Into::<Id3v1TagRef>::into(tag).write_to(data),
TagType::Id3v1 => Into::<v1::tag::Id3v1TagRef>::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),
}
}

View file

@ -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::<VorbisCommentsRef>::into(tag))
},
FileType::MP3 => crate::mp3::write::write_to(file, tag),
FileType::FLAC => ogg::flac::write::write_to(file, &mut Into::<VorbisCommentsRef>::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::<IlstRef>::into(tag)),
FileType::MP4 => mp4::ilst::write::write_to(file, &mut Into::<IlstRef>::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),
}
}