Added the playlist generator

This commit is contained in:
Connor Johnstone
2026-03-20 18:09:47 -04:00
parent 9d6c0e31c1
commit ea6a6410f3
17 changed files with 962 additions and 116 deletions

View File

@@ -193,8 +193,12 @@ async fn get_cached_album_tracks(
let release_mbid = if let Some(rid) = first_release_id {
rid.to_string()
} else {
// Browse releases for this release group
resolve_release_from_group(rg_id).await?
// Browse releases for this release group (through shared rate limiter)
state
.mb_client
.resolve_release_from_group(rg_id)
.await
.map_err(|e| ApiError::Internal(format!("MB error for group {rg_id}: {e}")))?
};
let mb_tracks = state
@@ -228,37 +232,6 @@ async fn get_cached_album_tracks(
Ok(cached)
}
/// Given a release-group MBID, find the first release MBID.
async fn resolve_release_from_group(release_group_mbid: &str) -> Result<String, ApiError> {
tokio::time::sleep(std::time::Duration::from_millis(1100)).await;
let client = reqwest::Client::builder()
.user_agent("Shanty/0.1.0 (shanty-music-app)")
.build()
.map_err(|e| ApiError::Internal(e.to_string()))?;
let url = format!(
"https://musicbrainz.org/ws/2/release?release-group={release_group_mbid}&fmt=json&limit=1"
);
let resp: serde_json::Value = client
.get(&url)
.send()
.await
.map_err(|e| ApiError::Internal(e.to_string()))?
.json()
.await
.map_err(|e| ApiError::Internal(e.to_string()))?;
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(|| ApiError::NotFound(format!("no releases for group {release_group_mbid}")))
}
#[derive(Deserialize)]
pub struct ArtistFullParams {
#[serde(default)]