mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 06:32:33 +00:00
Switch from Into to From
This commit is contained in:
parent
92cb9d51ba
commit
706a61383d
8 changed files with 111 additions and 104 deletions
|
@ -22,19 +22,6 @@ pub struct ApeFile {
|
|||
pub(crate) properties: FileProperties,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for ApeFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::APE,
|
||||
properties: self.properties,
|
||||
tags: vec![self.id3v1, self.id3v2, self.ape]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioFile for ApeFile {
|
||||
fn read_from<R>(reader: &mut R) -> Result<Self>
|
||||
where
|
||||
|
|
|
@ -11,24 +11,11 @@ use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
|
|||
/// An AIFF file
|
||||
pub struct AiffFile {
|
||||
/// The file's audio properties
|
||||
properties: FileProperties,
|
||||
pub(crate) properties: FileProperties,
|
||||
/// Any text chunks included in the file
|
||||
text_chunks: Option<Tag>,
|
||||
pub(crate) text_chunks: Option<Tag>,
|
||||
/// An ID3v2 tag
|
||||
id3v2: Option<Tag>,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for AiffFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::AIFF,
|
||||
properties: self.properties,
|
||||
tags: vec![self.text_chunks, self.id3v2]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
pub(crate) id3v2: Option<Tag>,
|
||||
}
|
||||
|
||||
impl AudioFile for AiffFile {
|
||||
|
|
|
@ -19,24 +19,11 @@ const EXTENSIBLE: u16 = 0xfffe;
|
|||
/// A WAV file
|
||||
pub struct WavFile {
|
||||
/// The file's audio properties
|
||||
properties: FileProperties,
|
||||
pub(crate) properties: FileProperties,
|
||||
/// A RIFF INFO LIST
|
||||
riff_info: Option<Tag>,
|
||||
pub(crate) riff_info: Option<Tag>,
|
||||
/// An ID3v2 tag
|
||||
id3v2: Option<Tag>,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for WavFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::WAV,
|
||||
properties: self.properties,
|
||||
tags: vec![self.riff_info, self.id3v2]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
pub(crate) id3v2: Option<Tag>,
|
||||
}
|
||||
|
||||
impl AudioFile for WavFile {
|
||||
|
|
|
@ -11,26 +11,13 @@ use std::io::{Read, Seek};
|
|||
/// An MPEG file
|
||||
pub struct MpegFile {
|
||||
/// An ID3v2 tag
|
||||
id3v2: Option<Tag>,
|
||||
pub(crate) id3v2: Option<Tag>,
|
||||
/// An ID3v1 tag
|
||||
id3v1: Option<Tag>,
|
||||
pub(crate) id3v1: Option<Tag>,
|
||||
/// An APEv1/v2 tag
|
||||
ape: Option<Tag>,
|
||||
pub(crate) ape: Option<Tag>,
|
||||
/// The file's audio properties
|
||||
properties: FileProperties,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for MpegFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::MP3,
|
||||
properties: self.properties,
|
||||
tags: vec![self.id3v1, self.id3v2, self.ape]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
pub(crate) properties: FileProperties,
|
||||
}
|
||||
|
||||
impl AudioFile for MpegFile {
|
||||
|
|
|
@ -18,25 +18,11 @@ use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
|
|||
/// A FLAC file
|
||||
pub struct FlacFile {
|
||||
/// The file's audio properties
|
||||
properties: FileProperties,
|
||||
pub(crate) properties: FileProperties,
|
||||
/// The vorbis comments contained in the file
|
||||
///
|
||||
/// NOTE: This field being `Some` does not mean the file has vorbis comments, as Picture blocks exist.
|
||||
metadata: Option<Tag>,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for FlacFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::FLAC,
|
||||
properties: self.properties,
|
||||
tags: if let Some(metadata) = self.metadata {
|
||||
vec![metadata]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
}
|
||||
}
|
||||
pub(crate) metadata: Option<Tag>,
|
||||
}
|
||||
|
||||
impl AudioFile for FlacFile {
|
||||
|
|
|
@ -16,23 +16,13 @@ use ogg_pager::Page;
|
|||
/// An OGG Opus file
|
||||
pub struct OpusFile {
|
||||
/// The file's audio properties
|
||||
properties: FileProperties,
|
||||
pub(crate) properties: FileProperties,
|
||||
/// The file vendor's name
|
||||
vendor: String,
|
||||
pub(crate) vendor: String,
|
||||
/// The vorbis comments contained in the file
|
||||
///
|
||||
/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
|
||||
vorbis_comments: Tag,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for OpusFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::Opus,
|
||||
properties: self.properties,
|
||||
tags: vec![self.vorbis_comments],
|
||||
}
|
||||
}
|
||||
pub(crate) vorbis_comments: Tag,
|
||||
}
|
||||
|
||||
impl AudioFile for OpusFile {
|
||||
|
|
|
@ -16,23 +16,13 @@ use ogg_pager::Page;
|
|||
/// An OGG Vorbis file
|
||||
pub struct VorbisFile {
|
||||
/// The file's audio properties
|
||||
pub properties: FileProperties,
|
||||
pub(crate) properties: FileProperties,
|
||||
/// The file vendor's name
|
||||
pub vendor: String,
|
||||
pub(crate) vendor: String,
|
||||
/// The vorbis comments contained in the file
|
||||
///
|
||||
/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
|
||||
pub vorbis_comments: Tag,
|
||||
}
|
||||
|
||||
impl Into<TaggedFile> for VorbisFile {
|
||||
fn into(self) -> TaggedFile {
|
||||
TaggedFile {
|
||||
ty: FileType::Vorbis,
|
||||
properties: self.properties,
|
||||
tags: vec![self.vorbis_comments],
|
||||
}
|
||||
}
|
||||
pub(crate) vorbis_comments: Tag,
|
||||
}
|
||||
|
||||
impl AudioFile for VorbisFile {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
use crate::logic::id3::v2::Id3v2Version;
|
||||
use crate::{FileProperties, LoftyError, Result, Tag, TagType};
|
||||
|
||||
use crate::logic::ape::ApeFile;
|
||||
use crate::logic::iff::aiff::AiffFile;
|
||||
use crate::logic::iff::wav::WavFile;
|
||||
use crate::logic::mpeg::MpegFile;
|
||||
use crate::logic::ogg::flac::FlacFile;
|
||||
use crate::logic::ogg::opus::OpusFile;
|
||||
use crate::logic::ogg::vorbis::VorbisFile;
|
||||
use byteorder::ReadBytesExt;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Seek, SeekFrom};
|
||||
|
@ -100,6 +107,92 @@ impl TaggedFile {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<AiffFile> for TaggedFile {
|
||||
fn from(input: AiffFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::AIFF,
|
||||
properties: input.properties,
|
||||
tags: vec![input.text_chunks, input.id3v2]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpusFile> for TaggedFile {
|
||||
fn from(input: OpusFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::Opus,
|
||||
properties: input.properties,
|
||||
tags: vec![input.vorbis_comments],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VorbisFile> for TaggedFile {
|
||||
fn from(input: VorbisFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::Vorbis,
|
||||
properties: input.properties,
|
||||
tags: vec![input.vorbis_comments],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FlacFile> for TaggedFile {
|
||||
fn from(input: FlacFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::FLAC,
|
||||
properties: input.properties,
|
||||
tags: if let Some(metadata) = input.metadata {
|
||||
vec![metadata]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WavFile> for TaggedFile {
|
||||
fn from(input: WavFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::WAV,
|
||||
properties: input.properties,
|
||||
tags: vec![input.riff_info, input.id3v2]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MpegFile> for TaggedFile {
|
||||
fn from(input: MpegFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::MP3,
|
||||
properties: input.properties,
|
||||
tags: vec![input.id3v1, input.id3v2, input.ape]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApeFile> for TaggedFile {
|
||||
fn from(input: ApeFile) -> Self {
|
||||
Self {
|
||||
ty: FileType::APE,
|
||||
properties: input.properties,
|
||||
tags: vec![input.id3v1, input.id3v2, input.ape]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
#[allow(missing_docs)]
|
||||
/// The type of file read
|
||||
|
|
Loading…
Reference in a new issue