pub struct LastFMHandler { /* private fields */ }Implementations§
Source§impl LastFMHandler
impl LastFMHandler
Sourcepub async fn get_user_loved_tracks_with_options(
&self,
limit: impl Into<TrackLimit>,
) -> Result<Vec<LovedTrack>>
👎Deprecated since 2.0.0: Use LovedTracksClient from the api module instead
pub async fn get_user_loved_tracks_with_options( &self, limit: impl Into<TrackLimit>, ) -> Result<Vec<LovedTrack>>
LovedTracksClient from the api module insteadGet loved tracks for a user with all available options.
This is the most flexible method for fetching loved tracks, exposing all parameters
supported by the Last.fm API’s user.getlovedtracks method.
§Arguments
limit- The number of tracks to fetch. UseNoneorTrackLimit::Unlimitedto fetch all tracks.
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<LovedTrack>>- The fetched loved tracks.
§Examples
// Get all loved tracks
let tracks = handler.get_user_loved_tracks_with_options(None).await?;
// Get first 100 loved tracks
let tracks = handler.get_user_loved_tracks_with_options(Some(100)).await?;Sourcepub async fn get_user_loved_tracks(
&self,
limit: impl Into<TrackLimit>,
) -> Result<Vec<LovedTrack>>
👎Deprecated since 2.0.0: Use LovedTracksClient from the api module instead
pub async fn get_user_loved_tracks( &self, limit: impl Into<TrackLimit>, ) -> Result<Vec<LovedTrack>>
LovedTracksClient from the api module insteadSourcepub async fn get_user_recent_tracks(
&self,
limit: impl Into<TrackLimit>,
) -> Result<Vec<RecentTrack>>
👎Deprecated since 2.0.0: Use RecentTracksClient from the api module instead
pub async fn get_user_recent_tracks( &self, limit: impl Into<TrackLimit>, ) -> Result<Vec<RecentTrack>>
RecentTracksClient from the api module insteadSourcepub async fn get_user_top_tracks_with_options(
&self,
limit: impl Into<TrackLimit>,
period: Option<Period>,
) -> Result<Vec<TopTrack>>
👎Deprecated since 2.0.0: Use TopTracksClient from the api module instead
pub async fn get_user_top_tracks_with_options( &self, limit: impl Into<TrackLimit>, period: Option<Period>, ) -> Result<Vec<TopTrack>>
TopTracksClient from the api module insteadGet top tracks for a user with all available options.
This is the most flexible method for fetching top tracks, exposing all parameters
supported by the Last.fm API’s user.gettoptracks method.
§Arguments
limit- The number of tracks to fetch. UseNoneorTrackLimit::Unlimitedto fetch all available top tracks.period- Optional period filter for the time range:Period::Overall- All time (default if None)Period::Week- Last 7 daysPeriod::Month- Last monthPeriod::ThreeMonth- Last 3 monthsPeriod::SixMonth- Last 6 monthsPeriod::TwelveMonth- Last 12 months
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<TopTrack>>- The fetched top tracks.
§Examples
// Get all-time top 50 tracks
let tracks = handler.get_user_top_tracks_with_options(Some(50), None).await?;
// Get top tracks from the last week
let tracks = handler.get_user_top_tracks_with_options(None, Some(Period::Week)).await?;
// Get top 100 tracks from the last 3 months
let tracks = handler.get_user_top_tracks_with_options(Some(100), Some(Period::ThreeMonth)).await?;Sourcepub async fn get_user_top_tracks(
&self,
limit: impl Into<TrackLimit>,
period: Option<Period>,
) -> Result<Vec<TopTrack>>
👎Deprecated since 2.0.0: Use TopTracksClient from the api module instead
pub async fn get_user_top_tracks( &self, limit: impl Into<TrackLimit>, period: Option<Period>, ) -> Result<Vec<TopTrack>>
TopTracksClient from the api module insteadGet top tracks for a user.
§Arguments
limit- The number of tracks to fetch. If None, fetch all available top tracks.period- Optional period filter (Period::Overall,Period::SevenDay,Period::OneMonth,Period::ThreeMonth,Period::SixMonth,Period::TwelveMonth)
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<TopTrack>>- The fetched tracks.
Sourcepub async fn get_and_save_recent_tracks(
&self,
limit: impl Into<TrackLimit>,
format: FileFormat,
filename_prefix: &str,
) -> Result<String>
pub async fn get_and_save_recent_tracks( &self, limit: impl Into<TrackLimit>, format: FileFormat, filename_prefix: &str, ) -> Result<String>
Get and save recent tracks to a file.
§Arguments
limit- The number of tracks to fetch. If None, fetch all tracks.format- The file format to save the tracks in.
§Errors
LastFmError::Api- If the API returns an error.LastFmError::Io- If there is an error saving the file.
§Returns
Result<String, Box<dyn std::error::Error>>- The filename of the saved file.
Sourcepub async fn get_and_save_loved_tracks(
&self,
limit: impl Into<TrackLimit>,
format: FileFormat,
) -> Result<String>
pub async fn get_and_save_loved_tracks( &self, limit: impl Into<TrackLimit>, format: FileFormat, ) -> Result<String>
Get and save loved tracks to a file.
§Arguments
limit- The number of tracks to fetch. If None, fetch all tracks.format- The file format to save the tracks in.
§Errors
FileError- If there was an error reading or writing the fileInvalidUtf8- If the file path is not valid UTF-8
§Returns
Result<String, Box<dyn std::error::Error>>- The filename of the saved file.
Sourcepub async fn get_user_recent_tracks_since(
&self,
from: i64,
to: Option<i64>,
limit: impl Into<TrackLimit>,
) -> Result<Vec<RecentTrack>>
pub async fn get_user_recent_tracks_since( &self, from: i64, to: Option<i64>, limit: impl Into<TrackLimit>, ) -> Result<Vec<RecentTrack>>
Get recent tracks for a user since a given timestamp.
§Arguments
from- The timestamp to fetch tracks since.to- Optional timestamp to fetch tracks until.limit- The number of tracks to fetch. If None, fetch all tracks.
§Errors
FileError- If there was an error reading or writing the fileInvalidUtf8- If the file path is not valid UTF-8
§Returns
Vec<RecentTrack>- The fetched tracks.
Sourcepub async fn get_user_recent_tracks_with_options(
&self,
limit: impl Into<TrackLimit>,
from: Option<i64>,
to: Option<i64>,
extended: bool,
) -> Result<Vec<RecentTrack>>
👎Deprecated since 2.0.0: Use RecentTracksClient from the api module instead
pub async fn get_user_recent_tracks_with_options( &self, limit: impl Into<TrackLimit>, from: Option<i64>, to: Option<i64>, extended: bool, ) -> Result<Vec<RecentTrack>>
RecentTracksClient from the api module insteadGet recent tracks for a user with all available options.
This is the most flexible method for fetching recent tracks, exposing all parameters
supported by the Last.fm API’s user.getrecenttracks method.
§Arguments
limit- The number of tracks to fetch. UseNoneorTrackLimit::Unlimitedto fetch all tracks.from- Optional timestamp (Unix timestamp in seconds) to fetch tracks from this time onwards.to- Optional timestamp (Unix timestamp in seconds) to fetch tracks up until this time.extended- Iftrue, fetches extended track information including additional artist details.
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<RecentTrack>>- The fetched tracks (normal format).Result<Vec<RecentTrackExtended>>- The fetched tracks (extended format) ifextendedistrue.
§Examples
// Get last 50 tracks
let tracks = handler.get_user_recent_tracks_with_options(Some(50), None, None, false).await?;
// Get tracks from the last week
let one_week_ago = (Utc::now() - Duration::days(7)).timestamp();
let tracks = handler.get_user_recent_tracks_with_options(None, Some(one_week_ago), None, false).await?;
// Get tracks between two dates with extended info
let tracks = handler.get_user_recent_tracks_with_options(None, Some(start), Some(end), true).await?;Sourcepub async fn get_user_recent_tracks_extended(
&self,
limit: impl Into<TrackLimit>,
from: Option<i64>,
to: Option<i64>,
) -> Result<Vec<RecentTrackExtended>>
👎Deprecated since 2.0.0: Use RecentTracksClient from the api module instead
pub async fn get_user_recent_tracks_extended( &self, limit: impl Into<TrackLimit>, from: Option<i64>, to: Option<i64>, ) -> Result<Vec<RecentTrackExtended>>
RecentTracksClient from the api module insteadGet recent tracks for a user with extended information.
This method is similar to get_user_recent_tracks_with_options but returns
the extended track format which includes additional artist details.
§Arguments
limit- The number of tracks to fetch. UseNoneorTrackLimit::Unlimitedto fetch all tracks.from- Optional timestamp (Unix timestamp in seconds) to fetch tracks from this time onwards.to- Optional timestamp (Unix timestamp in seconds) to fetch tracks up until this time.
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<RecentTrackExtended>>- The fetched tracks with extended information.
Sourcepub async fn get_user_recent_tracks_between(
&self,
from: i64,
to: i64,
extended: bool,
) -> Result<Vec<RecentTrack>>
👎Deprecated since 2.0.0: Use RecentTracksClient from the api module instead
pub async fn get_user_recent_tracks_between( &self, from: i64, to: i64, extended: bool, ) -> Result<Vec<RecentTrack>>
RecentTracksClient from the api module insteadGet all recent tracks for a user between two dates.
Convenience method for fetching all tracks within a specific time range. This always fetches unlimited tracks (all tracks in the range).
§Arguments
from- Start timestamp (Unix timestamp in seconds) - tracks from this time onwards.to- End timestamp (Unix timestamp in seconds) - tracks up until this time.extended- Iftrue, fetches extended track information including additional artist details.
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<RecentTrack>>- All fetched tracks in the date range (normal format).
§Examples
// Get all tracks from January 2024
let start = Utc.ymd(2024, 1, 1).and_hms(0, 0, 0).timestamp();
let end = Utc.ymd(2024, 2, 1).and_hms(0, 0, 0).timestamp();
let tracks = handler.get_user_recent_tracks_between(start, end, false).await?;
// Get all tracks from last week with extended info
let one_week_ago = (Utc::now() - Duration::days(7)).timestamp();
let now = Utc::now().timestamp();
let tracks = handler.get_user_recent_tracks_between(one_week_ago, now, true).await?;Sourcepub async fn get_user_recent_tracks_between_extended(
&self,
from: i64,
to: i64,
) -> Result<Vec<RecentTrackExtended>>
👎Deprecated since 2.0.0: Use RecentTracksClient from the api module instead
pub async fn get_user_recent_tracks_between_extended( &self, from: i64, to: i64, ) -> Result<Vec<RecentTrackExtended>>
RecentTracksClient from the api module insteadGet all recent tracks for a user between two dates with extended information.
Convenience method for fetching all tracks with extended information within a specific time range. This always fetches unlimited tracks (all tracks in the range) with extended data.
§Arguments
from- Start timestamp (Unix timestamp in seconds) - tracks from this time onwards.to- End timestamp (Unix timestamp in seconds) - tracks up until this time.
§Errors
Returns an error if the API request fails.
§Returns
Result<Vec<RecentTrackExtended>>- All fetched tracks in the date range with extended information.
§Examples
// Get all tracks from January 2024 with extended info
let start = Utc.ymd(2024, 1, 1).and_hms(0, 0, 0).timestamp();
let end = Utc.ymd(2024, 2, 1).and_hms(0, 0, 0).timestamp();
let tracks = handler.get_user_recent_tracks_between_extended(start, end).await?;Sourcepub async fn get_user_loved_tracks_since(
&self,
timestamp: u32,
limit: impl Into<TrackLimit>,
) -> Result<Vec<LovedTrack>>
pub async fn get_user_loved_tracks_since( &self, timestamp: u32, limit: impl Into<TrackLimit>, ) -> Result<Vec<LovedTrack>>
Get loved tracks for a user since a given timestamp.
§Arguments
timestamp- The timestamp to fetch tracks since.limit- The number of tracks to fetch. If None, fetch all tracks.
§Errors
FileError- If there was an error reading or writing the fileInvalidUtf8- If the file path is not valid UTF-8
§Returns
Vec<LovedTrack>- The fetched tracks.
Sourcepub async fn update_tracks_file<T: DeserializeOwned + Serialize + Timestamped>(
&self,
file_path: &Path,
) -> Result<String>
pub async fn update_tracks_file<T: DeserializeOwned + Serialize + Timestamped>( &self, file_path: &Path, ) -> Result<String>
Update a tracks file with new tracks.
§Arguments
file_path- Path to the file to update.fetch_since- Function to fetch tracks since a given timestamp.
§Errors
FileError- If there was an error reading or writing the file
§Panics
- If the file path is not valid UTF-8
§Returns
Result<String, Box<dyn std::error::Error>>- The filename of the updated file.
Sourcepub async fn export_recent_play_counts(
&self,
limit: impl Into<TrackLimit>,
) -> Result<String>
pub async fn export_recent_play_counts( &self, limit: impl Into<TrackLimit>, ) -> Result<String>
Export play counts for the last X songs with additional track information
§Arguments
limit- Number of recent tracks to analyzefile_path- Path to the file to save the play counts to
§Errors
FileError- If there was an error reading or writing the file
§Returns
Result<String>- Path to the saved JSON file containing play counts
Sourcepub async fn update_recent_play_counts(
&self,
limit: impl Into<TrackLimit>,
file_path: &str,
) -> Result<String>
pub async fn update_recent_play_counts( &self, limit: impl Into<TrackLimit>, file_path: &str, ) -> Result<String>
Update or create a file with play counts for the last X songs with additional track information
§Arguments
limit- Number of recent tracks to analyzefile_path- Path to the file to update/create
§Errors
LastFmError::Api- If the API returns an errorLastFmError::Io- If there is an error reading or writing the file
§Returns
Result<String>- Path to the updated/created JSON file containing play counts
Sourcepub async fn is_currently_playing(&self) -> Result<Option<RecentTrack>>
pub async fn is_currently_playing(&self) -> Result<Option<RecentTrack>>
Sourcepub async fn update_currently_listening(
&self,
file_path: &str,
) -> Result<Option<RecentTrack>>
pub async fn update_currently_listening( &self, file_path: &str, ) -> Result<Option<RecentTrack>>
Update a file with the currently playing track information
§Arguments
file_path- Path to the file to update
§Errors
LastFmError::Api- If the API returns an errorLastFmError::Io- If there is an error reading or writing the fileLastFmError::Parse- If there is an error parsing the JSON
§Returns
Result<Option<RecentTrack>>- The currently playing track if any
Trait Implementations§
Source§impl Clone for LastFMHandler
impl Clone for LastFMHandler
Source§fn clone(&self) -> LastFMHandler
fn clone(&self) -> LastFMHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more