Compare commits

...

2 Commits

Author SHA1 Message Date
8f55b28fbe Added function to set value for metadata for known types (#29)
All checks were successful
Release Tagging / release (push) Successful in 28s
Rust Build / Check (push) Successful in 28s
Rust Build / Check (pull_request) Successful in 25s
Rust Build / Test Suite (push) Successful in 27s
Rust Build / Rustfmt (push) Successful in 23s
Rust Build / Clippy (push) Successful in 27s
Rust Build / build (push) Successful in 32s
Rust Build / Test Suite (pull_request) Successful in 28s
Rust Build / Rustfmt (pull_request) Successful in 23s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 31s
Reviewed-on: #29
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-21 20:40:15 +00:00
859003fc65 Set meta bug fix (#27)
All checks were successful
Release Tagging / release (push) Successful in 28s
Rust Build / Check (push) Successful in 27s
Rust Build / Test Suite (push) Successful in 27s
Rust Build / Rustfmt (push) Successful in 24s
Rust Build / Clippy (push) Successful in 27s
Rust Build / build (push) Successful in 34s
Rust Build / Check (pull_request) Successful in 25s
Rust Build / Test Suite (pull_request) Successful in 25s
Rust Build / Rustfmt (pull_request) Successful in 22s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 30s
Reviewed-on: #27
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-21 01:01:53 +00:00
2 changed files with 48 additions and 2 deletions

View File

@@ -135,9 +135,11 @@ pub mod coverart {
}
pub mod metadata {
// TODO: Move this at the end after the non-std crates
use crate::types;
use lofty::file::AudioFile;
use lofty::tag::Accessor;
use lofty::tag::TagExt;
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
match std::fs::File::open(filepath) {
@@ -219,7 +221,14 @@ pub mod metadata {
}
};
Ok(value.to_owned())
match vb.save_to_path(filepath, lofty::config::WriteOptions::default())
{
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(
std::io::ErrorKind::InvalidData,
@@ -235,6 +244,23 @@ pub mod metadata {
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)]

View File

@@ -1,3 +1,4 @@
// TODO: Have this derive Debug
pub enum Type {
Title,
Artist,
@@ -11,8 +12,27 @@ pub enum Type {
DiscCount,
}
pub mod access {
#[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 fn get_type(t: super::Type) -> Result<String, std::io::Error> {
match t {
super::Type::Title => Ok("TITLE".to_owned()),