Skip to content

Instantly share code, notes, and snippets.

@marcelbuesing
Created November 29, 2020 19:40
Show Gist options
  • Select an option

  • Save marcelbuesing/bde682d94fb8440945f4eb5c596b3b5c to your computer and use it in GitHub Desktop.

Select an option

Save marcelbuesing/bde682d94fb8440945f4eb5c596b3b5c to your computer and use it in GitHub Desktop.
use std::env;
use tokio_02 as tokio;
use tokio::runtime::Handle;
use futures_util_03::compat::Future01CompatExt;
use librespot::core::authentication::Credentials;
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use librespot::core::spotify_id::SpotifyId;
use librespot::playback::config::PlayerConfig;
use librespot::playback::audio_backend;
use librespot::playback::player::Player;
#[tokio::main]
async fn main() {
let session_config = SessionConfig::default();
let player_config = PlayerConfig::default();
let args: Vec<_> = env::args().collect();
if args.len() != 4 {
println!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
}
let username = args[1].to_owned();
let password = args[2].to_owned();
let credentials = Credentials::with_password(username, password);
let track = SpotifyId::from_base62(&args[3]).unwrap();
let backend = audio_backend::find(None).unwrap();
println!("Connecting ..");
let handle = Handle::current();
let session = Session::connect(session_config, credentials, None, handle).compat().await.unwrap();
let (mut player, _) = Player::new(player_config, session.clone(), None, move || {
(backend)(None)
});
player.load(track, true, 0);
println!("Playing...");
player.get_end_of_track_future().compat().await;
println!("Done");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment