use std::fs;
use std::io::{self, Write};
use aspotify::{Client, ClientCredentials, Scope};
#[tokio::main]
async fn main() {
dotenv::dotenv().unwrap();
let client = Client::new(ClientCredentials::from_env().unwrap());
let (url, state) = aspotify::authorization_url(
&client.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,
]
.iter()
.copied(),
false,
"http://non.existant/",
);
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();
client.redirected(&redirect, &state).await.unwrap();
fs::write(".refresh_token", client.refresh_token().await.unwrap()).unwrap();
}