Added the playlist generator
CI / check (push) Successful in 1m12s
CI / docker (push) Successful in 2m1s

This commit is contained in:
Connor Johnstone
2026-03-20 18:09:47 -04:00
parent 4008b4d838
commit 6f73bb87ce
19 changed files with 1526 additions and 21 deletions
+29 -4
View File
@@ -21,14 +21,21 @@ pub struct MusicBrainzFetcher {
impl MusicBrainzFetcher {
pub fn new() -> DataResult<Self> {
Self::with_limiter(RateLimiter::new(RATE_LIMIT))
}
/// Create a fetcher that shares a rate limiter with other MB clients.
pub fn with_limiter(limiter: RateLimiter) -> DataResult<Self> {
let client = reqwest::Client::builder()
.user_agent(USER_AGENT)
.timeout(Duration::from_secs(30))
.build()?;
Ok(Self {
client,
limiter: RateLimiter::new(RATE_LIMIT),
})
Ok(Self { client, limiter })
}
/// Get a clone of the rate limiter for sharing with other MB clients.
pub fn limiter(&self) -> RateLimiter {
self.limiter.clone()
}
async fn get_json<T: serde::de::DeserializeOwned>(&self, url: &str) -> DataResult<T> {
@@ -84,6 +91,24 @@ impl MusicBrainzFetcher {
urls,
})
}
/// Resolve a release-group MBID to a release MBID (first release in the group).
pub async fn resolve_release_from_group(&self, release_group_mbid: &str) -> DataResult<String> {
let url = format!("{BASE_URL}/release?release-group={release_group_mbid}&fmt=json&limit=1");
let resp: serde_json::Value = self.get_json(&url).await?;
resp.get("releases")
.and_then(|r| r.as_array())
.and_then(|arr| arr.first())
.and_then(|r| r.get("id"))
.and_then(|id| id.as_str())
.map(String::from)
.ok_or_else(|| {
DataError::Other(format!(
"no releases for release-group {release_group_mbid}"
))
})
}
}
impl MetadataFetcher for MusicBrainzFetcher {