diff --git a/codegen/src/collect_album_types.rs b/codegen/src/collect_album_types.rs index d7c054e..752e90a 100644 --- a/codegen/src/collect_album_types.rs +++ b/codegen/src/collect_album_types.rs @@ -64,8 +64,12 @@ pub fn write_samples_to_dict(project_root: &Path) { let mut e_langs = dict_entry.equivalent.clone(); e_langs.push(lang); - collected.get(&lang).unwrap().iter().for_each(|(t, v)| { - dict_entry.album_types.insert(v.to_lowercase(), *t); + e_langs.iter().for_each(|lang| { + collected.get(&lang).unwrap().iter().for_each(|(t, v)| { + dict_entry + .album_types + .insert(v.to_lowercase().trim().to_owned(), *t); + }); }); } diff --git a/src/client/response/music_item.rs b/src/client/response/music_item.rs index a6658af..16b820f 100644 --- a/src/client/response/music_item.rs +++ b/src/client/response/music_item.rs @@ -630,7 +630,29 @@ pub(crate) fn map_artists(artists_p: Option) -> (Vec, pub(crate) fn map_album_type(txt: &str, lang: Language) -> AlbumType { dictionary::entry(lang) .album_types - .get(&txt.to_lowercase()) + .get(txt.to_lowercase().trim()) .copied() .unwrap_or_default() } + +#[cfg(test)] +mod tests { + use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path}; + + use super::*; + + #[test] + fn map_album_type_samples() { + let json_path = Path::new("testfiles/dict/album_type_samples.json"); + let json_file = File::open(json_path).unwrap(); + let atype_samples: BTreeMap> = + serde_json::from_reader(BufReader::new(json_file)).unwrap(); + + atype_samples.iter().for_each(|(lang, entry)| { + entry.iter().for_each(|(album_type, txt)| { + let res = map_album_type(txt, *lang); + assert_eq!(res, *album_type, "lang: {}, txt: {}", lang, txt); + }); + }); + } +} diff --git a/src/util/dictionary.rs b/src/util/dictionary.rs index 92e04a0..ae962f7 100644 --- a/src/util/dictionary.rs +++ b/src/util/dictionary.rs @@ -1886,15 +1886,18 @@ pub(crate) fn entry(lang: Language) -> Entry { ], }, album_types: ::phf::Map { - key: 2980949210194914378, + key: 12913932095322966823, disps: &[ - (2, 0), + (0, 0), + (5, 0), ], entries: &[ + ("microalbum", AlbumType::Ep), ("album", AlbumType::Album), - ("émission", AlbumType::Show), - ("ep", AlbumType::Ep), ("livre audio", AlbumType::Audiobook), + ("émission", AlbumType::Show), + ("simple", AlbumType::Single), + ("ep", AlbumType::Ep), ("single", AlbumType::Single), ], }, diff --git a/testfiles/dict/dictionary.json b/testfiles/dict/dictionary.json index fcdc00d..0c44250 100644 --- a/testfiles/dict/dictionary.json +++ b/testfiles/dict/dictionary.json @@ -1104,6 +1104,8 @@ "album": "Album", "ep": "Ep", "livre audio": "Audiobook", + "microalbum": "Ep", + "simple": "Single", "single": "Single", "émission": "Show" }