982 B · text History 6c56e6c
//! A track, independent of the player it came from. Port of scropple-android's
//! `Track`.

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Track {
    pub artist: String,
    pub title: String,
    pub album: Option<String>,
    pub album_artist: Option<String>,
    /// Milliseconds; 0 when the player didn't say.
    pub duration_ms: u64,
    /// The player it came from (`spotify`, `strawberry`, ...), for filtering.
    pub player: String,
}

impl Track {
    /// Worth scrobbling at all: an artist and a title.
    pub fn is_scrobbleable(&self) -> bool {
        !self.artist.trim().is_empty() && !self.title.trim().is_empty()
    }

    /// Identity for spotting a track change; the album is in it so a live and
    /// a studio take of a song count as different tracks.
    pub fn key(&self) -> String {
        format!(
            "{}\u{1f}{}\u{1f}{}",
            self.artist,
            self.title,
            self.album.as_deref().unwrap_or("")
        )
    }
}