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
/music_mgr/target
/music_mgr/config.json
/music_mgr/manifest.json
/.venv
/target
/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!("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();

View File

@ -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;

View File

@ -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;
};

View File

@ -32,7 +32,7 @@ impl Downloader {
pub async fn download_all(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<usize> {
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?;

View File

@ -31,7 +31,7 @@ pub struct Manifest {
#[serde(skip)]
path: PathBuf,
format: Format,
genres: HashMap<GenreName, Genre>
playlists: HashMap<GenreName, Genre>
}
#[allow(dead_code)]
@ -40,32 +40,32 @@ impl Manifest {
&self.format
}
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> {
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<GenreName, Genre> {
&self.genres
pub fn get_playlists(&self) -> &HashMap<GenreName, Genre> {
&self.playlists
}
pub fn get_genres_mut(&mut self) -> &mut HashMap<GenreName, Genre> {
&mut self.genres
pub fn get_playlists_mut(&mut self) -> &mut HashMap<GenreName, Genre> {
&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(())