Skip to main content

LastFmBaseClient

Trait LastFmBaseClient 

Source
pub trait LastFmBaseClient {
Show 17 methods // Required methods fn get_artists_page<'life0, 'async_trait>( &'life0 self, page: u32, ) -> Pin<Box<dyn Future<Output = Result<ArtistPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_artist_tracks_page<'life0, 'life1, 'async_trait>( &'life0 self, artist: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_artist_albums_page<'life0, 'life1, 'async_trait>( &'life0 self, artist: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<AlbumPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_album_tracks_page<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, album_name: &'life1 str, artist_name: &'life2 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn get_recent_tracks_page<'life0, 'async_trait>( &'life0 self, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn search_tracks_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn search_albums_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<AlbumPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn search_artists_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<ArtistPage>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn username(&self) -> String; fn get_session(&self) -> LastFmEditSession; fn subscribe(&self) -> ClientEventReceiver; fn latest_event(&self) -> Option<ClientEvent>; fn validate_session<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn find_recent_scrobble_for_track<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, track_name: &'life1 str, artist_name: &'life2 str, max_pages: u32, ) -> Pin<Box<dyn Future<Output = Result<Option<Track>>> + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; // Provided methods fn cancel(&self) { ... } fn reset_cancel(&self) { ... } fn is_cancelled(&self) -> bool { ... }
}
Expand description

Low-level trait for individual Last.fm page fetches, search, and session management.

This trait abstracts single-request operations: fetching a page of data, performing a search query, and managing session/cancellation state. It serves as the foundation that higher-level traits like LastFmEditClient build upon.

§Mocking Support

When the mock feature is enabled, this crate provides MockLastFmBaseClient that implements this trait using the mockall library.

Required Methods§

Source

fn get_artists_page<'life0, 'async_trait>( &'life0 self, page: u32, ) -> Pin<Box<dyn Future<Output = Result<ArtistPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a page of artists from the user’s library.

Source

fn get_artist_tracks_page<'life0, 'life1, 'async_trait>( &'life0 self, artist: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a page of tracks from the user’s library for the specified artist.

Source

fn get_artist_albums_page<'life0, 'life1, 'async_trait>( &'life0 self, artist: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<AlbumPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a page of albums from the user’s library for the specified artist.

Source

fn get_album_tracks_page<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, album_name: &'life1 str, artist_name: &'life2 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get a page of tracks from a specific album in the user’s library.

Source

fn get_recent_tracks_page<'life0, 'async_trait>( &'life0 self, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a page of tracks from the user’s recent listening history.

Source

fn search_tracks_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<TrackPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single page of track search results from the user’s library.

This performs a search using Last.fm’s library search functionality, returning one page of tracks that match the provided query string. For iterator-based access, use LastFmEditClient::search_tracks instead.

§Arguments
  • query - The search query (e.g., “remaster”, “live”, artist name, etc.)
  • page - The page number to retrieve (1-based)
§Returns

Returns a TrackPage containing the search results with pagination information.

Source

fn search_albums_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<AlbumPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single page of album search results from the user’s library.

This performs a search using Last.fm’s library search functionality, returning one page of albums that match the provided query string. For iterator-based access, use LastFmEditClient::search_albums instead.

§Arguments
  • query - The search query (e.g., “remaster”, “deluxe”, artist name, etc.)
  • page - The page number to retrieve (1-based)
§Returns

Returns an AlbumPage containing the search results with pagination information.

Source

fn search_artists_page<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, page: u32, ) -> Pin<Box<dyn Future<Output = Result<ArtistPage>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single page of artist search results from the user’s library.

This performs a search using Last.fm’s library search functionality, returning one page of artists that match the provided query string. For iterator-based access, use LastFmEditClient::search_artists instead.

§Arguments
  • query - The search query (e.g., artist name, partial match, etc.)
  • page - The page number to retrieve (1-based)
§Returns

Returns an ArtistPage containing the search results with pagination information.

Source

fn username(&self) -> String

Get the currently authenticated username.

Source

fn get_session(&self) -> LastFmEditSession

Extract the current session state for persistence.

This allows you to save the authentication state and restore it later without requiring the user to log in again.

§Returns

Returns a LastFmEditSession that can be serialized and saved.

Source

fn subscribe(&self) -> ClientEventReceiver

Subscribe to internal client events.

Returns a broadcast receiver that can be used to listen to events like rate limiting. Multiple subscribers can listen simultaneously.

§Example
use lastfm_edit::{LastFmEditClientImpl, LastFmEditSession, ClientEvent};

let http_client = http_client::native::NativeClient::new();
let test_session = LastFmEditSession::new("test".to_string(), vec!["sessionid=.test123".to_string()], Some("csrf".to_string()), "https://www.last.fm".to_string());
let client = LastFmEditClientImpl::from_session(Box::new(http_client), test_session);
let mut events = client.subscribe();

// Listen for events in a background task
tokio::spawn(async move {
    while let Ok(event) = events.recv().await {
        match event {
            ClientEvent::RequestStarted { request } => {
                println!("Request started: {}", request.short_description());
            }
            ClientEvent::RequestCompleted { request, status_code, duration_ms } => {
                println!("Request completed: {} - {} ({} ms)", request.short_description(), status_code, duration_ms);
            }
            ClientEvent::RateLimited { delay_seconds, .. } => {
                println!("Rate limited! Waiting {} seconds", delay_seconds);
            }
            ClientEvent::RateLimitEnded { total_rate_limit_duration_seconds, .. } => {
                println!("Rate limiting ended after {} seconds", total_rate_limit_duration_seconds);
            }
            ClientEvent::Delaying { delay_ms, reason, .. } => {
                println!("Delaying ({reason:?}) for {delay_ms}ms");
            }
            ClientEvent::EditAttempted { edit, success, .. } => {
                println!("Edit attempt: '{}' -> '{}' - {}",
                         edit.track_name_original, edit.track_name,
                         if success { "Success" } else { "Failed" });
            }
            _ => {}
        }
    }
});
Source

fn latest_event(&self) -> Option<ClientEvent>

Get the latest client event without subscribing to future events.

This returns the most recent event that occurred, or None if no events have occurred yet. Unlike subscribe(), this provides instant access to the current state without waiting.

§Example
use lastfm_edit::{LastFmEditClientImpl, LastFmEditSession, ClientEvent};

let http_client = http_client::native::NativeClient::new();
let test_session = LastFmEditSession::new("test".to_string(), vec!["sessionid=.test123".to_string()], Some("csrf".to_string()), "https://www.last.fm".to_string());
let client = LastFmEditClientImpl::from_session(Box::new(http_client), test_session);

if let Some(ClientEvent::RateLimited { delay_seconds, .. }) = client.latest_event() {
    println!("Currently rate limited for {} seconds", delay_seconds);
}
Source

fn validate_session<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Validate if the current session is still working.

This method makes a test request to a protected Last.fm settings page to verify that the current session is still valid. If the session has expired or become invalid, Last.fm will redirect to the login page.

This is useful for checking session validity before attempting operations that require authentication, especially after loading a previously saved session.

§Returns

Returns true if the session is valid and can be used for authenticated operations, false if the session is invalid or expired.

Source

fn find_recent_scrobble_for_track<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, track_name: &'life1 str, artist_name: &'life2 str, max_pages: u32, ) -> Pin<Box<dyn Future<Output = Result<Option<Track>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Find the most recent scrobble for a specific track.

Provided Methods§

Source

fn cancel(&self)

Request cooperative cancellation of ongoing operations (best-effort).

Implementations should interrupt internal waits (retry backoff, operational delays) and return LastFmError::Io(ErrorKind::Interrupted) where appropriate.

Source

fn reset_cancel(&self)

Clear the cancellation request so future operations can run again.

Source

fn is_cancelled(&self) -> bool

Whether cancellation has been requested.

Implementors§