rename genres to playlists

This commit is contained in:
Gvidas Juknevičius 2024-09-14 00:31:55 +03:00
parent 7eca925a8e
commit 266b580df7
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
6 changed files with 28 additions and 30 deletions

6
.gitignore vendored
View File

@ -1,6 +1,4 @@
/out /out
/music_mgr/target /target
/music_mgr/config.json
/music_mgr/manifest.json
/.venv
/config.json /config.json
/manifest.json

View File

@ -10,7 +10,7 @@ pub async fn add(cfg: &ConfigWrapper, manifest: &mut Manifest, downloader: &mut
log::debug!("url: {url:?}"); log::debug!("url: {url:?}");
log::debug!("name: {name:?}"); log::debug!("name: {name:?}");
let mut genres = manifest.get_genres().keys().map(|f| f.clone()).collect::<Vec<String>>(); let mut genres = manifest.get_playlists().keys().map(|f| f.clone()).collect::<Vec<String>>();
genres.sort(); genres.sort();

View File

@ -65,7 +65,7 @@ impl eframe::App for Gui {
.max_width(f32::INFINITY) .max_width(f32::INFINITY)
.auto_shrink(false) .auto_shrink(false)
.show(ui, |ui| { .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 { for (song_name, song) in songs {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0; ui.spacing_mut().item_spacing.x = 0.0;

View File

@ -66,7 +66,7 @@ impl Gui {
*song.get_url_str_mut() = self.song_editor.ed_url.clone(); *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; return;
}; };

View File

@ -32,7 +32,7 @@ impl Downloader {
pub async fn download_all(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<usize> { pub async fn download_all(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<usize> {
let format = manifest.get_format(); 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 { for (song_name, song) in songs {
self.download_song(cfg, song_name, song, &genre, format).await?; self.download_song(cfg, song_name, song, &genre, format).await?;
self.count += crate::process_manager::wait_for_procs_untill(10).await?; self.count += crate::process_manager::wait_for_procs_untill(10).await?;

View File

@ -31,7 +31,7 @@ pub struct Manifest {
#[serde(skip)] #[serde(skip)]
path: PathBuf, path: PathBuf,
format: Format, format: Format,
genres: HashMap<GenreName, Genre> playlists: HashMap<GenreName, Genre>
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -40,32 +40,32 @@ impl Manifest {
&self.format &self.format
} }
pub fn add_song(&mut self, genre: GenreName, name: SongName, song: Song) -> Option<Song> { pub fn add_song(&mut self, genre: GenreName, name: SongName, song: Song) -> Option<Song> {
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> { 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> { 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) { pub fn add_playlist(&mut self, name: GenreName) {
self.genres.insert(name, Default::default()); self.playlists.insert(name, Default::default());
} }
pub fn get_genre(&self, name: GenreName) -> Option<&Genre> { pub fn get_playlist(&self, name: GenreName) -> Option<&Genre> {
self.genres.get(&name) self.playlists.get(&name)
} }
pub fn get_genre_mut(&mut self, name: GenreName) -> Option<&mut Genre> { pub fn get_playlist_mut(&mut self, name: GenreName) -> Option<&mut Genre> {
self.genres.get_mut(&name) self.playlists.get_mut(&name)
} }
pub fn get_genres(&self) -> &HashMap<GenreName, Genre> { pub fn get_playlists(&self) -> &HashMap<GenreName, Genre> {
&self.genres &self.playlists
} }
pub fn get_genres_mut(&mut self) -> &mut HashMap<GenreName, Genre> { pub fn get_playlists_mut(&mut self) -> &mut HashMap<GenreName, Genre> {
&mut self.genres &mut self.playlists
} }
pub fn get_song_count(&self) -> usize { pub fn get_song_count(&self) -> usize {
let mut count = 0; let mut count = 0;
for (_, v) in &self.genres { for (_, v) in &self.playlists {
count += v.len(); count += v.len();
} }
count count
@ -76,7 +76,7 @@ impl Manifest {
let data = std::fs::read_to_string(path)?; let data = std::fs::read_to_string(path)?;
let s: Self = serde_json::from_str(data.as_str())?; let s: Self = serde_json::from_str(data.as_str())?;
self.genres = s.genres; self.playlists = s.playlists;
self.format = s.format; self.format = s.format;
Ok(()) Ok(())