@@ -35,8 +35,8 @@ rand = "0.6.5"
|
|||||||
webbrowser = "0.5"
|
webbrowser = "0.5"
|
||||||
|
|
||||||
[dependencies.rspotify]
|
[dependencies.rspotify]
|
||||||
git = "https://github.com/samrayleung/rspotify"
|
git = "https://github.com/KoffeinFlummi/rspotify"
|
||||||
rev = "9d9cf7c"
|
rev = "9d6c544"
|
||||||
|
|
||||||
[dependencies.librespot]
|
[dependencies.librespot]
|
||||||
git = "https://github.com/librespot-org/librespot.git"
|
git = "https://github.com/librespot-org/librespot.git"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub struct Library {
|
|||||||
pub artists: Arc<RwLock<Vec<Artist>>>,
|
pub artists: Arc<RwLock<Vec<Artist>>>,
|
||||||
pub playlists: Arc<RwLock<Vec<Playlist>>>,
|
pub playlists: Arc<RwLock<Vec<Playlist>>>,
|
||||||
is_done: Arc<RwLock<bool>>,
|
is_done: Arc<RwLock<bool>>,
|
||||||
|
user_id: Option<String>,
|
||||||
ev: EventManager,
|
ev: EventManager,
|
||||||
spotify: Arc<Spotify>,
|
spotify: Arc<Spotify>,
|
||||||
pub use_nerdfont: bool,
|
pub use_nerdfont: bool,
|
||||||
@@ -36,12 +37,15 @@ pub struct Library {
|
|||||||
|
|
||||||
impl Library {
|
impl Library {
|
||||||
pub fn new(ev: &EventManager, spotify: Arc<Spotify>, use_nerdfont: bool) -> Self {
|
pub fn new(ev: &EventManager, spotify: Arc<Spotify>, use_nerdfont: bool) -> Self {
|
||||||
|
let user_id = spotify.current_user().map(|u| u.id);
|
||||||
|
|
||||||
let library = Self {
|
let library = Self {
|
||||||
tracks: Arc::new(RwLock::new(Vec::new())),
|
tracks: Arc::new(RwLock::new(Vec::new())),
|
||||||
albums: Arc::new(RwLock::new(Vec::new())),
|
albums: Arc::new(RwLock::new(Vec::new())),
|
||||||
artists: Arc::new(RwLock::new(Vec::new())),
|
artists: Arc::new(RwLock::new(Vec::new())),
|
||||||
playlists: Arc::new(RwLock::new(Vec::new())),
|
playlists: Arc::new(RwLock::new(Vec::new())),
|
||||||
is_done: Arc::new(RwLock::new(false)),
|
is_done: Arc::new(RwLock::new(false)),
|
||||||
|
user_id,
|
||||||
ev: ev.clone(),
|
ev: ev.clone(),
|
||||||
spotify,
|
spotify,
|
||||||
use_nerdfont,
|
use_nerdfont,
|
||||||
@@ -699,6 +703,13 @@ impl Library {
|
|||||||
playlists.iter().any(|p| p.id == playlist.id)
|
playlists.iter().any(|p| p.id == playlist.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_followed_playlist(&self, playlist: &Playlist) -> bool {
|
||||||
|
self.user_id
|
||||||
|
.as_ref()
|
||||||
|
.map(|id| id != &playlist.owner_id)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn follow_playlist(&self, playlist: &Playlist) {
|
pub fn follow_playlist(&self, playlist: &Playlist) {
|
||||||
if !*self.is_done.read().unwrap() {
|
if !*self.is_done.read().unwrap() {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl ListItem for Playlist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_right(&self, library: Arc<Library>) -> String {
|
fn display_right(&self, library: Arc<Library>) -> String {
|
||||||
let saved = if library.is_saved_playlist(self) {
|
let followed = if library.is_followed_playlist(self) {
|
||||||
if library.use_nerdfont {
|
if library.use_nerdfont {
|
||||||
"\u{f62b} "
|
"\u{f62b} "
|
||||||
} else {
|
} else {
|
||||||
@@ -113,7 +113,7 @@ impl ListItem for Playlist {
|
|||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
format!("{}{:>3} tracks", saved, self.tracks.len())
|
format!("{}{:>3} tracks", followed, self.tracks.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn play(&mut self, queue: Arc<Queue>) {
|
fn play(&mut self, queue: Arc<Queue>) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use rspotify::spotify::model::search::{
|
|||||||
SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks,
|
SearchAlbums, SearchArtists, SearchPlaylists, SearchTracks,
|
||||||
};
|
};
|
||||||
use rspotify::spotify::model::track::{FullTrack, SavedTrack};
|
use rspotify::spotify::model::track::{FullTrack, SavedTrack};
|
||||||
|
use rspotify::spotify::model::user::PrivateUser;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
|
|
||||||
@@ -590,6 +591,10 @@ impl Spotify {
|
|||||||
.map(|fa| fa.artists.iter().map(|a| a.into()).collect())
|
.map(|fa| fa.artists.iter().map(|a| a.into()).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn current_user(&self) -> Option<PrivateUser> {
|
||||||
|
self.api_with_retry(|api| api.current_user())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load(&self, track: &Track) {
|
pub fn load(&self, track: &Track) {
|
||||||
info!("loading track: {:?}", track);
|
info!("loading track: {:?}", track);
|
||||||
self.channel
|
self.channel
|
||||||
|
|||||||
Reference in New Issue
Block a user