diff --git a/Cargo.toml b/Cargo.toml index ed7da5f..37f1f2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ teloxide = { version = "0.5", features = ["auto-send", "macros"] } log = "0.4" pretty_env_logger = "0.4.0" tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] } -rspotify = { version = "0.10.0", features = ["blocking"] } \ No newline at end of file +aspotify = "0.7.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 88809db..568c60f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use crate::SpotifyURL::Track; -use rspotify::blocking::client::Spotify; -use rspotify::blocking::oauth2::SpotifyClientCredentials; +use aspotify::{Client, ClientCredentials, Market}; use teloxide::prelude::*; enum SpotifyURL { @@ -31,11 +30,11 @@ struct TrackInfo { artist: Vec, } -fn get_spotify_track(spotify: Box, id: &String) -> Option { - match spotify.track(id.as_str()) { +async fn get_spotify_track(spotify: Box, id: &String) -> Option { + match spotify.tracks().get_track(id.as_str(), None).await { Ok(track) => Some(TrackInfo { - name: track.name, - artist: track.artists.iter().map(|x| x.name.clone()).collect(), + name: track.data.name, + artist: track.data.artists.iter().map(|x| x.name.clone()).collect(), }), Err(_e) => None, } @@ -48,19 +47,16 @@ async fn main() { let bot = Bot::from_env().auto_send(); teloxide::repl(bot, |message| async move { - let spotify_creds = SpotifyClientCredentials::default().build(); - let spotify_client = Box::new( - Spotify::default() - .client_credentials_manager(spotify_creds) - .build(), - ); + let spotify_creds = + ClientCredentials::from_env().expect("CLIENT_ID and CLIENT_SECRET not found."); + let spotify_client = Box::new(Client::new(spotify_creds)); log::info!("Connected to Spotify"); let text = message.update.text().and_then(get_spotify_entry); match text { Some(spotify) => match spotify { Track(id) => { - let track_info = get_spotify_track(spotify_client, &id); + let track_info = get_spotify_track(spotify_client, &id).await; match track_info { Some(info) => { let reply = format!(