@@ -3,6 +3,7 @@ pub use rspotify::model::{AlbumId, ArtistId, Id, PlaylistId, TrackId, UserId};
33
44use crate :: utils:: { format_duration, map_join} ;
55use serde:: Serialize ;
6+ use std:: borrow:: Cow ;
67
78#[ derive( Serialize , Clone , Debug ) ]
89#[ serde( untagged) ]
@@ -118,6 +119,7 @@ pub struct Track {
118119 pub album : Option < Album > ,
119120 #[ serde( serialize_with = "serialize_duration" ) ]
120121 pub duration : chrono:: Duration ,
122+ pub explicit : bool ,
121123 #[ serde( skip) ]
122124 pub added_at : u64 ,
123125}
@@ -240,6 +242,15 @@ impl Track {
240242 . unwrap_or_default ( )
241243 }
242244
245+ /// gets the track's name, including an explicit label
246+ pub fn display_name ( & self ) -> Cow < ' _ , str > {
247+ if self . explicit {
248+ Cow :: Owned ( format ! ( "{} (Explicit)" , self . name) )
249+ } else {
250+ Cow :: Borrowed ( self . name . as_str ( ) )
251+ }
252+ }
253+
243254 /// tries to convert from a `rspotify_model::SimplifiedTrack` into `Track`
244255 pub fn try_from_simplified_track ( track : rspotify_model:: SimplifiedTrack ) -> Option < Self > {
245256 if track. is_playable . unwrap_or ( true ) {
@@ -249,6 +260,7 @@ impl Track {
249260 artists : from_simplified_artists_to_artists ( track. artists ) ,
250261 album : None ,
251262 duration : track. duration ,
263+ explicit : track. explicit ,
252264 added_at : 0 ,
253265 } )
254266 } else {
@@ -265,6 +277,7 @@ impl Track {
265277 artists : from_simplified_artists_to_artists ( track. artists ) ,
266278 album : Album :: try_from_simplified_album ( track. album ) ,
267279 duration : track. duration ,
280+ explicit : track. explicit ,
268281 added_at : 0 ,
269282 } )
270283 } else {
@@ -278,7 +291,7 @@ impl std::fmt::Display for Track {
278291 write ! (
279292 f,
280293 "{} • {} ▎ {}" ,
281- self . name ,
294+ self . display_name ( ) ,
282295 self . artists_info( ) ,
283296 self . album_info( ) ,
284297 )
0 commit comments