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