mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Use the correct country when checking for track availability.
This commit is contained in:
parent
22d586e473
commit
8c2aa28d43
2 changed files with 29 additions and 12 deletions
|
@ -23,7 +23,7 @@ pub trait MetadataTrait : Send + 'static {
|
|||
type Message: protobuf::MessageStatic;
|
||||
|
||||
fn base_url() -> &'static str;
|
||||
fn parse(msg: &Self::Message) -> Self;
|
||||
fn parse(msg: &Self::Message, session: &Session) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -62,7 +62,7 @@ impl MetadataTrait for Track {
|
|||
"hm://metadata/3/track"
|
||||
}
|
||||
|
||||
fn parse(msg: &Self::Message) -> Self {
|
||||
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||
Track {
|
||||
id: SpotifyId::from_raw(msg.get_gid()),
|
||||
name: msg.get_name().to_owned(),
|
||||
|
@ -77,7 +77,10 @@ impl MetadataTrait for Track {
|
|||
alternatives: msg.get_alternative().iter()
|
||||
.map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
||||
.collect(),
|
||||
available: parse_restrictions(msg.get_restriction().iter(), "FR", "premium"),
|
||||
available: parse_restrictions(
|
||||
msg.get_restriction().iter(),
|
||||
&session.0.data.read().unwrap().country,
|
||||
"premium"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +92,7 @@ impl MetadataTrait for Album {
|
|||
"hm://metadata/3/album"
|
||||
}
|
||||
|
||||
fn parse(msg: &Self::Message) -> Self {
|
||||
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||
Album {
|
||||
id: SpotifyId::from_raw(msg.get_gid()),
|
||||
name: msg.get_name().to_owned(),
|
||||
|
@ -115,7 +118,7 @@ impl MetadataTrait for Artist {
|
|||
"hm://metadata/3/artist"
|
||||
}
|
||||
|
||||
fn parse(msg: &Self::Message) -> Self {
|
||||
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||
Artist {
|
||||
id: SpotifyId::from_raw(msg.get_gid()),
|
||||
name: msg.get_name().to_owned(),
|
||||
|
@ -133,16 +136,17 @@ impl MetadataManager {
|
|||
pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId)
|
||||
-> MetadataRef<T> {
|
||||
|
||||
let _session = session.clone();
|
||||
session.mercury(MercuryRequest {
|
||||
method: MercuryMethod::GET,
|
||||
uri: format!("{}/{}", T::base_url(), id.to_base16()),
|
||||
content_type: None,
|
||||
payload: Vec::new()
|
||||
}).and_then(|response| {
|
||||
}).and_then(move |response| {
|
||||
let msg : T::Message = protobuf::parse_from_bytes(
|
||||
response.payload.first().unwrap()).unwrap();
|
||||
|
||||
Ok(T::parse(&msg))
|
||||
Ok(T::parse(&msg, &_session))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use crypto::sha1::Sha1;
|
|||
use eventual::Future;
|
||||
use protobuf::{self, Message};
|
||||
use rand::thread_rng;
|
||||
use std::sync::{Mutex, Arc, mpsc};
|
||||
use std::sync::{Mutex, RwLock, Arc, mpsc};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use connection::{self, PlainConnection, CipherConnection};
|
||||
|
@ -28,7 +28,12 @@ pub struct Config {
|
|||
}
|
||||
|
||||
pub struct SessionData {
|
||||
pub country: String,
|
||||
}
|
||||
|
||||
pub struct SessionInternal {
|
||||
pub config: Config,
|
||||
pub data: RwLock<SessionData>,
|
||||
|
||||
mercury: Mutex<MercuryManager>,
|
||||
metadata: Mutex<MetadataManager>,
|
||||
|
@ -40,7 +45,7 @@ pub struct SessionData {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Session(pub Arc<SessionData>);
|
||||
pub struct Session(pub Arc<SessionInternal>);
|
||||
|
||||
impl Session {
|
||||
pub fn new(mut config: Config) -> Session {
|
||||
|
@ -116,8 +121,11 @@ impl Session {
|
|||
|
||||
let cipher_connection = connection.setup_cipher(shared_keys);
|
||||
|
||||
Session(Arc::new(SessionData {
|
||||
Session(Arc::new(SessionInternal {
|
||||
config: config,
|
||||
data: RwLock::new(SessionData {
|
||||
country: String::new(),
|
||||
}),
|
||||
|
||||
rx_connection: Mutex::new(cipher_connection.clone()),
|
||||
tx_connection: Mutex::new(cipher_connection),
|
||||
|
@ -165,6 +173,11 @@ impl Session {
|
|||
0x4a => (),
|
||||
0x9 => self.0.stream.lock().unwrap().handle(cmd, data),
|
||||
0xd | 0xe => self.0.audio_key.lock().unwrap().handle(cmd, data),
|
||||
0x1b => {
|
||||
self.0.data.write().unwrap().country =
|
||||
String::from_utf8(data).unwrap();
|
||||
},
|
||||
|
||||
0xb2...0xb6 => self.0.mercury.lock().unwrap().handle(cmd, data),
|
||||
0xac => eprintln!("Authentication succeedded"),
|
||||
0xad => eprintln!("Authentication failed"),
|
||||
|
|
Loading…
Reference in a new issue