Added downloading capabilities in the gui
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// pub mod v1;
|
||||
|
||||
pub mod song;
|
||||
pub mod playlist;
|
||||
use song::Song;
|
||||
|
||||
use std::{collections::HashMap, fmt::{Debug, Display}, path::PathBuf};
|
||||
@@ -11,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
const DEFAULT_MANIFEST: &'static str = include_str!("../../manifest.default.json");
|
||||
|
||||
pub type GenreName = String;
|
||||
|
||||
pub type SongName = String;
|
||||
pub type Genre = HashMap<SongName, song::Song>;
|
||||
|
||||
@@ -31,36 +32,39 @@ pub struct Manifest {
|
||||
#[serde(skip)]
|
||||
path: PathBuf,
|
||||
format: Format,
|
||||
playlists: HashMap<GenreName, Genre>
|
||||
playlists: HashMap<String, playlist::Playlist>,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Manifest {
|
||||
pub fn get_format(&self) -> &Format {
|
||||
&self.format
|
||||
}
|
||||
pub fn add_song(&mut self, genre: GenreName, name: SongName, song: Song) -> Option<Song> {
|
||||
self.get_playlist_mut(genre)?.insert(name, song)
|
||||
pub fn add_song(&mut self, playlist_name: String, name: SongName, song: Song) -> Option<Song> {
|
||||
self.get_playlist_mut(playlist_name)?.add_song(name, song)
|
||||
}
|
||||
pub fn get_song(&self, genre: GenreName, name: &SongName) -> Option<&Song> {
|
||||
self.get_playlist(genre)?.get(name)
|
||||
pub fn get_song(&self, playlist_name: String, name: &String) -> Option<&Song> {
|
||||
self.get_playlist(playlist_name)?.get_song(name)
|
||||
}
|
||||
pub fn get_song_mut(&mut self, genre: GenreName, name: &SongName) -> Option<&mut Song> {
|
||||
self.get_playlist_mut(genre)?.get_mut(name)
|
||||
pub fn get_song_mut(&mut self, playlist_name: String, name: &String) -> Option<&mut Song> {
|
||||
self.get_playlist_mut(playlist_name)?.get_song_mut(name)
|
||||
}
|
||||
pub fn add_playlist(&mut self, name: GenreName) {
|
||||
self.playlists.insert(name, Default::default());
|
||||
pub fn add_playlist(&mut self, playlist_name: String) {
|
||||
self.playlists.insert(playlist_name, Default::default());
|
||||
}
|
||||
pub fn get_playlist(&self, name: GenreName) -> Option<&Genre> {
|
||||
self.playlists.get(&name)
|
||||
pub fn get_playlist(&self, playlist_name: String) -> Option<&playlist::Playlist> {
|
||||
self.playlists.get(&playlist_name)
|
||||
}
|
||||
pub fn get_playlist_mut(&mut self, name: GenreName) -> Option<&mut Genre> {
|
||||
self.playlists.get_mut(&name)
|
||||
pub fn get_playlist_mut(&mut self, playlist_name: String) -> Option<&mut playlist::Playlist> {
|
||||
self.playlists.get_mut(&playlist_name)
|
||||
}
|
||||
pub fn get_playlists(&self) -> &HashMap<GenreName, Genre> {
|
||||
pub fn get_playlists(&self) -> &HashMap<String, playlist::Playlist> {
|
||||
&self.playlists
|
||||
}
|
||||
pub fn get_playlists_mut(&mut self) -> &mut HashMap<GenreName, Genre> {
|
||||
pub fn get_playlists_mut(&mut self) -> &mut HashMap<String, playlist::Playlist> {
|
||||
&mut self.playlists
|
||||
}
|
||||
pub fn get_song_count(&self) -> usize {
|
||||
|
||||
56
src/manifest/playlist.rs
Normal file
56
src/manifest/playlist.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use egui::ahash::HashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::song::Song;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct Playlist {
|
||||
songs: HashMap<String, Song>
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Playlist {
|
||||
pub fn new() -> Self {
|
||||
Self { ..Default::default() }
|
||||
}
|
||||
|
||||
pub fn add_song(&mut self, name: String, song: Song) -> Option<Song> {
|
||||
self.songs.insert(name, song)
|
||||
}
|
||||
|
||||
pub fn remove_song(&mut self, name: &String) -> Option<Song> {
|
||||
self.songs.remove(name)
|
||||
}
|
||||
|
||||
pub fn get_song(&self, name: &String) -> Option<&Song> {
|
||||
self.songs.get(name)
|
||||
}
|
||||
|
||||
pub fn get_songs(&self) -> &HashMap<String, Song> {
|
||||
&self.songs
|
||||
}
|
||||
|
||||
pub fn get_songs_mut(&mut self) -> &mut HashMap<String, Song> {
|
||||
&mut self.songs
|
||||
}
|
||||
|
||||
pub fn get_song_mut(&mut self, name: &String) -> Option<&mut Song> {
|
||||
self.songs.get_mut(name)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.songs.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for Playlist {
|
||||
type Item = (String, Song);
|
||||
type IntoIter = std::collections::hash_map::IntoIter<String, Song>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.songs.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub enum SongType {
|
||||
Youtube,
|
||||
Spotify,
|
||||
@@ -33,13 +33,17 @@ impl Song {
|
||||
pub fn from_url_str(url: String) -> Result<Self> {
|
||||
Self::from_url(url::Url::from_str(url.as_str())?)
|
||||
}
|
||||
|
||||
pub fn from_url(url: url::Url) -> Result<Self> {
|
||||
Ok(Self {
|
||||
url: url.to_string(),
|
||||
typ: url.try_into()?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_type(&mut self, typ: SongType) -> &mut Self {
|
||||
self.typ = typ;
|
||||
self
|
||||
}
|
||||
pub fn get_url(&self) -> Result<url::Url> {
|
||||
Ok(url::Url::from_str(&self.url)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user