From 0a7b327c030734f6579d003701c1f8b75e7b0571 Mon Sep 17 00:00:00 2001
From: Serial <69764315+Serial-ATA@users.noreply.github.com>
Date: Sat, 26 Jun 2021 15:35:39 -0400
Subject: [PATCH] Update tags
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
---
src/components/tags/ape_tag.rs | 8 +-
src/components/tags/id3_tag.rs | 24 ++---
src/components/tags/mp4_tag.rs | 18 ++--
src/components/tags/riff_tag.rs | 12 +--
src/components/tags/vorbis_tag.rs | 160 +++++++++++++++++-------------
5 files changed, 124 insertions(+), 98 deletions(-)
diff --git a/src/components/tags/ape_tag.rs b/src/components/tags/ape_tag.rs
index 5d5c10fc..c85e052d 100644
--- a/src/components/tags/ape_tag.rs
+++ b/src/components/tags/ape_tag.rs
@@ -11,7 +11,7 @@ use crate::types::picture::APE_PICTYPES;
use ape::Item;
use std::borrow::Cow;
use std::fs::File;
-use std::path::Path;
+use std::io::{Read, Seek};
#[impl_tag(ApeInnerTag, TagType::Ape)]
pub struct ApeTag;
@@ -19,12 +19,12 @@ pub struct ApeTag;
impl ApeTag {
#[allow(missing_docs)]
#[allow(clippy::missing_errors_doc)]
- pub fn read_from_path
(path: P) -> Result
+ pub fn read_from(reader: &mut R) -> Result
where
- P: AsRef,
+ R: Read + Seek,
{
Ok(Self {
- inner: ape::read_from_path(&path)?,
+ inner: ape::read_from(reader)?,
#[cfg(feature = "duration")]
duration: None, // TODO
})
diff --git a/src/components/tags/id3_tag.rs b/src/components/tags/id3_tag.rs
index ab256824..de028960 100644
--- a/src/components/tags/id3_tag.rs
+++ b/src/components/tags/id3_tag.rs
@@ -2,20 +2,18 @@
use crate::tag::Id3Format;
use crate::{
- Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Error, MimeType, Picture, Result,
- TagType, ToAny, ToAnyTag,
+ Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, LoftyError, MimeType, Picture,
+ PictureType, Result, TagType, ToAny, ToAnyTag,
};
use lofty_attr::impl_tag;
pub use id3::Tag as Id3v2InnerTag;
-use crate::types::picture::PictureType;
use filepath::FilePath;
use std::borrow::Cow;
use std::convert::{TryFrom, TryInto};
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
-use std::path::Path;
#[impl_tag(Id3v2InnerTag, TagType::Id3v2(Id3Format::Default))]
pub struct Id3v2Tag;
@@ -23,23 +21,23 @@ pub struct Id3v2Tag;
impl Id3v2Tag {
#[allow(missing_docs)]
#[allow(clippy::missing_errors_doc)]
- pub fn read_from_path(path: P, format: &Id3Format) -> Result
+ pub fn read_from(reader: &mut R, format: &Id3Format) -> Result
where
- P: AsRef,
+ R: Read + Seek,
{
match format {
Id3Format::Default => Ok(Self {
- inner: Id3v2InnerTag::read_from_path(&path)?,
+ inner: Id3v2InnerTag::read_from(reader)?,
#[cfg(feature = "duration")]
- duration: Some(mp3_duration::from_path(&path)?),
+ duration: None, // TODO
}),
Id3Format::Riff => Ok(Self {
- inner: Id3v2InnerTag::read_from_wav(&path)?,
+ inner: Id3v2InnerTag::read_from_wav_reader(reader)?,
#[cfg(feature = "duration")]
duration: None,
}),
Id3Format::Form => Ok(Self {
- inner: Id3v2InnerTag::read_from_aiff(&path)?,
+ inner: Id3v2InnerTag::read_from_aiff_reader(reader)?,
#[cfg(feature = "duration")]
duration: None,
}),
@@ -48,7 +46,8 @@ impl Id3v2Tag {
}
impl std::convert::TryFrom for Picture {
- type Error = Error;
+ type Error = LoftyError;
+
fn try_from(inp: id3::frame::Picture) -> Result {
let id3::frame::Picture {
ref mime_type,
@@ -75,7 +74,8 @@ impl std::convert::TryFrom for Picture {
}
impl TryFrom