A tool to sync music with your favorite devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

*: use mimetype instead of trusting the file extension

Gee Sawra 11c094a3 94f35c7f

+16 -19
+9 -9
src/fs.rs
··· 51 51 52 52 /// Returns true if name has one of the supported music file extension. 53 53 fn is_music(name: &String) -> bool { 54 - // TODO: look at the mimetype instead of trusting the extension 55 - let formats = ["flac", "mp3", "ogg", "mp4", "m4a"]; 54 + let formats = ["flac", "mp3", "ogg", "mp4", "m4a", "opus"]; 56 55 57 - formats 58 - .into_iter() 59 - .filter_map(|format| name.ends_with(&format!(".{format}")).then_some(true)) 60 - .collect::<Vec<bool>>() 61 - .into_iter() 62 - .find(|x| *x == true) 63 - .is_some() 56 + let mime = infer::get_from_path(name).unwrap(); 57 + match mime { 58 + Some(mime) => { 59 + let ext = mime.extension(); 60 + formats.iter().find(|f| **f == ext).is_some() 61 + } 62 + None => false, 63 + } 64 64 }
+7 -10
src/model.rs
··· 77 77 78 78 impl std::fmt::Display for Track { 79 79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 80 - write!(f, "{} - {}, {}", self.title, self.album, self.artist) 80 + write!(f, "{} - {}, {}", self.title, self.album, self.artist) 81 81 } 82 82 } 83 83 ··· 105 105 p.push(clean(filename, true)); 106 106 107 107 p.to_str().unwrap().to_string() 108 + } 109 + 110 + pub fn is_lossless(&self) -> bool { 111 + self.extension == "flac" 108 112 } 109 113 } 110 114 ··· 143 147 144 148 t.track_id = track_hash(&t); 145 149 146 - // TODO: use extracted mimetype extension. 147 - let extension = std::path::Path::new(&t.file_path) 148 - .extension() 149 - .unwrap_or(std::ffi::OsStr::new("NONE")) 150 - .to_str() 151 - .unwrap() 152 - .to_string(); 153 - 154 - t.extension = extension; 150 + let mime = infer::get_from_path(&t.file_path).unwrap().unwrap(); 151 + t.extension = mime.extension().to_owned(); 155 152 156 153 t 157 154 }