Added the playlist generator
This commit is contained in:
@@ -116,51 +116,18 @@ async fn get_album(
|
||||
})))
|
||||
}
|
||||
|
||||
/// Given a release-group MBID, find the first release MBID via the MB API.
|
||||
/// Given a release-group MBID, find the first release MBID via the shared MB client.
|
||||
async fn resolve_release_from_group(
|
||||
_state: &web::Data<AppState>,
|
||||
state: &web::Data<AppState>,
|
||||
release_group_mbid: &str,
|
||||
) -> Result<String, ApiError> {
|
||||
// Use the MB client's get_json (it's private, so we go through search)
|
||||
// The approach: search for releases by this release group
|
||||
// MB API: /ws/2/release?release-group={mbid}&fmt=json&limit=1
|
||||
// Since we can't call get_json directly, use the artist_releases approach
|
||||
// to find a release that matches this group.
|
||||
//
|
||||
// Actually, the simplest: the MetadataFetcher trait has get_artist_releases
|
||||
// which returns releases, but we need releases for a release GROUP.
|
||||
// Let's add a direct HTTP call here via reqwest.
|
||||
|
||||
let url = format!(
|
||||
"https://musicbrainz.org/ws/2/release?release-group={release_group_mbid}&fmt=json&limit=1"
|
||||
);
|
||||
|
||||
// Respect rate limiting by going through a small delay
|
||||
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 resp: serde_json::Value = client
|
||||
.get(&url)
|
||||
.send()
|
||||
state
|
||||
.mb_client
|
||||
.resolve_release_from_group(release_group_mbid)
|
||||
.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(|| {
|
||||
.map_err(|e| {
|
||||
ApiError::NotFound(format!(
|
||||
"no releases found for release group {release_group_mbid}"
|
||||
"no releases found for release group {release_group_mbid}: {e}"
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user