Add detection for whether an artist should be synced
This commit is contained in:
parent
93196f4dd8
commit
d9691ca6d2
|
@ -62,20 +62,31 @@ impl Registry {
|
|||
|
||||
pub fn save_albums_file(&self) -> Result<(), Error> {
|
||||
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();
|
||||
albums.sort();
|
||||
for album in albums {
|
||||
let parent = album.parent().unwrap();
|
||||
if parent != cur_parent {
|
||||
writeln!(file, "{}/", parent.to_str().unwrap());
|
||||
cur_parent = parent.to_path_buf();
|
||||
}
|
||||
if self.selected_albums.contains(album) {
|
||||
writeln!(file, "{}/***", album.to_str().unwrap());
|
||||
let artist = album.parent().unwrap();
|
||||
if artist != cur_artist {
|
||||
let artist_str = format!("{}/", artist.to_str().unwrap());
|
||||
// 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, "#{}/***", album.to_str().unwrap());
|
||||
writeln!(file, "#{}", artist_str)?;
|
||||
}
|
||||
cur_artist = artist.to_path_buf();
|
||||
}
|
||||
let album_str = album.to_str().unwrap();
|
||||
if self.selected_albums.contains(album) {
|
||||
writeln!(file, "{}/***", album_str)?;
|
||||
} else {
|
||||
writeln!(file, "#{}/***", album_str)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Reference in New Issue