album art pattern is now case insensitive

This commit is contained in:
Antoine Gersant 2020-12-15 01:44:46 -08:00
parent bd48ad1a5c
commit 404d42d254
2 changed files with 36 additions and 2 deletions

View file

@ -1,7 +1,7 @@
use diesel; use diesel;
use diesel::prelude::*; use diesel::prelude::*;
use std::time::Duration;
use regex::Regex; use regex::Regex;
use std::time::Duration;
use super::*; use super::*;
use crate::app::user; use crate::app::user;
@ -53,7 +53,8 @@ impl Manager {
diesel::result::Error::NotFound => Error::IndexAlbumArtPatternNotFound, diesel::result::Error::NotFound => Error::IndexAlbumArtPatternNotFound,
_ => Error::Unspecified, _ => Error::Unspecified,
}) })
.and_then(|s: String| Regex::new(&s).map_err(|_| Error::IndexAlbumArtPatternInvalid)) .map(|s: String| format!("(?i){}", s))
.and_then(|s| Regex::new(&s).map_err(|_| Error::IndexAlbumArtPatternInvalid))
} }
pub fn read(&self) -> anyhow::Result<Config> { pub fn read(&self) -> anyhow::Result<Config> {

View file

@ -64,6 +64,39 @@ fn test_metadata() {
); );
} }
#[test]
fn test_artwork_pattern_case_insensitive() {
let target: PathBuf = ["test-data", "small-collection", "Khemmis", "Hunted"]
.iter()
.collect();
let mut song_path = target.clone();
song_path.push("05 - Hunted.mp3");
let mut artwork_path = target.clone();
artwork_path.push("folder.jpg");
let db = db::get_test_db(&test_name!());
let vfs_manager = vfs::Manager::new(db.clone());
let user_manager = user::Manager::new(db.clone());
let config_manager = config::Manager::new(db.clone(), user_manager);
let index = Index::new(db.clone(), vfs_manager, config_manager);
index.update().unwrap();
let connection = db.connect().unwrap();
let songs: Vec<Song> = songs::table
.filter(songs::title.eq("Hunted"))
.load(&connection)
.unwrap();
assert_eq!(songs.len(), 1);
let song = &songs[0];
assert_eq!(
song.artwork,
Some(artwork_path.to_string_lossy().into_owned())
);
}
#[test] #[test]
fn test_embedded_artwork() { fn test_embedded_artwork() {
let song_path: PathBuf = [ let song_path: PathBuf = [