add web api facilities
This commit is contained in:
@@ -7,8 +7,10 @@ authors = ["Henrik Friedrichsen <henrik@affekt.org>"]
|
|||||||
cursive = "0.9"
|
cursive = "0.9"
|
||||||
crossbeam-channel = "0.2"
|
crossbeam-channel = "0.2"
|
||||||
env_logger = "0.5.13"
|
env_logger = "0.5.13"
|
||||||
|
failure = "0.1.3"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
|
rspotify = "0.2.5"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
extern crate crossbeam_channel;
|
extern crate crossbeam_channel;
|
||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
extern crate failure;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate librespot;
|
extern crate librespot;
|
||||||
|
extern crate rspotify;
|
||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ use librespot::playback::audio_backend;
|
|||||||
use librespot::playback::config::Bitrate;
|
use librespot::playback::config::Bitrate;
|
||||||
use librespot::playback::player::Player;
|
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;
|
||||||
use futures::sync::mpsc;
|
use futures::sync::mpsc;
|
||||||
use futures::sync::oneshot;
|
use futures::sync::oneshot;
|
||||||
@@ -28,8 +33,8 @@ enum WorkerCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Spotify {
|
pub struct Spotify {
|
||||||
|
pub api: SpotifyAPI,
|
||||||
channel: mpsc::UnboundedSender<WorkerCommand>,
|
channel: mpsc::UnboundedSender<WorkerCommand>,
|
||||||
token: Token,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Worker {
|
struct Worker {
|
||||||
@@ -107,14 +112,14 @@ impl Spotify {
|
|||||||
Spotify::worker(rx, p, session_config, player_config, credentials, client_id)
|
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,
|
channel: tx,
|
||||||
token: c.wait().unwrap(),
|
}
|
||||||
};
|
|
||||||
|
|
||||||
info!("token received: {:?}", spotify.token);
|
|
||||||
|
|
||||||
spotify
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn worker(
|
fn worker(
|
||||||
@@ -151,6 +156,10 @@ impl Spotify {
|
|||||||
println!("Spotify::run() finished");
|
println!("Spotify::run() finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn search(&mut self, query: &str, limit: u32, offset: u32) -> Result<SearchTracks, Error> {
|
||||||
|
self.api.search_track(query, limit, offset, None)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load(&mut self, track: SpotifyId) {
|
pub fn load(&mut self, track: SpotifyId) {
|
||||||
info!("loading track: {:?}", track);
|
info!("loading track: {:?}", track);
|
||||||
self.channel.unbounded_send(WorkerCommand::Load(track)).unwrap();
|
self.channel.unbounded_send(WorkerCommand::Load(track)).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user