use aspotify::{AuthCodeFlow, ClientCredentials, Scope};
use std::fs;
use std::io::{self, Write};
#[tokio::main]
async fn main() {
dotenv::dotenv().unwrap();
let credentials = ClientCredentials::from_env().unwrap();
let url = aspotify::get_authorization_url(
&credentials.id,
&[
Scope::UgcImageUpload,
Scope::UserReadPlaybackState,
Scope::UserModifyPlaybackState,
Scope::UserReadCurrentlyPlaying,
Scope::Streaming,
Scope::AppRemoteControl,
Scope::UserReadEmail,
Scope::UserReadPrivate,
Scope::PlaylistReadCollaborative,
Scope::PlaylistModifyPublic,
Scope::PlaylistReadPrivate,
Scope::PlaylistModifyPrivate,
Scope::UserLibraryModify,
Scope::UserLibraryRead,
Scope::UserTopRead,
Scope::UserReadRecentlyPlayed,
Scope::UserFollowRead,
Scope::UserFollowModify,
],
false,
"http://non.existant/",
)
.await;
println!("Go to this website: {}", url);
print!("Enter the URL that you were redirected to: ");
io::stdout().flush().unwrap();
let mut redirect = String::new();
io::stdin().read_line(&mut redirect).unwrap();
let flow = AuthCodeFlow::from_redirect(&credentials, &redirect)
.await
.unwrap();
fs::write(".refresh_token", flow.get_refresh_token()).unwrap();
}