2015-07-08 18:28:17 +00:00
|
|
|
#![feature(plugin,scoped)]
|
2015-07-02 17:24:25 +00:00
|
|
|
#![allow(deprecated)]
|
2015-07-07 21:40:31 +00:00
|
|
|
//#![allow(unused_imports,dead_code)]
|
2015-04-25 20:32:07 +00:00
|
|
|
|
|
|
|
#![plugin(protobuf_macros)]
|
|
|
|
#[macro_use] extern crate lazy_static;
|
|
|
|
|
2015-07-01 18:47:51 +00:00
|
|
|
|
2015-04-25 20:32:07 +00:00
|
|
|
extern crate byteorder;
|
|
|
|
extern crate crypto;
|
|
|
|
extern crate gmp;
|
|
|
|
extern crate num;
|
2015-06-23 14:38:29 +00:00
|
|
|
extern crate portaudio;
|
2015-04-25 20:32:07 +00:00
|
|
|
extern crate protobuf;
|
2015-05-09 10:07:24 +00:00
|
|
|
extern crate shannon;
|
2015-04-25 20:32:07 +00:00
|
|
|
extern crate rand;
|
2015-05-09 10:07:24 +00:00
|
|
|
extern crate readall;
|
2015-06-23 14:38:29 +00:00
|
|
|
extern crate vorbis;
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2015-07-08 18:28:17 +00:00
|
|
|
#[macro_use] extern crate librespot;
|
2015-04-25 20:32:07 +00:00
|
|
|
|
2015-06-23 14:38:29 +00:00
|
|
|
use std::clone::Clone;
|
2015-05-09 10:07:24 +00:00
|
|
|
use std::fs::File;
|
2015-06-23 14:38:29 +00:00
|
|
|
use std::io::{Read, Write};
|
2015-05-09 10:07:24 +00:00
|
|
|
use std::path::Path;
|
2015-07-02 17:24:25 +00:00
|
|
|
use std::thread;
|
2015-07-07 21:40:31 +00:00
|
|
|
use std::path::PathBuf;
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2015-07-08 18:28:17 +00:00
|
|
|
use librespot::metadata::{AlbumRef, ArtistRef, TrackRef};
|
|
|
|
use librespot::session::{Config, Session};
|
|
|
|
use librespot::util::SpotifyId;
|
|
|
|
use librespot::util::version::version_string;
|
2015-07-08 19:50:44 +00:00
|
|
|
use librespot::player::Player;
|
|
|
|
use librespot::spirc::SpircManager;
|
2015-04-25 20:32:07 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-05-09 10:07:24 +00:00
|
|
|
let mut args = std::env::args().skip(1);
|
|
|
|
let mut appkey_file = File::open(Path::new(&args.next().unwrap())).unwrap();
|
|
|
|
let username = args.next().unwrap();
|
|
|
|
let password = args.next().unwrap();
|
2015-07-07 21:40:31 +00:00
|
|
|
let cache_location = args.next().unwrap();
|
2015-07-01 23:27:19 +00:00
|
|
|
let name = args.next().unwrap();
|
2015-05-09 10:07:24 +00:00
|
|
|
|
|
|
|
let mut appkey = Vec::new();
|
|
|
|
appkey_file.read_to_end(&mut appkey).unwrap();
|
|
|
|
|
|
|
|
let config = Config {
|
|
|
|
application_key: appkey,
|
2015-07-01 23:27:19 +00:00
|
|
|
user_agent: version_string(),
|
2015-07-07 21:40:31 +00:00
|
|
|
device_id: name.clone(),
|
|
|
|
cache_location: PathBuf::from(cache_location)
|
2015-05-09 10:07:24 +00:00
|
|
|
};
|
2015-06-23 14:38:29 +00:00
|
|
|
let session = Session::new(config);
|
2015-07-01 23:27:19 +00:00
|
|
|
session.login(username.clone(), password);
|
2015-06-23 14:38:29 +00:00
|
|
|
session.poll();
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2015-07-02 17:24:25 +00:00
|
|
|
let poll_thread = thread::scoped(|| {
|
|
|
|
loop {
|
|
|
|
session.poll();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-02 19:42:49 +00:00
|
|
|
let player = Player::new(&session);
|
|
|
|
|
2015-07-08 19:50:44 +00:00
|
|
|
let mut spirc_manager = SpircManager::new(&session, &player, username, name);
|
|
|
|
spirc_manager.run();
|
2015-07-01 17:49:03 +00:00
|
|
|
|
2015-07-02 17:24:25 +00:00
|
|
|
poll_thread.join();
|
2015-07-01 17:49:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 17:24:25 +00:00
|
|
|
fn print_track(session: &Session, track_id: SpotifyId) {
|
|
|
|
let track : TrackRef = session.metadata(track_id);
|
2015-06-23 14:38:29 +00:00
|
|
|
|
|
|
|
let album : AlbumRef = {
|
|
|
|
let handle = track.wait();
|
|
|
|
let data = handle.unwrap();
|
|
|
|
eprintln!("{}", data.name);
|
2015-07-02 17:24:25 +00:00
|
|
|
session.metadata(data.album)
|
2015-06-23 14:38:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let artists : Vec<ArtistRef> = {
|
|
|
|
let handle = album.wait();
|
|
|
|
let data = handle.unwrap();
|
|
|
|
eprintln!("{}", data.name);
|
|
|
|
data.artists.iter().map(|id| {
|
2015-07-02 17:24:25 +00:00
|
|
|
session.metadata(*id)
|
2015-06-23 14:38:29 +00:00
|
|
|
}).collect()
|
|
|
|
};
|
|
|
|
|
|
|
|
for artist in artists {
|
|
|
|
let handle = artist.wait();
|
|
|
|
let data = handle.unwrap();
|
|
|
|
eprintln!("{}", data.name);
|
|
|
|
}
|
2015-04-25 20:32:07 +00:00
|
|
|
}
|