From 266b580df70316b7073394e8ad157868d31de359 Mon Sep 17 00:00:00 2001 From: MCorange Date: Sat, 14 Sep 2024 00:31:55 +0300 Subject: [PATCH] rename genres to playlists --- .gitignore | 10 ++++----- src/commands/add.rs | 4 ++-- src/commands/gui/mod.rs | 4 ++-- src/commands/gui/song_edit_window.rs | 4 ++-- src/downloader.rs | 4 ++-- src/manifest/mod.rs | 32 ++++++++++++++-------------- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 756598a..01b8ef5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -/out -/music_mgr/target -/music_mgr/config.json -/music_mgr/manifest.json -/.venv -/config.json \ No newline at end of file +/out +/target +/config.json +/manifest.json diff --git a/src/commands/add.rs b/src/commands/add.rs index 176e354..a32a4af 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -10,7 +10,7 @@ pub async fn add(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut log::debug!("url: {url:?}"); log::debug!("name: {name:?}"); - let mut genres = manifest.get_genres().keys().map(|f| f.clone()).collect::>(); + let mut genres = manifest.get_playlists().keys().map(|f| f.clone()).collect::>(); genres.sort(); @@ -47,4 +47,4 @@ pub async fn add(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut } Ok(()) -} \ No newline at end of file +} diff --git a/src/commands/gui/mod.rs b/src/commands/gui/mod.rs index f240cd2..068c64b 100644 --- a/src/commands/gui/mod.rs +++ b/src/commands/gui/mod.rs @@ -65,7 +65,7 @@ impl eframe::App for Gui { .max_width(f32::INFINITY) .auto_shrink(false) .show(ui, |ui| { - for (genre, songs) in self.manifest.get_genres() { + for (genre, songs) in self.manifest.get_playlists() { for (song_name, song) in songs { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0; @@ -102,4 +102,4 @@ impl eframe::App for Gui { }); }); } -} \ No newline at end of file +} diff --git a/src/commands/gui/song_edit_window.rs b/src/commands/gui/song_edit_window.rs index ee45629..c479b3e 100644 --- a/src/commands/gui/song_edit_window.rs +++ b/src/commands/gui/song_edit_window.rs @@ -66,7 +66,7 @@ impl Gui { *song.get_url_str_mut() = self.song_editor.ed_url.clone(); } - let Some(genre) = self.manifest.get_genre_mut(genre.clone()) else { + let Some(genre) = self.manifest.get_playlist_mut(genre.clone()) else { return; }; @@ -76,4 +76,4 @@ impl Gui { let _ = self.manifest.save(None); } } -} \ No newline at end of file +} diff --git a/src/downloader.rs b/src/downloader.rs index 228498f..8bcbb72 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -32,7 +32,7 @@ impl Downloader { pub async fn download_all(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result { let format = manifest.get_format(); - for (genre, songs) in manifest.get_genres() { + for (genre, songs) in manifest.get_playlists() { for (song_name, song) in songs { self.download_song(cfg, song_name, song, &genre, format).await?; self.count += crate::process_manager::wait_for_procs_untill(10).await?; @@ -92,4 +92,4 @@ impl Downloader { crate::process_manager::add_proc(cmd, format!("Downloaded {dl_file}")).await?; Ok(()) } -} \ No newline at end of file +} diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index aee94fb..bea936f 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -31,7 +31,7 @@ pub struct Manifest { #[serde(skip)] path: PathBuf, format: Format, - genres: HashMap + playlists: HashMap } #[allow(dead_code)] @@ -40,32 +40,32 @@ impl Manifest { &self.format } pub fn add_song(&mut self, genre: GenreName, name: SongName, song: Song) -> Option { - self.get_genre_mut(genre)?.insert(name, song) + self.get_playlist_mut(genre)?.insert(name, song) } pub fn get_song(&self, genre: GenreName, name: &SongName) -> Option<&Song> { - self.get_genre(genre)?.get(name) + self.get_playlist(genre)?.get(name) } pub fn get_song_mut(&mut self, genre: GenreName, name: &SongName) -> Option<&mut Song> { - self.get_genre_mut(genre)?.get_mut(name) + self.get_playlist_mut(genre)?.get_mut(name) } - pub fn add_genre(&mut self, name: GenreName) { - self.genres.insert(name, Default::default()); + pub fn add_playlist(&mut self, name: GenreName) { + self.playlists.insert(name, Default::default()); } - pub fn get_genre(&self, name: GenreName) -> Option<&Genre> { - self.genres.get(&name) + pub fn get_playlist(&self, name: GenreName) -> Option<&Genre> { + self.playlists.get(&name) } - pub fn get_genre_mut(&mut self, name: GenreName) -> Option<&mut Genre> { - self.genres.get_mut(&name) + pub fn get_playlist_mut(&mut self, name: GenreName) -> Option<&mut Genre> { + self.playlists.get_mut(&name) } - pub fn get_genres(&self) -> &HashMap { - &self.genres + pub fn get_playlists(&self) -> &HashMap { + &self.playlists } - pub fn get_genres_mut(&mut self) -> &mut HashMap { - &mut self.genres + pub fn get_playlists_mut(&mut self) -> &mut HashMap { + &mut self.playlists } pub fn get_song_count(&self) -> usize { let mut count = 0; - for (_, v) in &self.genres { + for (_, v) in &self.playlists { count += v.len(); } count @@ -76,7 +76,7 @@ impl Manifest { let data = std::fs::read_to_string(path)?; let s: Self = serde_json::from_str(data.as_str())?; - self.genres = s.genres; + self.playlists = s.playlists; self.format = s.format; Ok(())