Update playlist every hour
This commit is contained in:
12
src/main.rs
12
src/main.rs
@ -40,6 +40,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let url = spotify.get_authorize_url(false)?;
|
||||
spotify.prompt_for_token(&url).await?;
|
||||
|
||||
loop {
|
||||
println!("Updating playlist...");
|
||||
top_songs_playlist(&spotify, &playlist_name, track_limit).await?;
|
||||
|
||||
// Wait 1 hour before updating again
|
||||
tokio::time::sleep(std::time::Duration::from_secs(60 * 60)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn top_songs_playlist<'a>(spotify: &AuthCodeSpotify, playlist_name: &str, track_limit: usize) -> Result<(), ClientError> {
|
||||
let mut top_tracks = spotify.current_user_top_tracks(Some(TimeRange::ShortTerm));
|
||||
let mut top_track_ids = Vec::new();
|
||||
|
||||
@ -52,7 +62,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
println!("Adding top tracks to playlist: {}", playlist_name);
|
||||
let playlist_id = find_or_create_playlist(&spotify, &playlist_name, spotify.me().await?.id).await?;
|
||||
let playlist_id = find_or_create_playlist(&spotify, playlist_name, spotify.me().await?.id).await?;
|
||||
spotify.playlist_replace_items(playlist_id, top_track_ids.into_iter().map(|track| PlayableId::Track(track))).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user