From bf60f6e7ab08c92552156f3979537fcab337f69a Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Thu, 3 Aug 2017 19:58:44 +0100 Subject: [PATCH] Create new librespot-core crate --- Cargo.lock | 120 ++++++++++++------ Cargo.toml | 5 + build.rs | 32 ----- core/Cargo.toml | 53 ++++++++ core/build.rs | 43 +++++++ {src => core/src}/apresolve.rs | 0 {src => core/src}/audio_key.rs | 0 .../mod.rs => core/src/authentication.rs | 2 - {src => core/src}/cache/mod.rs | 0 {src => core/src}/channel.rs | 0 {src => core/src}/component.rs | 0 {src => core/src}/config.rs | 33 ++--- {src => core/src}/connection/codec.rs | 0 {src => core/src}/connection/handshake.rs | 0 {src => core/src}/connection/mod.rs | 0 {src => core/src}/diffie_hellman.rs | 0 core/src/lib.in.rs | 1 + core/src/lib.rs | 50 ++++++++ {src => core/src}/mercury/mod.rs | 0 {src => core/src}/mercury/sender.rs | 0 {src => core/src}/mercury/types.rs | 0 {src => core/src}/session.rs | 0 {src => core/src}/util/int128.rs | 0 {src => core/src}/util/mod.rs | 0 {src => core/src}/util/spotify_id.rs | 0 {src => core/src}/util/subfile.rs | 0 {src => core/src}/version.rs | 0 src/album_cover.rs | 6 +- src/audio_decrypt.rs | 2 +- src/audio_file.rs | 6 +- src/{authentication => }/discovery.rs | 8 +- src/keymaster.rs | 5 +- src/lib.in.rs | 1 - src/lib.rs | 17 +-- src/main.rs | 22 ++-- src/metadata.rs | 6 +- src/player.rs | 7 +- src/spirc.rs | 15 ++- 38 files changed, 293 insertions(+), 141 deletions(-) create mode 100644 core/Cargo.toml create mode 100644 core/build.rs rename {src => core/src}/apresolve.rs (100%) rename {src => core/src}/audio_key.rs (100%) rename src/authentication/mod.rs => core/src/authentication.rs (99%) rename {src => core/src}/cache/mod.rs (100%) rename {src => core/src}/channel.rs (100%) rename {src => core/src}/component.rs (100%) rename {src => core/src}/config.rs (99%) rename {src => core/src}/connection/codec.rs (100%) rename {src => core/src}/connection/handshake.rs (100%) rename {src => core/src}/connection/mod.rs (100%) rename {src => core/src}/diffie_hellman.rs (100%) create mode 100644 core/src/lib.in.rs create mode 100644 core/src/lib.rs rename {src => core/src}/mercury/mod.rs (100%) rename {src => core/src}/mercury/sender.rs (100%) rename {src => core/src}/mercury/types.rs (100%) rename {src => core/src}/session.rs (100%) rename {src => core/src}/util/int128.rs (100%) rename {src => core/src}/util/mod.rs (100%) rename {src => core/src}/util/spotify_id.rs (100%) rename {src => core/src}/util/subfile.rs (100%) rename {src => core/src}/version.rs (100%) rename src/{authentication => }/discovery.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 87ace96b..2e5ac65d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,44 +1,8 @@ [root] -name = "librespot" +name = "librespot-protocol" version = "0.1.0" dependencies = [ - "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)", - "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)", - "librespot-protocol 0.1.0", - "linear-map 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "mdns 0.2.0 (git+https://github.com/plietar/rust-mdns)", - "num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "portaudio-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf_macros 0.6.0 (git+https://github.com/plietar/rust-protobuf-macros)", - "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", - "serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", - "shannon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-signal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tremor 0.1.0 (git+https://github.com/plietar/rust-tremor)", - "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "vorbis 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -275,10 +239,90 @@ dependencies = [ ] [[package]] -name = "librespot-protocol" +name = "librespot" version = "0.1.0" dependencies = [ + "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)", + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)", + "librespot-core 0.1.0", + "librespot-protocol 0.1.0", + "linear-map 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "mdns 0.2.0 (git+https://github.com/plietar/rust-mdns)", + "num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "portaudio-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf_macros 0.6.0 (git+https://github.com/plietar/rust-protobuf-macros)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", + "serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "shannon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-signal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tremor 0.1.0 (git+https://github.com/plietar/rust-tremor)", + "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "vorbis 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "librespot-core" +version = "0.1.0" +dependencies = [ + "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)", + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)", + "librespot-protocol 0.1.0", + "linear-map 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "mdns 0.2.0 (git+https://github.com/plietar/rust-mdns)", + "num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "portaudio-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf_macros 0.6.0 (git+https://github.com/plietar/rust-protobuf-macros)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", + "serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "shannon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-signal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tremor 0.1.0 (git+https://github.com/plietar/rust-tremor)", + "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "vorbis 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ddbcc609..6199505b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ keywords = ["spotify"] repository = "https://github.com/plietar/librespot" readme = "README.md" +[workspace] + [lib] name = "librespot" path = "src/lib.rs" @@ -21,6 +23,9 @@ doc = false [dependencies.librespot-protocol] path = "protocol" +[dependencies.librespot-core] +path = "core" + [dependencies] base64 = "0.5.0" bit-set = "0.4.0" diff --git a/build.rs b/build.rs index 9222c3dc..033187ec 100644 --- a/build.rs +++ b/build.rs @@ -1,46 +1,14 @@ -extern crate vergen; extern crate protobuf_macros; -extern crate rand; -use rand::Rng; use std::env; use std::path::PathBuf; -use std::fs::OpenOptions; -use std::io::Write; fn main() { - let out = PathBuf::from(env::var("OUT_DIR").unwrap()); - vergen::vergen(vergen::OutputFns::all()).unwrap(); - - let build_id: String = rand::thread_rng() - .gen_ascii_chars() - .take(8) - .collect(); - - let mut version_file = - OpenOptions::new() - .write(true) - .append(true) - .open(&out.join("version.rs")) - .unwrap(); - - let build_id_fn = format!(" -/// Generate a random build id. -pub fn build_id() -> &'static str {{ - \"{}\" -}} -", build_id); - - if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) { - println!("{}", e); - } - protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap(); println!("cargo:rerun-if-changed=src/lib.in.rs"); println!("cargo:rerun-if-changed=src/spirc.rs"); - println!("cargo:rerun-if-changed=src/connection"); } diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 00000000..be909d0d --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,53 @@ +[package] +name = "librespot-core" +version = "0.1.0" +authors = ["Paul Lietar "] +build = "build.rs" + +[dependencies.librespot-protocol] +path = "../protocol" + +[dependencies] +base64 = "0.5.0" +bit-set = "0.4.0" +byteorder = "1.0" +env_logger = "0.4.0" +getopts = "0.2.14" +hyper = { git = "https://github.com/hyperium/hyper" } +lazy_static = "0.2.0" +linear-map = "1.0" +log = "0.3.5" +num-bigint = "0.1.35" +num-integer = "0.1.32" +num-traits = "0.1.36" +protobuf = "1.1" +rand = "0.3.13" +rpassword = "0.3.0" +rust-crypto = { git = "https://github.com/awmath/rust-crypto.git", branch = "avx2" } +serde = "0.9.6" +serde_json = "0.9.5" +serde_derive = "0.9.6" +shannon = "0.2.0" +tempfile = "2.1" +url = "1.3" + +vorbis = "0.1.0" +tremor = { git = "https://github.com/plietar/rust-tremor", optional = true } + +alsa = { git = "https://github.com/plietar/rust-alsa", optional = true } +portaudio-rs = { version = "0.3.0", optional = true } +libpulse-sys = { git = "https://github.com/astro/libpulse-sys", optional = true } + +mdns = { git = "https://github.com/plietar/rust-mdns" } + +error-chain = { version = "0.9.0", default_features = false } +futures = "0.1.8" +tokio-core = "0.1.2" +tokio-proto = "0.1.0" +tokio-signal = "0.1" +uuid = { version = "0.4", features = ["v4"] } + +[build-dependencies] +rand = "0.3.13" +vergen = "0.1.0" +protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros", features = ["with-syntex"] } diff --git a/core/build.rs b/core/build.rs new file mode 100644 index 00000000..01fd14a1 --- /dev/null +++ b/core/build.rs @@ -0,0 +1,43 @@ +extern crate vergen; +extern crate protobuf_macros; +extern crate rand; + +use rand::Rng; +use std::env; +use std::path::PathBuf; +use std::fs::OpenOptions; +use std::io::Write; + +fn main() { + let out = PathBuf::from(env::var("OUT_DIR").unwrap()); + + vergen::vergen(vergen::OutputFns::all()).unwrap(); + + let build_id: String = rand::thread_rng() + .gen_ascii_chars() + .take(8) + .collect(); + + let mut version_file = + OpenOptions::new() + .write(true) + .append(true) + .open(&out.join("version.rs")) + .unwrap(); + + let build_id_fn = format!(" +/// Generate a random build id. +pub fn build_id() -> &'static str {{ + \"{}\" +}} +", build_id); + + if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) { + println!("{}", e); + } + + protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap(); + + println!("cargo:rerun-if-changed=src/lib.in.rs"); + println!("cargo:rerun-if-changed=src/connection"); +} diff --git a/src/apresolve.rs b/core/src/apresolve.rs similarity index 100% rename from src/apresolve.rs rename to core/src/apresolve.rs diff --git a/src/audio_key.rs b/core/src/audio_key.rs similarity index 100% rename from src/audio_key.rs rename to core/src/audio_key.rs diff --git a/src/authentication/mod.rs b/core/src/authentication.rs similarity index 99% rename from src/authentication/mod.rs rename to core/src/authentication.rs index 2f8559a2..0075fe0d 100644 --- a/src/authentication/mod.rs +++ b/core/src/authentication.rs @@ -16,8 +16,6 @@ use std::path::Path; use protocol::authentication::AuthenticationType; -pub mod discovery; - #[derive(Debug, Clone)] #[derive(Serialize, Deserialize)] pub struct Credentials { diff --git a/src/cache/mod.rs b/core/src/cache/mod.rs similarity index 100% rename from src/cache/mod.rs rename to core/src/cache/mod.rs diff --git a/src/channel.rs b/core/src/channel.rs similarity index 100% rename from src/channel.rs rename to core/src/channel.rs diff --git a/src/component.rs b/core/src/component.rs similarity index 100% rename from src/component.rs rename to core/src/component.rs diff --git a/src/config.rs b/core/src/config.rs similarity index 99% rename from src/config.rs rename to core/src/config.rs index 6325d1a1..7dcb97d3 100644 --- a/src/config.rs +++ b/core/src/config.rs @@ -4,6 +4,23 @@ use std::fmt; use version; +#[derive(Clone,Debug)] +pub struct SessionConfig { + pub user_agent: String, + pub device_id: String, +} + +impl Default for SessionConfig { + fn default() -> SessionConfig { + let device_id = Uuid::new_v4().hyphenated().to_string(); + SessionConfig { + user_agent: version::version_string(), + device_id: device_id, + } + } +} + + #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum Bitrate { Bitrate96, @@ -83,22 +100,6 @@ impl Default for DeviceType { } } -#[derive(Clone,Debug)] -pub struct SessionConfig { - pub user_agent: String, - pub device_id: String, -} - -impl Default for SessionConfig { - fn default() -> SessionConfig { - let device_id = Uuid::new_v4().hyphenated().to_string(); - SessionConfig { - user_agent: version::version_string(), - device_id: device_id, - } - } -} - #[derive(Clone,Debug)] pub struct PlayerConfig { pub bitrate: Bitrate, diff --git a/src/connection/codec.rs b/core/src/connection/codec.rs similarity index 100% rename from src/connection/codec.rs rename to core/src/connection/codec.rs diff --git a/src/connection/handshake.rs b/core/src/connection/handshake.rs similarity index 100% rename from src/connection/handshake.rs rename to core/src/connection/handshake.rs diff --git a/src/connection/mod.rs b/core/src/connection/mod.rs similarity index 100% rename from src/connection/mod.rs rename to core/src/connection/mod.rs diff --git a/src/diffie_hellman.rs b/core/src/diffie_hellman.rs similarity index 100% rename from src/diffie_hellman.rs rename to core/src/diffie_hellman.rs diff --git a/core/src/lib.in.rs b/core/src/lib.in.rs new file mode 100644 index 00000000..b3b606b4 --- /dev/null +++ b/core/src/lib.in.rs @@ -0,0 +1 @@ +pub mod connection; diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 00000000..39ae1f2f --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,50 @@ +#![cfg_attr(feature = "cargo-clippy", allow(unused_io_amount))] + +// TODO: many items from tokio-core::io have been deprecated in favour of tokio-io +#![allow(deprecated)] + +#[macro_use] extern crate error_chain; +#[macro_use] extern crate futures; +#[macro_use] extern crate lazy_static; +#[macro_use] extern crate log; +#[macro_use] extern crate serde_derive; + +extern crate base64; +extern crate bit_set; +extern crate byteorder; +extern crate crypto; +extern crate getopts; +extern crate hyper; +extern crate linear_map; +extern crate mdns; +extern crate num_bigint; +extern crate num_integer; +extern crate num_traits; +extern crate protobuf; +extern crate rand; +extern crate rpassword; +extern crate serde; +extern crate serde_json; +extern crate shannon; +extern crate tempfile; +extern crate tokio_core; +extern crate tokio_proto; +extern crate url; +extern crate uuid; + +pub extern crate librespot_protocol as protocol; + +#[macro_use] mod component; +pub mod apresolve; +pub mod audio_key; +pub mod authentication; +pub mod cache; +pub mod channel; +pub mod config; +pub mod diffie_hellman; +pub mod mercury; +pub mod session; +pub mod util; +pub mod version; + +include!(concat!(env!("OUT_DIR"), "/lib.rs")); diff --git a/src/mercury/mod.rs b/core/src/mercury/mod.rs similarity index 100% rename from src/mercury/mod.rs rename to core/src/mercury/mod.rs diff --git a/src/mercury/sender.rs b/core/src/mercury/sender.rs similarity index 100% rename from src/mercury/sender.rs rename to core/src/mercury/sender.rs diff --git a/src/mercury/types.rs b/core/src/mercury/types.rs similarity index 100% rename from src/mercury/types.rs rename to core/src/mercury/types.rs diff --git a/src/session.rs b/core/src/session.rs similarity index 100% rename from src/session.rs rename to core/src/session.rs diff --git a/src/util/int128.rs b/core/src/util/int128.rs similarity index 100% rename from src/util/int128.rs rename to core/src/util/int128.rs diff --git a/src/util/mod.rs b/core/src/util/mod.rs similarity index 100% rename from src/util/mod.rs rename to core/src/util/mod.rs diff --git a/src/util/spotify_id.rs b/core/src/util/spotify_id.rs similarity index 100% rename from src/util/spotify_id.rs rename to core/src/util/spotify_id.rs diff --git a/src/util/subfile.rs b/core/src/util/subfile.rs similarity index 100% rename from src/util/subfile.rs rename to core/src/util/subfile.rs diff --git a/src/version.rs b/core/src/version.rs similarity index 100% rename from src/version.rs rename to core/src/version.rs diff --git a/src/album_cover.rs b/src/album_cover.rs index ae800ecb..ea3c197b 100644 --- a/src/album_cover.rs +++ b/src/album_cover.rs @@ -1,9 +1,9 @@ use byteorder::{BigEndian, WriteBytesExt}; use std::io::Write; -use channel::ChannelData; -use session::Session; -use util::FileId; +use core::channel::ChannelData; +use core::session::Session; +use core::util::FileId; pub fn get(session: &Session, file: FileId) -> ChannelData { let (channel_id, channel) = session.channel().allocate(); diff --git a/src/audio_decrypt.rs b/src/audio_decrypt.rs index 98be833c..b745c4e0 100644 --- a/src/audio_decrypt.rs +++ b/src/audio_decrypt.rs @@ -5,7 +5,7 @@ use num_traits::FromPrimitive; use std::io; use std::ops::Add; -use audio_key::AudioKey; +use core::audio_key::AudioKey; const AUDIO_AESIV: &'static [u8] = &[0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93]; diff --git a/src/audio_file.rs b/src/audio_file.rs index 1681c0e6..1547e364 100644 --- a/src/audio_file.rs +++ b/src/audio_file.rs @@ -10,9 +10,9 @@ use std::io::{self, Read, Write, Seek, SeekFrom}; use std::sync::{Arc, Condvar, Mutex}; use tempfile::NamedTempFile; -use channel::{Channel, ChannelData, ChannelError, ChannelHeaders}; -use session::Session; -use util::FileId; +use core::channel::{Channel, ChannelData, ChannelError, ChannelHeaders}; +use core::session::Session; +use core::util::FileId; const CHUNK_SIZE: usize = 0x20000; diff --git a/src/authentication/discovery.rs b/src/discovery.rs similarity index 98% rename from src/authentication/discovery.rs rename to src/discovery.rs index a5732aed..3eaa5f0a 100644 --- a/src/authentication/discovery.rs +++ b/src/discovery.rs @@ -2,7 +2,6 @@ use base64; use crypto::digest::Digest; use crypto::mac::Mac; use crypto; -use diffie_hellman::{DH_GENERATOR, DH_PRIME}; use futures::sync::mpsc; use futures::{Future, Stream, BoxFuture, Poll, Async}; use hyper::server::{Service, NewService, Request, Response, Http}; @@ -17,9 +16,10 @@ use tokio_core::net::TcpListener; use tokio_core::reactor::Handle; use url; -use authentication::Credentials; -use util; -use config::ConnectConfig; +use core::diffie_hellman::{DH_GENERATOR, DH_PRIME}; +use core::authentication::Credentials; +use core::util; +use core::config::ConnectConfig; #[derive(Clone)] struct Discovery(Arc); diff --git a/src/keymaster.rs b/src/keymaster.rs index ac2cfd3f..6ed11fd7 100644 --- a/src/keymaster.rs +++ b/src/keymaster.rs @@ -1,7 +1,8 @@ use futures::{Future, BoxFuture}; use serde_json; -use session::Session; -use mercury::MercuryError; + +use core::mercury::MercuryError; +use core::session::Session; #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] diff --git a/src/lib.in.rs b/src/lib.in.rs index 55ce5507..be92c5d8 100644 --- a/src/lib.in.rs +++ b/src/lib.in.rs @@ -1,2 +1 @@ -pub mod connection; pub mod spirc; diff --git a/src/lib.rs b/src/lib.rs index a6d66a45..f070a07f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,7 @@ // TODO: many items from tokio-core::io have been deprecated in favour of tokio-io #![allow(deprecated)] -#[macro_use] extern crate error_chain; #[macro_use] extern crate futures; -#[macro_use] extern crate lazy_static; #[macro_use] extern crate log; #[macro_use] extern crate serde_json; #[macro_use] extern crate serde_derive; @@ -34,6 +32,7 @@ extern crate tokio_proto; extern crate url; extern crate uuid; +pub extern crate librespot_core as core; pub extern crate librespot_protocol as protocol; #[cfg(not(feature = "with-tremor"))] @@ -50,26 +49,14 @@ extern crate portaudio_rs; #[cfg(feature = "libpulse-sys")] extern crate libpulse_sys; - -#[macro_use] mod component; pub mod album_cover; -pub mod apresolve; pub mod audio_backend; pub mod audio_decrypt; pub mod audio_file; -pub mod audio_key; -pub mod authentication; -pub mod cache; -pub mod channel; -pub mod config; -pub mod diffie_hellman; +pub mod discovery; pub mod keymaster; -pub mod mercury; pub mod metadata; pub mod mixer; pub mod player; -pub mod session; -pub mod util; -pub mod version; include!(concat!(env!("OUT_DIR"), "/lib.rs")); diff --git a/src/main.rs b/src/main.rs index 8f90c3b8..c2850cdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,17 +20,17 @@ use tokio_core::reactor::{Handle, Core}; use tokio_core::io::IoStream; use std::mem; -use librespot::spirc::{Spirc, SpircTask}; -use librespot::authentication::{get_credentials, Credentials}; -use librespot::authentication::discovery::{discovery, DiscoveryStream}; -use librespot::audio_backend::{self, Sink, BACKENDS}; -use librespot::cache::Cache; -use librespot::player::Player; -use librespot::session::Session; -use librespot::config::{Bitrate, DeviceType, PlayerConfig, SessionConfig, ConnectConfig}; -use librespot::mixer::{self, Mixer}; +use librespot::core::authentication::{get_credentials, Credentials}; +use librespot::core::cache::Cache; +use librespot::core::config::{Bitrate, DeviceType, PlayerConfig, SessionConfig, ConnectConfig}; +use librespot::core::session::Session; +use librespot::core::version; -use librespot::version; +use librespot::audio_backend::{self, Sink, BACKENDS}; +use librespot::discovery::{discovery, DiscoveryStream}; +use librespot::mixer::{self, Mixer}; +use librespot::player::Player; +use librespot::spirc::{Spirc, SpircTask}; fn usage(program: &str, opts: &getopts::Options) -> String { let brief = format!("Usage: {} [options]", program); @@ -152,7 +152,7 @@ fn setup(args: &[String]) -> Setup { }; let session_config = { - let device_id = librespot::session::device_id(&name); + let device_id = librespot::core::session::device_id(&name); SessionConfig { user_agent: version::version_string(), diff --git a/src/metadata.rs b/src/metadata.rs index f47c1cf7..d1aee408 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -2,10 +2,10 @@ use futures::{Future, BoxFuture}; use linear_map::LinearMap; use protobuf; -use mercury::MercuryError; +use core::mercury::MercuryError; use protocol; -use session::Session; -use util::{SpotifyId, FileId, StrChunksExt}; +use core::session::Session; +use core::util::{SpotifyId, FileId, StrChunksExt}; pub use protocol::metadata::AudioFile_Format as FileFormat; diff --git a/src/player.rs b/src/player.rs index b443daf0..f1afa9fa 100644 --- a/src/player.rs +++ b/src/player.rs @@ -8,14 +8,15 @@ use std::thread; use std; use vorbis::{self, VorbisError}; +use core::config::{Bitrate, PlayerConfig}; +use core::session::Session; +use core::util::{self, SpotifyId, Subfile}; + use audio_backend::Sink; use audio_decrypt::AudioDecrypt; use audio_file::AudioFile; use metadata::{FileFormat, Track, Metadata}; -use session::Session; use mixer::AudioFilter; -use util::{self, SpotifyId, Subfile}; -use config::{Bitrate, PlayerConfig}; #[derive(Clone)] pub struct Player { diff --git a/src/spirc.rs b/src/spirc.rs index 2b877939..3b5fb77c 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -5,17 +5,18 @@ use futures::sync::{oneshot, mpsc}; use futures::{Future, Stream, Sink, Async, Poll, BoxFuture}; use protobuf::{self, Message}; -use config::ConnectConfig; -use mercury::MercuryError; -use mixer::Mixer; -use player::Player; -use session::Session; -use util::{now_ms, SpotifyId, SeqGenerator}; -use version; +use core::config::ConnectConfig; +use core::mercury::MercuryError; +use core::session::Session; +use core::util::{now_ms, SpotifyId, SeqGenerator}; +use core::version; use protocol; use protocol::spirc::{PlayStatus, State, MessageType, Frame, DeviceState}; +use mixer::Mixer; +use player::Player; + pub struct SpircTask { player: Player, mixer: Box,