diff --git a/Cargo.toml b/Cargo.toml index ec6ccf5..a76ef52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,10 @@ authors = ["Henrik Friedrichsen "] cursive = "0.9" crossbeam-channel = "0.2" env_logger = "0.5.13" +failure = "0.1.3" futures = "0.1" log = "0.4.6" +rspotify = "0.2.5" serde = "1.0" serde_derive = "1.0" toml = "0.4" diff --git a/src/main.rs b/src/main.rs index f55ffc4..3c42c88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ extern crate crossbeam_channel; extern crate cursive; +extern crate failure; extern crate futures; extern crate librespot; +extern crate rspotify; extern crate tokio_core; #[macro_use] diff --git a/src/spotify.rs b/src/spotify.rs index fe7fc3b..8db63c6 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -10,6 +10,11 @@ use librespot::playback::audio_backend; use librespot::playback::config::Bitrate; use librespot::playback::player::Player; +use rspotify::spotify::client::Spotify as SpotifyAPI; +use rspotify::spotify::model::search::SearchTracks; + +use failure::Error; + use futures; use futures::sync::mpsc; use futures::sync::oneshot; @@ -28,8 +33,8 @@ enum WorkerCommand { } pub struct Spotify { + pub api: SpotifyAPI, channel: mpsc::UnboundedSender, - token: Token, } struct Worker { @@ -107,14 +112,14 @@ impl Spotify { Spotify::worker(rx, p, session_config, player_config, credentials, client_id) }); - let spotify = Spotify { + let token = c.wait().unwrap(); + debug!("token received: {:?}", token); + let api = SpotifyAPI::default().access_token(&token.access_token); + + Spotify { + api: api, channel: tx, - token: c.wait().unwrap(), - }; - - info!("token received: {:?}", spotify.token); - - spotify + } } fn worker( @@ -151,6 +156,10 @@ impl Spotify { println!("Spotify::run() finished"); } + pub fn search(&mut self, query: &str, limit: u32, offset: u32) -> Result { + self.api.search_track(query, limit, offset, None) + } + pub fn load(&mut self, track: SpotifyId) { info!("loading track: {:?}", track); self.channel.unbounded_send(WorkerCommand::Load(track)).unwrap();