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;
|
type Message: protobuf::MessageStatic;
|
||||||
|
|
||||||
fn base_url() -> &'static str;
|
fn base_url() -> &'static str;
|
||||||
fn parse(msg: &Self::Message) -> Self;
|
fn parse(msg: &Self::Message, session: &Session) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -62,7 +62,7 @@ impl MetadataTrait for Track {
|
||||||
"hm://metadata/3/track"
|
"hm://metadata/3/track"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(msg: &Self::Message) -> Self {
|
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||||
Track {
|
Track {
|
||||||
id: SpotifyId::from_raw(msg.get_gid()),
|
id: SpotifyId::from_raw(msg.get_gid()),
|
||||||
name: msg.get_name().to_owned(),
|
name: msg.get_name().to_owned(),
|
||||||
|
@ -77,7 +77,10 @@ impl MetadataTrait for Track {
|
||||||
alternatives: msg.get_alternative().iter()
|
alternatives: msg.get_alternative().iter()
|
||||||
.map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
.map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
||||||
.collect(),
|
.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"
|
"hm://metadata/3/album"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(msg: &Self::Message) -> Self {
|
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||||
Album {
|
Album {
|
||||||
id: SpotifyId::from_raw(msg.get_gid()),
|
id: SpotifyId::from_raw(msg.get_gid()),
|
||||||
name: msg.get_name().to_owned(),
|
name: msg.get_name().to_owned(),
|
||||||
|
@ -115,7 +118,7 @@ impl MetadataTrait for Artist {
|
||||||
"hm://metadata/3/artist"
|
"hm://metadata/3/artist"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(msg: &Self::Message) -> Self {
|
fn parse(msg: &Self::Message, session: &Session) -> Self {
|
||||||
Artist {
|
Artist {
|
||||||
id: SpotifyId::from_raw(msg.get_gid()),
|
id: SpotifyId::from_raw(msg.get_gid()),
|
||||||
name: msg.get_name().to_owned(),
|
name: msg.get_name().to_owned(),
|
||||||
|
@ -131,18 +134,19 @@ impl MetadataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId)
|
pub fn get<T: MetadataTrait>(&mut self, session: &Session, id: SpotifyId)
|
||||||
-> MetadataRef<T> {
|
-> MetadataRef<T> {
|
||||||
|
|
||||||
|
let _session = session.clone();
|
||||||
session.mercury(MercuryRequest {
|
session.mercury(MercuryRequest {
|
||||||
method: MercuryMethod::GET,
|
method: MercuryMethod::GET,
|
||||||
uri: format!("{}/{}", T::base_url(), id.to_base16()),
|
uri: format!("{}/{}", T::base_url(), id.to_base16()),
|
||||||
content_type: None,
|
content_type: None,
|
||||||
payload: Vec::new()
|
payload: Vec::new()
|
||||||
}).and_then(|response| {
|
}).and_then(move |response| {
|
||||||
let msg : T::Message = protobuf::parse_from_bytes(
|
let msg : T::Message = protobuf::parse_from_bytes(
|
||||||
response.payload.first().unwrap()).unwrap();
|
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 eventual::Future;
|
||||||
use protobuf::{self, Message};
|
use protobuf::{self, Message};
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use std::sync::{Mutex, Arc, mpsc};
|
use std::sync::{Mutex, RwLock, Arc, mpsc};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use connection::{self, PlainConnection, CipherConnection};
|
use connection::{self, PlainConnection, CipherConnection};
|
||||||
|
@ -28,7 +28,12 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SessionData {
|
pub struct SessionData {
|
||||||
|
pub country: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SessionInternal {
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
|
pub data: RwLock<SessionData>,
|
||||||
|
|
||||||
mercury: Mutex<MercuryManager>,
|
mercury: Mutex<MercuryManager>,
|
||||||
metadata: Mutex<MetadataManager>,
|
metadata: Mutex<MetadataManager>,
|
||||||
|
@ -40,7 +45,7 @@ pub struct SessionData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Session(pub Arc<SessionData>);
|
pub struct Session(pub Arc<SessionInternal>);
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn new(mut config: Config) -> Session {
|
pub fn new(mut config: Config) -> Session {
|
||||||
|
@ -116,8 +121,11 @@ impl Session {
|
||||||
|
|
||||||
let cipher_connection = connection.setup_cipher(shared_keys);
|
let cipher_connection = connection.setup_cipher(shared_keys);
|
||||||
|
|
||||||
Session(Arc::new(SessionData {
|
Session(Arc::new(SessionInternal {
|
||||||
config: config,
|
config: config,
|
||||||
|
data: RwLock::new(SessionData {
|
||||||
|
country: String::new(),
|
||||||
|
}),
|
||||||
|
|
||||||
rx_connection: Mutex::new(cipher_connection.clone()),
|
rx_connection: Mutex::new(cipher_connection.clone()),
|
||||||
tx_connection: Mutex::new(cipher_connection),
|
tx_connection: Mutex::new(cipher_connection),
|
||||||
|
@ -165,6 +173,11 @@ impl Session {
|
||||||
0x4a => (),
|
0x4a => (),
|
||||||
0x9 => self.0.stream.lock().unwrap().handle(cmd, data),
|
0x9 => self.0.stream.lock().unwrap().handle(cmd, data),
|
||||||
0xd | 0xe => self.0.audio_key.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),
|
0xb2...0xb6 => self.0.mercury.lock().unwrap().handle(cmd, data),
|
||||||
0xac => eprintln!("Authentication succeedded"),
|
0xac => eprintln!("Authentication succeedded"),
|
||||||
0xad => eprintln!("Authentication failed"),
|
0xad => eprintln!("Authentication failed"),
|
||||||
|
@ -175,7 +188,7 @@ impl Session {
|
||||||
pub fn send_packet(&self, cmd: u8, data: &[u8]) -> connection::Result<()> {
|
pub fn send_packet(&self, cmd: u8, data: &[u8]) -> connection::Result<()> {
|
||||||
self.0.tx_connection.lock().unwrap().send_packet(cmd, data)
|
self.0.tx_connection.lock().unwrap().send_packet(cmd, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn audio_key(&self, track: SpotifyId, file: FileId) -> Future<AudioKey, ()> {
|
pub fn audio_key(&self, track: SpotifyId, file: FileId) -> Future<AudioKey, ()> {
|
||||||
self.0.audio_key.lock().unwrap().request(self, track, file)
|
self.0.audio_key.lock().unwrap().request(self, track, file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue