Files
Main/shanty-data/src/traits.rs
T
Connor Johnstone 31d54651e6
CI / check (push) Successful in 1m30s
CI / docker (push) Successful in 2m7s
Sped up artist enrichment at least somewhat
2026-03-21 15:08:28 -04:00

114 lines
3.5 KiB
Rust

use std::future::Future;
use crate::error::DataResult;
use crate::types::{
ArtistInfo, ArtistSearchResult, DiscographyEntry, LyricsResult, PopularTrack, RecordingDetails,
RecordingMatch, ReleaseGroupEntry, ReleaseMatch, ReleaseTrack, SimilarArtist,
};
/// Trait for metadata lookup backends. MusicBrainz is the default implementation;
/// others (Last.fm, Discogs, etc.) can be added later.
pub trait MetadataFetcher: Send + Sync {
fn search_recording(
&self,
artist: &str,
title: &str,
) -> impl Future<Output = DataResult<Vec<RecordingMatch>>> + Send;
fn search_release(
&self,
artist: &str,
album: &str,
) -> impl Future<Output = DataResult<Vec<ReleaseMatch>>> + Send;
fn get_recording(
&self,
mbid: &str,
) -> impl Future<Output = DataResult<RecordingDetails>> + Send;
fn search_artist(
&self,
query: &str,
limit: u32,
) -> impl Future<Output = DataResult<Vec<ArtistSearchResult>>> + Send;
fn get_artist_releases(
&self,
artist_mbid: &str,
limit: u32,
) -> impl Future<Output = DataResult<Vec<DiscographyEntry>>> + Send;
fn get_release_tracks(
&self,
release_mbid: &str,
) -> impl Future<Output = DataResult<Vec<ReleaseTrack>>> + Send;
/// Get deduplicated release groups (albums, EPs, singles) for an artist.
fn get_artist_release_groups(
&self,
artist_mbid: &str,
) -> impl Future<Output = DataResult<Vec<ReleaseGroupEntry>>> + Send;
/// Resolve a release-group MBID to a concrete release MBID (first release in the group).
fn resolve_release_from_group(
&self,
release_group_mbid: &str,
) -> impl Future<Output = DataResult<String>> + Send;
}
/// Fetches artist image URLs from an external source.
pub trait ArtistImageFetcher: Send + Sync {
/// Thumbnail/profile image for the artist.
fn get_artist_image(
&self,
artist_info: &ArtistInfo,
) -> impl Future<Output = DataResult<Option<String>>> + Send;
/// Wide banner/background image for the artist (e.g., 1920x1080).
/// Returns None by default — providers that don't support banners need not implement this.
fn get_artist_banner(
&self,
artist_info: &ArtistInfo,
) -> impl Future<Output = DataResult<Option<String>>> + Send {
let _ = artist_info;
async { Ok(None) }
}
}
/// Fetches an artist biography from an external source.
pub trait ArtistBioFetcher: Send + Sync {
fn get_artist_bio(
&self,
artist_info: &ArtistInfo,
) -> impl Future<Output = DataResult<Option<String>>> + Send;
}
/// Fetches song lyrics from an external source.
pub trait LyricsFetcher: Send + Sync {
fn get_lyrics(
&self,
artist: &str,
title: &str,
) -> impl Future<Output = DataResult<LyricsResult>> + Send;
}
/// Fetches similar artists and top tracks from an external source (e.g. Last.fm).
pub trait SimilarArtistFetcher: Send + Sync {
fn get_similar_artists(
&self,
artist_name: &str,
mbid: Option<&str>,
) -> impl Future<Output = DataResult<Vec<SimilarArtist>>> + Send;
fn get_top_tracks(
&self,
artist_name: &str,
mbid: Option<&str>,
) -> impl Future<Output = DataResult<Vec<PopularTrack>>> + Send;
}
/// Fetches cover art URLs for releases.
pub trait CoverArtFetcher: Send + Sync {
fn get_cover_art_url(&self, release_id: &str) -> Option<String>;
}