From 5fa3fc44ed0954298772512d1aa5cf8d5843980d Mon Sep 17 00:00:00 2001 From: Marekkon5 Date: Thu, 14 Mar 2024 23:32:11 +0100 Subject: [PATCH] Spotify release date --- crates/onetagger-platforms/src/spotify.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/onetagger-platforms/src/spotify.rs b/crates/onetagger-platforms/src/spotify.rs index 94289f1..202bf2a 100644 --- a/crates/onetagger-platforms/src/spotify.rs +++ b/crates/onetagger-platforms/src/spotify.rs @@ -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}; @@ -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()