Skip to content

Commit

Permalink
Re-use existing session instead of creating a new one when playing a …
Browse files Browse the repository at this point in the history
…track or getting a token.
  • Loading branch information
michaelherger committed Sep 27, 2024
1 parent 8d1f4df commit 1a14709
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ async fn main() {
setup.start_position,
last_credentials,
setup.player_config,
setup.session_config,
session,
)
.await;
exit(0);
Expand All @@ -2074,7 +2074,7 @@ async fn main() {
setup.scopes,
setup.save_token,
last_credentials,
setup.session_config,
session,
)
.await;
exit(0);
Expand Down
7 changes: 2 additions & 5 deletions src/spotty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::fs;
use std::process::exit;

use librespot::core::authentication::Credentials;
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use librespot::core::spotify_id::SpotifyId;

Expand Down Expand Up @@ -49,13 +48,12 @@ pub async fn get_token(
scopes: Option<String>,
save_token: Option<String>,
last_credentials: Option<Credentials>,
session_config: SessionConfig,
session: Session,
) {
match last_credentials {
Some(last_credentials) => {
if let Some(client_id) = client_id {
let scopes = scopes.unwrap_or_else(|| SCOPES.to_string());
let session = Session::new(session_config, None);
session.set_client_id(client_id.as_str());

match session.connect(last_credentials, true).await {
Expand Down Expand Up @@ -113,7 +111,7 @@ pub async fn play_track(
start_position: u32,
last_credentials: Option<Credentials>,
player_config: PlayerConfig,
session_config: SessionConfig,
session: Session,
) {
match last_credentials {
Some(last_credentials) => {
Expand All @@ -127,7 +125,6 @@ pub async fn play_track(
.as_str(),
);

let session = Session::new(session_config, None);
if let Err(error) = session.connect(last_credentials, false).await {
error!("Failed to create session (play_track): {:?}", error);
return;
Expand Down

0 comments on commit 1a14709

Please sign in to comment.