Skip to content

Commit

Permalink
Camelot in renamer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Aug 29, 2024
1 parent e8d9fbb commit 9e77b63
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 2 additions & 4 deletions crates/onetagger-autotag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crossbeam_channel::{unbounded, Sender, Receiver};
use onetagger_tag::{AudioFileFormat, Tag, Field, TagDate, CoverType, TagImpl, EXTENSIONS};
use onetagger_shared::Settings;
use onetagger_player::AudioSources;
use onetagger_tagger::{Track, AudioFileInfo, TaggerConfig, StylesOptions, AutotaggerSource, AutotaggerSourceBuilder, CAMELOT_NOTES};
use onetagger_tagger::{Track, AudioFileInfo, TaggerConfig, StylesOptions, AutotaggerSource, AutotaggerSourceBuilder};

use crate::shazam::Shazam;
mod shazam;
Expand Down Expand Up @@ -121,9 +121,7 @@ impl TrackImpl for Track {
let mut value = self.key.as_ref().unwrap().to_string();
// Convert to camelot
if config.camelot {
if let Some((_, c)) = CAMELOT_NOTES.iter().find(|(o, _)| o == &value) {
value = c.to_string();
}
value = onetagger_tagger::to_camelot(&value).to_owned();
}
tag.set_field(Field::Key, vec![value], config.overwrite_tag(SupportedTag::Key));
}
Expand Down
5 changes: 3 additions & 2 deletions crates/onetagger-renamer/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ lazy_static! {
SymbolDoc::prop("last", "Get the last item in an array"),
];

pub static ref FUNCTIONS: [SymbolDoc; 15] = [
pub static ref FUNCTIONS: [SymbolDoc; 17] = [
SymbolDoc::f("lower", "Convert all to lowercase", vec![]),
SymbolDoc::f("lowercase", "Convert all to lowercase", vec![]),
SymbolDoc::f("upper", "Convert all to uppercase", vec![]),
Expand All @@ -58,7 +58,8 @@ lazy_static! {
SymbolDoc::f("join", "Join array into string with custom separator", vec![DocParameter::s("separator", true)]),
SymbolDoc::f("parent", "Get parent folder of path", vec![]),
SymbolDoc::f("filename", "Get file/folder name of path", vec![]),

SymbolDoc::f("camelot", "Convert key to camelot, or keep original", vec![DocParameter::s("value", true)]),
SymbolDoc::f("uncamelot", "Convert key from camelot, or keep original", vec![DocParameter::s("value", true)]),
];
}

Expand Down
22 changes: 22 additions & 0 deletions crates/onetagger-renamer/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,28 @@ impl Token for TokenFunction {
Some(Data::String(a.last()?.to_string()))
},
}
},
// Conver to camelot
"camelot" => {
match data {
Data::String(s) => {
Some(Data::String(onetagger_tagger::to_camelot(s).to_owned()))
},
Data::Array(a) => {
Some(Data::Array(a.iter().map(|v| onetagger_tagger::to_camelot(v).to_owned()).collect()))
}
}
},
// Convert from camelot
"uncamelot" => {
match data {
Data::String(s) => {
Some(Data::String(onetagger_tagger::from_camelot(s).to_owned()))
},
Data::Array(a) => {
Some(Data::Array(a.iter().map(|v| onetagger_tagger::from_camelot(v).to_owned()).collect()))
}
}
}
f => {
error!("Invalid function: {f}!");
Expand Down
17 changes: 17 additions & 0 deletions crates/onetagger-tagger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,23 @@ pub const CAMELOT_NOTES: [(&str, &str); 35] = [
("E", "12B"),
];

/// Convert to camelot or return original
pub fn to_camelot(key: &str) -> &str {
if let Some((_, v)) = CAMELOT_NOTES.iter().find(|(k, _)| *k == key.trim()) {
return *v;
}
key
}

/// Convert from camelot to normal key
pub fn from_camelot(key: &str) -> &str {
if let Some((v, _)) = CAMELOT_NOTES.iter().find(|(_, k)| *k == key.trim()) {
return *v;
}
key
}


pub trait LyricsExt {
/// Generate LRC data
/// If meta is present, will be written
Expand Down

0 comments on commit 9e77b63

Please sign in to comment.