librespot/src/main.rs

96 lines
2.2 KiB
Rust
Raw Normal View History

2015-04-25 20:32:07 +00:00
#![crate_name = "librespot"]
2015-06-23 14:38:29 +00:00
#![feature(alloc,plugin,core,collections,std_misc,zero_one)]
2015-04-25 20:32:07 +00:00
#![plugin(protobuf_macros)]
#[macro_use] extern crate lazy_static;
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;
extern crate shannon;
2015-04-25 20:32:07 +00:00
extern crate rand;
extern crate readall;
2015-06-23 14:38:29 +00:00
extern crate vorbis;
extern crate librespot_protocol;
2015-04-25 20:32:07 +00:00
2015-06-23 14:38:29 +00:00
#[macro_use] mod util;
mod audio_decrypt;
mod audio_file;
mod audio_key;
2015-04-25 20:32:07 +00:00
mod connection;
mod keys;
2015-06-23 14:38:29 +00:00
mod mercury;
mod metadata;
mod player;
2015-04-25 20:32:07 +00:00
mod session;
2015-06-23 14:38:29 +00:00
mod stream;
mod subsystem;
2015-04-25 20:32:07 +00:00
2015-06-23 14:38:29 +00:00
use std::clone::Clone;
use std::fs::File;
2015-06-23 14:38:29 +00:00
use std::io::{Read, Write};
use std::path::Path;
2015-06-23 14:38:29 +00:00
use metadata::{MetadataCache, AlbumRef, ArtistRef, TrackRef};
use session::{Config, Session};
use util::SpotifyId;
use player::Player;
2015-04-25 20:32:07 +00:00
fn main() {
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-06-23 14:38:29 +00:00
let track_uri = args.next().unwrap();
let track_id = SpotifyId::from_base62(track_uri.split(':').nth(2).unwrap());
let mut appkey = Vec::new();
appkey_file.read_to_end(&mut appkey).unwrap();
let config = Config {
application_key: appkey,
user_agent: "ABC".to_string(),
device_id: "ABC".to_string()
};
2015-06-23 14:38:29 +00:00
let session = Session::new(config);
session.login(username, password);
session.poll();
2015-06-23 14:38:29 +00:00
let mut cache = MetadataCache::new(session.metadata.clone());
let track : TrackRef = cache.get(track_id);
let album : AlbumRef = {
let handle = track.wait();
let data = handle.unwrap();
eprintln!("{}", data.name);
cache.get(data.album)
};
let artists : Vec<ArtistRef> = {
let handle = album.wait();
let data = handle.unwrap();
eprintln!("{}", data.name);
data.artists.iter().map(|id| {
cache.get(*id)
}).collect()
};
for artist in artists {
let handle = artist.wait();
let data = handle.unwrap();
eprintln!("{}", data.name);
}
Player::play(&session, track);
loop {
session.poll();
}
2015-04-25 20:32:07 +00:00
}