lastfm_edit/
track.rs

1/// Represents a music track with associated metadata.
2///
3/// This structure contains track information as parsed from Last.fm pages,
4/// including play count and optional timestamp data for scrobbles.
5///
6/// # Examples
7///
8/// ```rust
9/// use lastfm_edit::Track;
10///
11/// let track = Track {
12///     name: "Paranoid Android".to_string(),
13///     artist: "Radiohead".to_string(),
14///     playcount: 42,
15///     timestamp: Some(1640995200), // Unix timestamp
16///     album: Some("OK Computer".to_string()),
17///     album_artist: Some("Radiohead".to_string()),
18/// };
19///
20/// println!("{} by {} (played {} times)", track.name, track.artist, track.playcount);
21/// if let Some(album) = &track.album {
22///     println!("From album: {}", album);
23/// }
24/// ```
25#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
26pub struct Track {
27    /// The track name/title
28    pub name: String,
29    /// The artist name
30    pub artist: String,
31    /// Number of times this track has been played/scrobbled
32    pub playcount: u32,
33    /// Unix timestamp of when this track was scrobbled (if available)
34    ///
35    /// This field is populated when tracks are retrieved from recent scrobbles
36    /// or individual scrobble data, but may be `None` for aggregate track listings.
37    pub timestamp: Option<u64>,
38    /// The album name (if available)
39    ///
40    /// This field is populated when tracks are retrieved from recent scrobbles
41    /// where album information is available in the edit forms. May be `None`
42    /// for aggregate track listings or when album information is not available.
43    pub album: Option<String>,
44    /// The album artist name (if available and different from track artist)
45    ///
46    /// This field is populated when tracks are retrieved from recent scrobbles
47    /// where album artist information is available. May be `None` for tracks
48    /// where the album artist is the same as the track artist, or when this
49    /// information is not available.
50    pub album_artist: Option<String>,
51}
52
53/// Represents a paginated collection of tracks.
54///
55/// This structure is returned by track listing methods and provides
56/// information about the current page and pagination state.
57///
58/// # Examples
59///
60/// ```rust
61/// use lastfm_edit::{Track, TrackPage};
62///
63/// let page = TrackPage {
64///     tracks: vec![
65///         Track {
66///             name: "Song 1".to_string(),
67///             artist: "Artist".to_string(),
68///             playcount: 10,
69///             timestamp: None,
70///             album: None,
71///             album_artist: None,
72///         }
73///     ],
74///     page_number: 1,
75///     has_next_page: true,
76///     total_pages: Some(5),
77/// };
78///
79/// println!("Page {} of {:?}, {} tracks",
80///          page.page_number,
81///          page.total_pages,
82///          page.tracks.len());
83/// ```
84#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
85pub struct TrackPage {
86    /// The tracks on this page
87    pub tracks: Vec<Track>,
88    /// Current page number (1-indexed)
89    pub page_number: u32,
90    /// Whether there are more pages available
91    pub has_next_page: bool,
92    /// Total number of pages, if known
93    ///
94    /// This may be `None` if the total page count cannot be determined
95    /// from the Last.fm response.
96    pub total_pages: Option<u32>,
97}