Compare commits
14 Commits
v0.1.0-dev
...
v0.1.30-de
Author | SHA1 | Date | |
---|---|---|---|
859003fc65 | |||
000639b0f8 | |||
2932cdbe1c | |||
f534687292 | |||
c80bc7d7e1 | |||
805dfb269b | |||
43774fe580 | |||
e0e9eab98c | |||
7c1881d102 | |||
a69212adb0 | |||
b7df0a1994 | |||
79a7012a3a | |||
ed0ac3c156 | |||
4a84fa15da |
@@ -1,9 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.1.0"
|
version = "0.1.30"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.86"
|
rust-version = "1.86"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
metadata = { version = "0.1.10" }
|
lofty = { version = "0.22.3" }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = { version = "3.19.1" }
|
121
src/lib.rs
121
src/lib.rs
@@ -1,119 +1,2 @@
|
|||||||
pub mod meta_type {
|
pub mod meta;
|
||||||
pub enum Type {
|
pub mod types;
|
||||||
Title,
|
|
||||||
Artist,
|
|
||||||
Album,
|
|
||||||
Genre,
|
|
||||||
Year,
|
|
||||||
Track,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod meta_nouveaou {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub fn get_meta(t: meta_type::Type, filepath: &String) -> Result<String, std::io::Error> {
|
|
||||||
match t {
|
|
||||||
meta_type::Type::Title => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
meta_type::Type::Artist => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
meta_type::Type::Album => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
meta_type::Type::Genre => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
meta_type::Type::Year => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
meta_type::Type::Track => match new_meta(filepath) {
|
|
||||||
Ok(metaa) => match get_val(t, metaa.tags) {
|
|
||||||
Ok(val) => Ok(val),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_type(t: meta_type::Type) -> Result<String, std::io::Error> {
|
|
||||||
match t {
|
|
||||||
meta_type::Type::Title => Ok("TITLE".to_string()),
|
|
||||||
meta_type::Type::Artist => Ok("ARTIST".to_string()),
|
|
||||||
meta_type::Type::Album => Ok("".to_string()),
|
|
||||||
meta_type::Type::Genre => Ok("".to_string()),
|
|
||||||
meta_type::Type::Year => Ok("".to_string()),
|
|
||||||
meta_type::Type::Track => Ok("".to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_val(t: meta_type::Type, tags: Vec<(String, String)>) -> Result<String, std::io::Error> {
|
|
||||||
let type_ma: String = get_type(t).unwrap();
|
|
||||||
for tag in tags {
|
|
||||||
if tag.0 == type_ma {
|
|
||||||
return Ok(tag.1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidInput,
|
|
||||||
"Invalid",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_meta(filepath: &String) -> Result<metadata::MediaFileMetadata, std::io::Error> {
|
|
||||||
let path = std::path::Path::new(&filepath);
|
|
||||||
metadata::MediaFileMetadata::new(&path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_title() {
|
|
||||||
let filename = String::from("track01.flac");
|
|
||||||
let dir = String::from("tests/sample_tracks3");
|
|
||||||
let dir_path = std::path::Path::new(&dir);
|
|
||||||
let full_path = dir_path.join(filename);
|
|
||||||
|
|
||||||
println!("Path: {:?}", full_path);
|
|
||||||
|
|
||||||
assert!(full_path.exists(), "Path does not exists {:?}", full_path);
|
|
||||||
let filepath = full_path.display().to_string();
|
|
||||||
|
|
||||||
match meta_nouveaou::get_meta(meta_type::Type::Title, &filepath) {
|
|
||||||
Ok(title) => {
|
|
||||||
let found = title == "Just roll it";
|
|
||||||
assert!(found, "Meta information was not found {:?}", title);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
1244
src/meta.rs
Normal file
1244
src/meta.rs
Normal file
File diff suppressed because it is too large
Load Diff
30
src/types.rs
Normal file
30
src/types.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
pub enum Type {
|
||||||
|
Title,
|
||||||
|
Artist,
|
||||||
|
Album,
|
||||||
|
AlbumArtist,
|
||||||
|
Genre,
|
||||||
|
Date,
|
||||||
|
Track,
|
||||||
|
Disc,
|
||||||
|
TrackCount,
|
||||||
|
DiscCount,
|
||||||
|
}
|
||||||
|
|
||||||
|
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()),
|
||||||
|
super::Type::TrackCount => Ok("TRACKCOUNT".to_owned()),
|
||||||
|
super::Type::DiscCount => Ok("DISCCOUNT".to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
tests/sample_tracks3/Sample Tracks 3 - Other one.png
Normal file
BIN
tests/sample_tracks3/Sample Tracks 3 - Other one.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
tests/sample_tracks3/Sample Tracks 3.png
Normal file
BIN
tests/sample_tracks3/Sample Tracks 3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user