refactor (#24)
All checks were successful
Rust Build / Check (push) Successful in 37s
Rust Build / Check (pull_request) Successful in 31s
Release Tagging / release (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 41s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 38s
Rust Build / build (push) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 43s
All checks were successful
Rust Build / Check (push) Successful in 37s
Rust Build / Check (pull_request) Successful in 31s
Release Tagging / release (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 41s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 38s
Rust Build / build (push) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 43s
Reviewed-on: #24 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.1.11"
|
version = "0.1.20"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.86"
|
rust-version = "1.86"
|
||||||
|
|
||||||
|
174
src/meta.rs
174
src/meta.rs
@@ -1,20 +1,3 @@
|
|||||||
use lofty::{file::AudioFile, tag::Accessor};
|
|
||||||
|
|
||||||
use crate::types;
|
|
||||||
|
|
||||||
fn get_type(t: types::Type) -> Result<String, std::io::Error> {
|
|
||||||
match t {
|
|
||||||
types::Type::Title => Ok("TITLE".to_owned()),
|
|
||||||
types::Type::Artist => Ok("ARTIST".to_owned()),
|
|
||||||
types::Type::Album => Ok("ALBUM".to_owned()),
|
|
||||||
types::Type::AlbumArtist => Ok("ALBUMARTIST".to_owned()),
|
|
||||||
types::Type::Genre => Ok("GENRE".to_owned()),
|
|
||||||
types::Type::Date => Ok("DATE".to_owned()),
|
|
||||||
types::Type::Track => Ok("TRACKNUMBER".to_owned()),
|
|
||||||
types::Type::Disc => Ok("DISCNUMBER".to_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod coverart {
|
pub mod coverart {
|
||||||
|
|
||||||
use lofty::{file::AudioFile, ogg::OggPictureStorage};
|
use lofty::{file::AudioFile, ogg::OggPictureStorage};
|
||||||
@@ -151,90 +134,100 @@ pub mod coverart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
pub mod metadata {
|
||||||
match std::fs::File::open(filepath) {
|
use crate::types;
|
||||||
Ok(mut content) => {
|
use lofty::file::AudioFile;
|
||||||
match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new())
|
use lofty::tag::Accessor;
|
||||||
{
|
|
||||||
Ok(flac_file) => match flac_file.vorbis_comments() {
|
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
||||||
Some(vb) => {
|
match std::fs::File::open(filepath) {
|
||||||
let type_str: String = get_type(t).unwrap();
|
Ok(mut content) => {
|
||||||
match vb.get(&type_str) {
|
match lofty::flac::FlacFile::read_from(
|
||||||
Some(val) => Ok(val.to_owned()),
|
&mut content,
|
||||||
None => Err(std::io::Error::new(
|
lofty::config::ParseOptions::new(),
|
||||||
std::io::ErrorKind::InvalidData,
|
) {
|
||||||
"Could not get tag data",
|
Ok(flac_file) => match flac_file.vorbis_comments() {
|
||||||
)),
|
Some(vb) => {
|
||||||
|
let type_str: String = types::access::get_type(t).unwrap();
|
||||||
|
match vb.get(&type_str) {
|
||||||
|
Some(val) => Ok(val.to_owned()),
|
||||||
|
None => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
"Could not get tag data",
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
None => Err(std::io::Error::new(
|
||||||
None => Err(std::io::Error::new(
|
std::io::ErrorKind::InvalidData,
|
||||||
|
"No tags found",
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
"No tags found",
|
err.to_string(),
|
||||||
)),
|
)),
|
||||||
},
|
}
|
||||||
Err(err) => Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidData,
|
|
||||||
err.to_string(),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_meta(
|
pub fn set_meta(
|
||||||
t: types::Type,
|
t: types::Type,
|
||||||
filepath: &String,
|
filepath: &String,
|
||||||
value: &String,
|
value: &String,
|
||||||
) -> Result<String, std::io::Error> {
|
) -> Result<String, std::io::Error> {
|
||||||
match std::fs::File::open(filepath) {
|
match std::fs::File::open(filepath) {
|
||||||
Ok(mut content) => {
|
Ok(mut content) => {
|
||||||
match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new())
|
match lofty::flac::FlacFile::read_from(
|
||||||
{
|
&mut content,
|
||||||
Ok(mut flac_file) => match flac_file.vorbis_comments_mut() {
|
lofty::config::ParseOptions::new(),
|
||||||
Some(vb) => {
|
) {
|
||||||
let pre_value = value.clone();
|
Ok(mut flac_file) => match flac_file.vorbis_comments_mut() {
|
||||||
match t {
|
Some(vb) => {
|
||||||
types::Type::Album => {
|
let pre_value = value.clone();
|
||||||
vb.set_album(pre_value);
|
match t {
|
||||||
}
|
types::Type::Album => {
|
||||||
types::Type::AlbumArtist => {
|
vb.set_album(pre_value);
|
||||||
vb.insert(get_type(t).unwrap(), pre_value);
|
}
|
||||||
}
|
types::Type::AlbumArtist => {
|
||||||
types::Type::Artist => {
|
vb.insert(types::access::get_type(t).unwrap(), pre_value);
|
||||||
vb.set_artist(pre_value);
|
}
|
||||||
}
|
types::Type::Artist => {
|
||||||
types::Type::Date => {
|
vb.set_artist(pre_value);
|
||||||
vb.insert(get_type(t).unwrap(), pre_value);
|
}
|
||||||
}
|
types::Type::Date => {
|
||||||
types::Type::Disc => {
|
vb.insert(types::access::get_type(t).unwrap(), pre_value);
|
||||||
vb.set_disk(pre_value.parse().unwrap());
|
}
|
||||||
}
|
types::Type::Disc => {
|
||||||
types::Type::Genre => {
|
vb.set_disk(pre_value.parse().unwrap());
|
||||||
vb.set_genre(pre_value);
|
}
|
||||||
}
|
types::Type::Genre => {
|
||||||
types::Type::Title => {
|
vb.set_genre(pre_value);
|
||||||
vb.set_title(pre_value);
|
}
|
||||||
}
|
types::Type::Title => {
|
||||||
types::Type::Track => {
|
vb.set_title(pre_value);
|
||||||
vb.set_track(pre_value.parse().unwrap());
|
}
|
||||||
}
|
types::Type::Track => {
|
||||||
};
|
vb.set_track(pre_value.parse().unwrap());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Ok(value.to_owned())
|
Ok(value.to_owned())
|
||||||
}
|
}
|
||||||
None => Err(std::io::Error::new(
|
None => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
"No tags found",
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
"No tags found",
|
err.to_string(),
|
||||||
)),
|
)),
|
||||||
},
|
}
|
||||||
Err(err) => Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidData,
|
|
||||||
err.to_string(),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,6 +308,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod get {
|
mod get {
|
||||||
|
use super::metadata::get_meta;
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
||||||
@@ -519,7 +513,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod set {
|
mod set {
|
||||||
|
use super::metadata::{get_meta, set_meta};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::types;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_set_title() {
|
fn test_set_title() {
|
||||||
|
16
src/types.rs
16
src/types.rs
@@ -8,3 +8,19 @@ pub enum Type {
|
|||||||
Track,
|
Track,
|
||||||
Disc,
|
Disc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod access {
|
||||||
|
|
||||||
|
pub fn get_type(t: super::Type) -> Result<String, std::io::Error> {
|
||||||
|
match t {
|
||||||
|
super::Type::Title => Ok("TITLE".to_owned()),
|
||||||
|
super::Type::Artist => Ok("ARTIST".to_owned()),
|
||||||
|
super::Type::Album => Ok("ALBUM".to_owned()),
|
||||||
|
super::Type::AlbumArtist => Ok("ALBUMARTIST".to_owned()),
|
||||||
|
super::Type::Genre => Ok("GENRE".to_owned()),
|
||||||
|
super::Type::Date => Ok("DATE".to_owned()),
|
||||||
|
super::Type::Track => Ok("TRACKNUMBER".to_owned()),
|
||||||
|
super::Type::Disc => Ok("DISCNUMBER".to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user