Add detection for whether an artist should be synced

This commit is contained in:
Paul van Tilburg 2018-08-24 21:21:56 +02:00
parent 93196f4dd8
commit d9691ca6d2
1 changed files with 18 additions and 7 deletions

View File

@ -62,20 +62,31 @@ impl Registry {
pub fn save_albums_file(&self) -> Result<(), Error> { pub fn save_albums_file(&self) -> Result<(), Error> {
let mut file = File::create(format!("{}.list.new", self.device))?; let mut file = File::create(format!("{}.list.new", self.device))?;
let mut cur_parent = PathBuf::new(); let mut cur_artist = PathBuf::new();
let mut albums: Vec<&PathBuf> = self.albums_fs.iter().collect(); let mut albums: Vec<&PathBuf> = self.albums_fs.iter().collect();
albums.sort(); albums.sort();
for album in albums { for album in albums {
let parent = album.parent().unwrap(); let artist = album.parent().unwrap();
if parent != cur_parent { if artist != cur_artist {
writeln!(file, "{}/", parent.to_str().unwrap()); let artist_str = format!("{}/", artist.to_str().unwrap());
cur_parent = parent.to_path_buf(); // FIXME: Make this way more efficient!
if self
.selected_albums
.iter()
.any(|ref path| path.starts_with(&artist_str))
{
writeln!(file, "{}", artist_str)?;
} else {
writeln!(file, "#{}", artist_str)?;
}
cur_artist = artist.to_path_buf();
} }
let album_str = album.to_str().unwrap();
if self.selected_albums.contains(album) { if self.selected_albums.contains(album) {
writeln!(file, "{}/***", album.to_str().unwrap()); writeln!(file, "{}/***", album_str)?;
} else { } else {
writeln!(file, "#{}/***", album.to_str().unwrap()); writeln!(file, "#{}/***", album_str)?;
} }
} }
Ok(()) Ok(())