Skip to content

Commit

Permalink
Spotify release date
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Mar 14, 2024
1 parent ba4d5e0 commit 5fa3fc4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/onetagger-platforms/src/spotify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Error;
use chrono::NaiveDate;
use std::time::Duration;
use rspotify::clients::{BaseClient, OAuthClient};
use rspotify::model::{SearchType, TrackId, Id, AlbumId, ArtistId, Modality};
Expand Down Expand Up @@ -237,7 +238,8 @@ fn full_track_to_track(track: FullTrack) -> Track {
duration: track.duration.to_std().unwrap().into(),
track_number: Some(TrackNumber::Number(track.track_number as i32)),
isrc: track.external_ids.into_iter().find(|(k, _)| k == "isrc").map(|(_, v)| v.to_string()),
release_year: track.album.release_date.map(|d| if d.len() > 4 { d[0..4].to_string().parse().ok() } else { None }).flatten(),
release_year: track.album.release_date.as_ref().map(|d| if d.len() > 4 { d[0..4].to_string().parse().ok() } else { None }).flatten(),
release_date: track.album.release_date.as_ref().map(|d| NaiveDate::parse_from_str(d, "%Y-%m-%d").ok()).flatten(),
explicit: Some(track.explicit),
thumbnail: track.album.images.iter().min_by(|a, b| a.width.unwrap_or(1000.0).partial_cmp(&b.width.unwrap_or(1000.0)).unwrap()).map(|i| i.url.to_string()),
..Default::default()
Expand Down

0 comments on commit 5fa3fc4

Please sign in to comment.