mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 21:52:33 +00:00
Remove unwraps; Stop taking references to Copy
types
This commit is contained in:
parent
55cc5e5264
commit
e01d875e05
26 changed files with 102 additions and 99 deletions
|
@ -24,7 +24,7 @@ fn main() {
|
||||||
let tag_type = tag.tag_type();
|
let tag_type = tag.tag_type();
|
||||||
|
|
||||||
println!("{}: {:?}", num, tag_type);
|
println!("{}: {:?}", num, tag_type);
|
||||||
available_tag_types.push(*tag_type);
|
available_tag_types.push(tag_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut to_remove = None;
|
let mut to_remove = None;
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl AudioFile for ApeFile {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
TagType::Ape => self.ape_tag.is_some(),
|
TagType::Ape => self.ape_tag.is_some(),
|
||||||
|
|
|
@ -137,7 +137,7 @@ pub(crate) fn utf16_decode(reader: &[u8], endianness: fn([u8; 2]) -> u16) -> Res
|
||||||
.chunks_exact(2)
|
.chunks_exact(2)
|
||||||
.map_while(|c| match c {
|
.map_while(|c| match c {
|
||||||
[0, 0] => None,
|
[0, 0] => None,
|
||||||
_ => Some(endianness(c.try_into().unwrap())),
|
_ => Some(endianness(c.try_into().unwrap())), // Infallible
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl AudioFile for AiffFile {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
TagType::Id3v2 => self.id3v2_tag.is_some(),
|
TagType::Id3v2 => self.id3v2_tag.is_some(),
|
||||||
|
|
|
@ -23,7 +23,9 @@ where
|
||||||
return Err(LoftyError::new(ErrorKind::UnknownFormat));
|
return Err(LoftyError::new(ErrorKind::UnknownFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(u32::from_be_bytes(id[4..8].try_into().unwrap()))
|
Ok(u32::from_be_bytes(
|
||||||
|
id[4..8].try_into().unwrap(), // Infallible
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<AiffFile>
|
pub(crate) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<AiffFile>
|
||||||
|
@ -120,30 +122,34 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let properties = if read_properties {
|
let properties;
|
||||||
if comm.is_none() {
|
if read_properties {
|
||||||
return Err(FileDecodingError::new(
|
match comm {
|
||||||
FileType::AIFF,
|
Some(comm) => {
|
||||||
"File does not contain a \"COMM\" chunk",
|
if stream_len == 0 {
|
||||||
)
|
return Err(FileDecodingError::new(
|
||||||
.into());
|
FileType::AIFF,
|
||||||
}
|
"File does not contain a \"SSND\" chunk",
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
if stream_len == 0 {
|
properties = super::properties::read_properties(
|
||||||
return Err(FileDecodingError::new(
|
&mut &*comm,
|
||||||
FileType::AIFF,
|
stream_len,
|
||||||
"File does not contain a \"SSND\" chunk",
|
data.seek(SeekFrom::Current(0))?,
|
||||||
)
|
)?;
|
||||||
.into());
|
},
|
||||||
|
None => {
|
||||||
|
return Err(FileDecodingError::new(
|
||||||
|
FileType::AIFF,
|
||||||
|
"File does not contain a \"COMM\" chunk",
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
super::properties::read_properties(
|
|
||||||
&mut &*comm.unwrap(),
|
|
||||||
stream_len,
|
|
||||||
data.seek(SeekFrom::Current(0))?,
|
|
||||||
)?
|
|
||||||
} else {
|
} else {
|
||||||
FileProperties::default()
|
properties = FileProperties::default();
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(AiffFile {
|
Ok(AiffFile {
|
||||||
|
|
|
@ -383,7 +383,7 @@ where
|
||||||
chunks_remove.sort_unstable();
|
chunks_remove.sort_unstable();
|
||||||
chunks_remove.reverse();
|
chunks_remove.reverse();
|
||||||
|
|
||||||
let first = chunks_remove.pop().unwrap();
|
let first = chunks_remove.pop().unwrap(); // Infallible
|
||||||
|
|
||||||
for (s, e) in &chunks_remove {
|
for (s, e) in &chunks_remove {
|
||||||
file_bytes.drain(*s as usize..*e as usize);
|
file_bytes.drain(*s as usize..*e as usize);
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl AudioFile for WavFile {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
TagType::Id3v2 => self.id3v2_tag.is_some(),
|
TagType::Id3v2 => self.id3v2_tag.is_some(),
|
||||||
|
|
|
@ -31,7 +31,9 @@ where
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(u32::from_le_bytes(id[4..8].try_into().unwrap()))
|
Ok(u32::from_le_bytes(
|
||||||
|
id[4..8].try_into().unwrap(), // Infallible
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<WavFile>
|
pub(crate) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<WavFile>
|
||||||
|
|
|
@ -76,11 +76,11 @@
|
||||||
//! let tagged_file = read_from_path("tests/files/assets/minimal/full_test.mp3", false)?;
|
//! let tagged_file = read_from_path("tests/files/assets/minimal/full_test.mp3", false)?;
|
||||||
//!
|
//!
|
||||||
//! // Get the primary tag (ID3v2 in this case)
|
//! // Get the primary tag (ID3v2 in this case)
|
||||||
//! let id3v2 = tagged_file.primary_tag().unwrap();
|
//! let id3v2 = tagged_file.primary_tag();
|
||||||
//!
|
//!
|
||||||
//! // If the primary tag doesn't exist, or the tag types
|
//! // If the primary tag doesn't exist, or the tag types
|
||||||
//! // don't matter, the first tag can be retrieved
|
//! // don't matter, the first tag can be retrieved
|
||||||
//! let unknown_first_tag = tagged_file.first_tag().unwrap();
|
//! let unknown_first_tag = tagged_file.first_tag();
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
@ -102,8 +102,8 @@
|
||||||
//! assert_eq!(mpeg_file.properties().channels(), 2);
|
//! assert_eq!(mpeg_file.properties().channels(), 2);
|
||||||
//!
|
//!
|
||||||
//! // Here we have a file with multiple tags
|
//! // Here we have a file with multiple tags
|
||||||
//! assert!(mpeg_file.contains_tag_type(&TagType::Id3v2));
|
//! assert!(mpeg_file.contains_tag_type(TagType::Id3v2));
|
||||||
//! assert!(mpeg_file.contains_tag_type(&TagType::Ape));
|
//! assert!(mpeg_file.contains_tag_type(TagType::Ape));
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl AudioFile for Mp3File {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
TagType::Ape => self.ape_tag.is_some(),
|
TagType::Ape => self.ape_tag.is_some(),
|
||||||
|
|
|
@ -83,7 +83,7 @@ where
|
||||||
},
|
},
|
||||||
// Tags might be followed by junk bytes before the first MP3 frame begins
|
// Tags might be followed by junk bytes before the first MP3 frame begins
|
||||||
_ => {
|
_ => {
|
||||||
// seek back the length of the temporary header buffer, to include them
|
// Seek back the length of the temporary header buffer, to include them
|
||||||
// in the frame sync search
|
// in the frame sync search
|
||||||
#[allow(clippy::neg_multiply)]
|
#[allow(clippy::neg_multiply)]
|
||||||
let start_of_search_area = reader.seek(SeekFrom::Current(-1 * header.len() as i64))?;
|
let start_of_search_area = reader.seek(SeekFrom::Current(-1 * header.len() as i64))?;
|
||||||
|
@ -102,7 +102,8 @@ where
|
||||||
// We have found the first frame
|
// We have found the first frame
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// the search for sync bits was unsuccessful
|
|
||||||
|
// The search for sync bits was unsuccessful
|
||||||
return Err(FileDecodingError::new(
|
return Err(FileDecodingError::new(
|
||||||
FileType::MP3,
|
FileType::MP3,
|
||||||
"File contains an invalid frame",
|
"File contains an invalid frame",
|
||||||
|
|
|
@ -89,9 +89,9 @@ impl AudioFile for Mp4File {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unreachable_code, unused_variables)]
|
#[allow(unreachable_code, unused_variables)]
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
#[cfg(feature = "mp4_ilst")]
|
#[cfg(feature = "mp4_ilst")]
|
||||||
return tag_type == &TagType::Mp4Ilst && self.ilst.is_some();
|
return tag_type == TagType::Mp4Ilst && self.ilst.is_some();
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,22 +23,22 @@ impl Moov {
|
||||||
where
|
where
|
||||||
R: Read + Seek,
|
R: Read + Seek,
|
||||||
{
|
{
|
||||||
let mut moov = (false, None);
|
let mut moov = None;
|
||||||
|
|
||||||
while let Ok(atom) = AtomInfo::read(data) {
|
while let Ok(atom) = AtomInfo::read(data) {
|
||||||
if atom.ident == AtomIdent::Fourcc(*b"moov") {
|
if atom.ident == AtomIdent::Fourcc(*b"moov") {
|
||||||
moov = (true, Some(atom));
|
moov = Some(atom);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_unneeded(data, atom.extended, atom.len)?;
|
skip_unneeded(data, atom.extended, atom.len)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !moov.0 {
|
if let Some(moov) = moov {
|
||||||
return Err(FileDecodingError::new(FileType::MP4, "No \"moov\" atom found").into());
|
Ok(moov)
|
||||||
|
} else {
|
||||||
|
Err(FileDecodingError::new(FileType::MP4, "No \"moov\" atom found").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(moov.1.unwrap())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse<R>(data: &mut R, read_properties: bool) -> Result<Self>
|
pub(crate) fn parse<R>(data: &mut R, read_properties: bool) -> Result<Self>
|
||||||
|
|
|
@ -62,9 +62,9 @@ impl AudioFile for FlacFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
#[cfg(feature = "vorbis_comments")]
|
#[cfg(feature = "vorbis_comments")]
|
||||||
return tag_type == &TagType::VorbisComments && self.vorbis_comments.is_some();
|
return tag_type == TagType::VorbisComments && self.vorbis_comments.is_some();
|
||||||
|
|
||||||
#[cfg(not(feature = "vorbis_comments"))]
|
#[cfg(not(feature = "vorbis_comments"))]
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -96,7 +96,7 @@ where
|
||||||
blocks_remove.sort_unstable();
|
blocks_remove.sort_unstable();
|
||||||
blocks_remove.reverse();
|
blocks_remove.reverse();
|
||||||
|
|
||||||
let first = blocks_remove.pop().unwrap();
|
let first = blocks_remove.pop().unwrap(); // Infallible
|
||||||
|
|
||||||
for (s, e) in &blocks_remove {
|
for (s, e) in &blocks_remove {
|
||||||
file_bytes.drain(*s as usize..*e as usize);
|
file_bytes.drain(*s as usize..*e as usize);
|
||||||
|
|
|
@ -61,8 +61,8 @@ impl AudioFile for OpusFile {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
tag_type == &TagType::VorbisComments
|
tag_type == TagType::VorbisComments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ impl AudioFile for SpeexFile {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
tag_type == &TagType::VorbisComments
|
tag_type == TagType::VorbisComments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ impl AudioFile for VorbisFile {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool {
|
fn contains_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
tag_type == &TagType::VorbisComments
|
tag_type == TagType::VorbisComments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub trait AudioFile: Into<TaggedFile> {
|
||||||
/// Checks if the file contains any tags
|
/// Checks if the file contains any tags
|
||||||
fn contains_tag(&self) -> bool;
|
fn contains_tag(&self) -> bool;
|
||||||
/// Checks if the file contains the given [`TagType`]
|
/// Checks if the file contains the given [`TagType`]
|
||||||
fn contains_tag_type(&self, tag_type: &TagType) -> bool;
|
fn contains_tag_type(&self, tag_type: TagType) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic representation of a file
|
/// A generic representation of a file
|
||||||
|
@ -47,8 +47,8 @@ pub struct TaggedFile {
|
||||||
|
|
||||||
impl TaggedFile {
|
impl TaggedFile {
|
||||||
/// Returns the file's [`FileType`]
|
/// Returns the file's [`FileType`]
|
||||||
pub fn file_type(&self) -> &FileType {
|
pub fn file_type(&self) -> FileType {
|
||||||
&self.ty
|
self.ty
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file's [`FileProperties`]
|
/// Returns the file's [`FileProperties`]
|
||||||
|
@ -70,17 +70,17 @@ impl TaggedFile {
|
||||||
|
|
||||||
/// Determines whether the file supports the given [`TagType`]
|
/// Determines whether the file supports the given [`TagType`]
|
||||||
pub fn supports_tag_type(&self, tag_type: TagType) -> bool {
|
pub fn supports_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
self.ty.supports_tag_type(&tag_type)
|
self.ty.supports_tag_type(tag_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to a specific [`TagType`]
|
/// Get a reference to a specific [`TagType`]
|
||||||
pub fn tag(&self, tag_type: &TagType) -> Option<&Tag> {
|
pub fn tag(&self, tag_type: &TagType) -> Option<&Tag> {
|
||||||
self.tags.iter().find(|i| i.tag_type() == tag_type)
|
self.tags.iter().find(|i| i.tag_type() == *tag_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to a specific [`TagType`]
|
/// Get a mutable reference to a specific [`TagType`]
|
||||||
pub fn tag_mut(&mut self, tag_type: &TagType) -> Option<&mut Tag> {
|
pub fn tag_mut(&mut self, tag_type: &TagType) -> Option<&mut Tag> {
|
||||||
self.tags.iter_mut().find(|i| i.tag_type() == tag_type)
|
self.tags.iter_mut().find(|i| i.tag_type() == *tag_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primary tag
|
/// Returns the primary tag
|
||||||
|
@ -114,7 +114,7 @@ impl TaggedFile {
|
||||||
///
|
///
|
||||||
/// If a tag is replaced, it will be returned
|
/// If a tag is replaced, it will be returned
|
||||||
pub fn insert_tag(&mut self, tag: Tag) -> Option<Tag> {
|
pub fn insert_tag(&mut self, tag: Tag) -> Option<Tag> {
|
||||||
let tag_type = *tag.tag_type();
|
let tag_type = tag.tag_type();
|
||||||
|
|
||||||
if self.supports_tag_type(tag_type) {
|
if self.supports_tag_type(tag_type) {
|
||||||
let ret = self.remove_tag(tag_type);
|
let ret = self.remove_tag(tag_type);
|
||||||
|
@ -132,7 +132,7 @@ impl TaggedFile {
|
||||||
pub fn remove_tag(&mut self, tag_type: TagType) -> Option<Tag> {
|
pub fn remove_tag(&mut self, tag_type: TagType) -> Option<Tag> {
|
||||||
self.tags
|
self.tags
|
||||||
.iter()
|
.iter()
|
||||||
.position(|t| t.tag_type() == &tag_type)
|
.position(|t| t.tag_type() == tag_type)
|
||||||
.map(|pos| self.tags.remove(pos))
|
.map(|pos| self.tags.remove(pos))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,28 +225,28 @@ impl FileType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns if the target `FileType` supports a [`TagType`]
|
/// Returns if the target `FileType` supports a [`TagType`]
|
||||||
pub fn supports_tag_type(&self, tag_type: &TagType) -> bool {
|
pub fn supports_tag_type(&self, tag_type: TagType) -> bool {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
FileType::AIFF | FileType::APE | FileType::MP3 | FileType::WAV
|
FileType::AIFF | FileType::APE | FileType::MP3 | FileType::WAV
|
||||||
if tag_type == &TagType::Id3v2 =>
|
if tag_type == TagType::Id3v2 =>
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
#[cfg(feature = "aiff_text_chunks")]
|
#[cfg(feature = "aiff_text_chunks")]
|
||||||
FileType::AIFF if tag_type == &TagType::AiffText => true,
|
FileType::AIFF if tag_type == TagType::AiffText => true,
|
||||||
#[cfg(feature = "id3v1")]
|
#[cfg(feature = "id3v1")]
|
||||||
FileType::APE | FileType::MP3 if tag_type == &TagType::Id3v1 => true,
|
FileType::APE | FileType::MP3 if tag_type == TagType::Id3v1 => true,
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
FileType::APE | FileType::MP3 if tag_type == &TagType::Ape => true,
|
FileType::APE | FileType::MP3 if tag_type == TagType::Ape => true,
|
||||||
#[cfg(feature = "vorbis_comments")]
|
#[cfg(feature = "vorbis_comments")]
|
||||||
FileType::Opus | FileType::FLAC | FileType::Vorbis | FileType::Speex => {
|
FileType::Opus | FileType::FLAC | FileType::Vorbis | FileType::Speex => {
|
||||||
tag_type == &TagType::VorbisComments
|
tag_type == TagType::VorbisComments
|
||||||
},
|
},
|
||||||
#[cfg(feature = "mp4_ilst")]
|
#[cfg(feature = "mp4_ilst")]
|
||||||
FileType::MP4 => tag_type == &TagType::Mp4Ilst,
|
FileType::MP4 => tag_type == TagType::Mp4Ilst,
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
FileType::WAV => tag_type == &TagType::RiffInfo,
|
FileType::WAV => tag_type == TagType::RiffInfo,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ impl Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`TagType`]
|
/// Returns the [`TagType`]
|
||||||
pub fn tag_type(&self) -> &TagType {
|
pub fn tag_type(&self) -> TagType {
|
||||||
&self.tag_type
|
self.tag_type
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of [`TagItem`]s
|
/// Returns the number of [`TagItem`]s
|
||||||
|
@ -440,7 +440,7 @@ impl TagType {
|
||||||
None => return Err(LoftyError::new(ErrorKind::UnknownFormat)),
|
None => return Err(LoftyError::new(ErrorKind::UnknownFormat)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !file_type.supports_tag_type(self) {
|
if !file_type.supports_tag_type(*self) {
|
||||||
return Err(LoftyError::new(ErrorKind::UnsupportedTag));
|
return Err(LoftyError::new(ErrorKind::UnsupportedTag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn read() {
|
||||||
// Here we have an AIFF file with both an ID3v2 chunk and text chunks
|
// Here we have an AIFF file with both an ID3v2 chunk and text chunks
|
||||||
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.aiff", false).unwrap();
|
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.aiff", false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), &FileType::AIFF);
|
assert_eq!(file.file_type(), FileType::AIFF);
|
||||||
|
|
||||||
// Verify the ID3v2 tag first
|
// Verify the ID3v2 tag first
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||||
|
@ -22,7 +22,7 @@ fn write() {
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(tagged_file.file_type(), &FileType::AIFF);
|
assert_eq!(tagged_file.file_type(), FileType::AIFF);
|
||||||
|
|
||||||
// ID3v2
|
// ID3v2
|
||||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn read() {
|
||||||
// Here we have an APE file with an ID3v2, ID3v1, and an APEv2 tag
|
// Here we have an APE file with an ID3v2, ID3v1, and an APEv2 tag
|
||||||
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.ape", false).unwrap();
|
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.ape", false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), &FileType::APE);
|
assert_eq!(file.file_type(), FileType::APE);
|
||||||
|
|
||||||
// Verify the APEv2 tag first
|
// Verify the APEv2 tag first
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||||
|
@ -26,7 +26,7 @@ fn write() {
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(tagged_file.file_type(), &FileType::APE);
|
assert_eq!(tagged_file.file_type(), FileType::APE);
|
||||||
|
|
||||||
// APEv2
|
// APEv2
|
||||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||||
|
|
|
@ -8,7 +8,7 @@ fn read() {
|
||||||
let file =
|
let file =
|
||||||
lofty::read_from_path("tests/files/assets/minimal/m4a_codec_aac.m4a", false).unwrap();
|
lofty::read_from_path("tests/files/assets/minimal/m4a_codec_aac.m4a", false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), &FileType::MP4);
|
assert_eq!(file.file_type(), FileType::MP4);
|
||||||
|
|
||||||
// Verify the ilst tag
|
// Verify the ilst tag
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||||
|
@ -20,7 +20,7 @@ fn write() {
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(tagged_file.file_type(), &FileType::MP4);
|
assert_eq!(tagged_file.file_type(), FileType::MP4);
|
||||||
|
|
||||||
// ilst
|
// ilst
|
||||||
crate::set_artist!(tagged_file, tag_mut, TagType::Mp4Ilst, "Foo artist", 1 => file, "Bar artist");
|
crate::set_artist!(tagged_file, tag_mut, TagType::Mp4Ilst, "Foo artist", 1 => file, "Bar artist");
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn read() {
|
||||||
// Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag
|
// Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag
|
||||||
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.mp3", false).unwrap();
|
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.mp3", false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), &FileType::MP3);
|
assert_eq!(file.file_type(), FileType::MP3);
|
||||||
|
|
||||||
// Verify the ID3v2 tag first
|
// Verify the ID3v2 tag first
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||||
|
@ -26,7 +26,7 @@ fn read_with_junk_bytes_between_frames() {
|
||||||
lofty::read_from_path("tests/files/assets/junk_between_id3_and_mp3.mp3", true).unwrap();
|
lofty::read_from_path("tests/files/assets/junk_between_id3_and_mp3.mp3", true).unwrap();
|
||||||
|
|
||||||
// note that the file contains ID3v2 and ID3v1 data
|
// note that the file contains ID3v2 and ID3v1 data
|
||||||
assert_eq!(file.file_type(), &FileType::MP3);
|
assert_eq!(file.file_type(), FileType::MP3);
|
||||||
|
|
||||||
let id3v2_tag = &file.tags()[0];
|
let id3v2_tag = &file.tags()[0];
|
||||||
assert_eq!(id3v2_tag.artist(), Some("artist test"));
|
assert_eq!(id3v2_tag.artist(), Some("artist test"));
|
||||||
|
@ -49,7 +49,7 @@ fn write() {
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(tagged_file.file_type(), &FileType::MP3);
|
assert_eq!(tagged_file.file_type(), FileType::MP3);
|
||||||
|
|
||||||
// ID3v2
|
// ID3v2
|
||||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||||
|
|
|
@ -7,12 +7,12 @@ use std::io::{Seek, SeekFrom, Write};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn opus_read() {
|
fn opus_read() {
|
||||||
read("tests/files/assets/minimal/full_test.opus", &FileType::Opus)
|
read("tests/files/assets/minimal/full_test.opus", FileType::Opus)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn opus_write() {
|
fn opus_write() {
|
||||||
write("tests/files/assets/minimal/full_test.opus", &FileType::Opus)
|
write("tests/files/assets/minimal/full_test.opus", FileType::Opus)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -26,12 +26,12 @@ fn opus_remove() {
|
||||||
#[test]
|
#[test]
|
||||||
fn flac_read() {
|
fn flac_read() {
|
||||||
// FLAC does **not** require a Vorbis comment block be present, this file has one
|
// FLAC does **not** require a Vorbis comment block be present, this file has one
|
||||||
read("tests/files/assets/minimal/full_test.flac", &FileType::FLAC)
|
read("tests/files/assets/minimal/full_test.flac", FileType::FLAC)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flac_write() {
|
fn flac_write() {
|
||||||
write("tests/files/assets/minimal/full_test.flac", &FileType::FLAC)
|
write("tests/files/assets/minimal/full_test.flac", FileType::FLAC)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -44,18 +44,12 @@ fn flac_remove() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vorbis_read() {
|
fn vorbis_read() {
|
||||||
read(
|
read("tests/files/assets/minimal/full_test.ogg", FileType::Vorbis)
|
||||||
"tests/files/assets/minimal/full_test.ogg",
|
|
||||||
&FileType::Vorbis,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vorbis_write() {
|
fn vorbis_write() {
|
||||||
write(
|
write("tests/files/assets/minimal/full_test.ogg", FileType::Vorbis)
|
||||||
"tests/files/assets/minimal/full_test.ogg",
|
|
||||||
&FileType::Vorbis,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -68,12 +62,12 @@ fn vorbis_remove() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn speex_read() {
|
fn speex_read() {
|
||||||
read("tests/files/assets/minimal/full_test.spx", &FileType::Speex)
|
read("tests/files/assets/minimal/full_test.spx", FileType::Speex)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn speex_write() {
|
fn speex_write() {
|
||||||
write("tests/files/assets/minimal/full_test.spx", &FileType::Speex)
|
write("tests/files/assets/minimal/full_test.spx", FileType::Speex)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -84,7 +78,7 @@ fn speex_remove() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(path: &str, file_type: &FileType) {
|
fn read(path: &str, file_type: FileType) {
|
||||||
let file = lofty::read_from_path(path, false).unwrap();
|
let file = lofty::read_from_path(path, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), file_type);
|
assert_eq!(file.file_type(), file_type);
|
||||||
|
@ -92,7 +86,7 @@ fn read(path: &str, file_type: &FileType) {
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 2);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(path: &str, file_type: &FileType) {
|
fn write(path: &str, file_type: FileType) {
|
||||||
let mut file = temp_file!(path);
|
let mut file = temp_file!(path);
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
|
@ -8,7 +8,7 @@ fn read() {
|
||||||
let file =
|
let file =
|
||||||
lofty::read_from_path("tests/files/assets/minimal/wav_format_pcm.wav", false).unwrap();
|
lofty::read_from_path("tests/files/assets/minimal/wav_format_pcm.wav", false).unwrap();
|
||||||
|
|
||||||
assert_eq!(file.file_type(), &FileType::WAV);
|
assert_eq!(file.file_type(), FileType::WAV);
|
||||||
|
|
||||||
// Verify the ID3v2 tag first
|
// Verify the ID3v2 tag first
|
||||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||||
|
@ -23,7 +23,7 @@ fn write() {
|
||||||
|
|
||||||
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
|
||||||
|
|
||||||
assert_eq!(tagged_file.file_type(), &FileType::WAV);
|
assert_eq!(tagged_file.file_type(), FileType::WAV);
|
||||||
|
|
||||||
// ID3v2
|
// ID3v2
|
||||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||||
|
|
Loading…
Reference in a new issue