use spotify user id from librespot session for web api requests

fixes broken web api requests for users who logged in with their email address

fixes #98
This commit is contained in:
Henrik Friedrichsen
2019-10-12 16:15:53 +02:00
parent 82a199b5d2
commit d01dad9a57
2 changed files with 10 additions and 4 deletions

View File

@@ -38,7 +38,9 @@ fn get_metadata(track: Option<Track>) -> Metadata {
); );
hm.insert( hm.insert(
"mpris:length".to_string(), "mpris:length".to_string(),
Variant(Box::new(track.map(|t| t.duration * 1_000).unwrap_or(0) as i64)), Variant(Box::new(
track.map(|t| t.duration * 1_000).unwrap_or(0) as i64
)),
); );
hm.insert( hm.insert(
"mpris:artUrl".to_string(), "mpris:artUrl".to_string(),

View File

@@ -203,12 +203,12 @@ impl Spotify {
normalisation: false, normalisation: false,
normalisation_pregain: 0.0, normalisation_pregain: 0.0,
}; };
let user = credentials.username.clone(); let (user_tx, user_rx) = oneshot::channel();
let (tx, rx) = mpsc::unbounded(); let (tx, rx) = mpsc::unbounded();
{ {
let events = events.clone(); let events = events.clone();
thread::spawn(move || Self::worker(events, rx, player_config, credentials)); thread::spawn(move || Self::worker(events, rx, player_config, credentials, user_tx));
} }
let spotify = Spotify { let spotify = Spotify {
@@ -218,7 +218,7 @@ impl Spotify {
since: RwLock::new(None), since: RwLock::new(None),
token_issued: RwLock::new(None), token_issued: RwLock::new(None),
channel: tx, channel: tx,
user, user: user_rx.wait().expect("error retrieving userid from worker"),
}; };
// acquire token for web api usage // acquire token for web api usage
@@ -283,10 +283,14 @@ impl Spotify {
commands: mpsc::UnboundedReceiver<WorkerCommand>, commands: mpsc::UnboundedReceiver<WorkerCommand>,
player_config: PlayerConfig, player_config: PlayerConfig,
credentials: Credentials, credentials: Credentials,
user_tx: oneshot::Sender<String>,
) { ) {
let mut core = Core::new().unwrap(); let mut core = Core::new().unwrap();
let session = Self::create_session(&mut core, credentials); let session = Self::create_session(&mut core, credentials);
user_tx
.send(session.username())
.expect("could not pass username back to Spotify::new");
let backend = audio_backend::find(None).unwrap(); let backend = audio_backend::find(None).unwrap();
let (player, _eventchannel) = let (player, _eventchannel) =