Compare commits
3 Commits
v0.1.30-de
...
v0.1.30-ma
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a798dea9c | |||
| 5e57b9146c | |||
| 0dc8c153d2 |
28
src/meta.rs
28
src/meta.rs
@@ -135,11 +135,9 @@ pub mod coverart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod metadata {
|
pub mod metadata {
|
||||||
// TODO: Move this at the end after the non-std crates
|
|
||||||
use crate::types;
|
use crate::types;
|
||||||
use lofty::file::AudioFile;
|
use lofty::file::AudioFile;
|
||||||
use lofty::tag::Accessor;
|
use lofty::tag::Accessor;
|
||||||
use lofty::tag::TagExt;
|
|
||||||
|
|
||||||
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
||||||
match std::fs::File::open(filepath) {
|
match std::fs::File::open(filepath) {
|
||||||
@@ -221,14 +219,7 @@ pub mod metadata {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match vb.save_to_path(filepath, lofty::config::WriteOptions::default())
|
Ok(value.to_owned())
|
||||||
{
|
|
||||||
Ok(_) => Ok(value.to_owned()),
|
|
||||||
Err(err) => Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidData,
|
|
||||||
err.to_string(),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => Err(std::io::Error::new(
|
None => Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
@@ -244,23 +235,6 @@ pub mod metadata {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_value(value: types::MetadataType) -> String {
|
|
||||||
match value {
|
|
||||||
types::MetadataType::String(val) => val,
|
|
||||||
types::MetadataType::Int(val) => val.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_meta_value(
|
|
||||||
t: types::Type,
|
|
||||||
filepath: &String,
|
|
||||||
value: types::MetadataType,
|
|
||||||
) -> Result<String, std::io::Error> {
|
|
||||||
let parsed_val = parse_value(value);
|
|
||||||
|
|
||||||
set_meta(t, filepath, &parsed_val)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
22
src/types.rs
22
src/types.rs
@@ -1,4 +1,3 @@
|
|||||||
// TODO: Have this derive Debug
|
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
Title,
|
Title,
|
||||||
Artist,
|
Artist,
|
||||||
@@ -12,27 +11,8 @@ pub enum Type {
|
|||||||
DiscCount,
|
DiscCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum MetadataType {
|
|
||||||
String(String),
|
|
||||||
Int(i32),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MetadataType {
|
|
||||||
pub fn from_std_str(s: &str) -> Self {
|
|
||||||
MetadataType::String(s.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_string(s: String) -> Self {
|
|
||||||
MetadataType::String(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_int(i: i32) -> Self {
|
|
||||||
MetadataType::Int(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod access {
|
pub mod access {
|
||||||
|
|
||||||
pub fn get_type(t: super::Type) -> Result<String, std::io::Error> {
|
pub fn get_type(t: super::Type) -> Result<String, std::io::Error> {
|
||||||
match t {
|
match t {
|
||||||
super::Type::Title => Ok("TITLE".to_owned()),
|
super::Type::Title => Ok("TITLE".to_owned()),
|
||||||
|
|||||||
Reference in New Issue
Block a user