Formatting

This commit is contained in:
Connor Johnstone
2026-03-18 15:37:02 -04:00
parent 3d01fa85c9
commit 0b336789da
5 changed files with 103 additions and 46 deletions
+53 -24
View File
@@ -55,7 +55,7 @@ impl fmt::Display for LibrarySummary {
writeln!(f, " Wanted: {}", self.wanted)?;
writeln!(f, " Available: {}", self.available)?;
writeln!(f, " Downloaded: {}", self.downloaded)?;
write!(f, " Owned: {}", self.owned)
write!(f, " Owned: {}", self.owned)
}
}
@@ -84,11 +84,12 @@ pub async fn add_artist(
.search_artist(&resolved_name, 1)
.await
.map_err(|e| WatchError::Other(format!("artist search failed: {e}")))?;
results
.into_iter()
.next()
.map(|a| a.mbid)
.ok_or_else(|| WatchError::Other(format!("artist '{}' not found on MusicBrainz", resolved_name)))?
results.into_iter().next().map(|a| a.mbid).ok_or_else(|| {
WatchError::Other(format!(
"artist '{}' not found on MusicBrainz",
resolved_name
))
})?
}
};
@@ -117,7 +118,14 @@ pub async fn add_artist(
};
for track in &tracks {
match add_track_inner(conn, &resolved_name, &track.title, Some(&track.recording_mbid)).await {
match add_track_inner(
conn,
&resolved_name,
&track.title,
Some(&track.recording_mbid),
)
.await
{
Ok(true) => summary.tracks_added += 1,
Ok(false) => summary.tracks_already_owned += 1,
Err(e) => {
@@ -153,11 +161,12 @@ pub async fn add_album(
.search_release(&resolved_artist, &resolved_album)
.await
.map_err(|e| WatchError::Other(format!("album search failed: {e}")))?;
results
.into_iter()
.next()
.map(|r| r.mbid)
.ok_or_else(|| WatchError::Other(format!("album '{}' not found on MusicBrainz", resolved_album)))?
results.into_iter().next().map(|r| r.mbid).ok_or_else(|| {
WatchError::Other(format!(
"album '{}' not found on MusicBrainz",
resolved_album
))
})?
}
};
@@ -171,7 +180,14 @@ pub async fn add_album(
let mut summary = AddSummary::default();
for track in &tracks {
match add_track_inner(conn, &resolved_artist, &track.title, Some(&track.recording_mbid)).await {
match add_track_inner(
conn,
&resolved_artist,
&track.title,
Some(&track.recording_mbid),
)
.await
{
Ok(true) => summary.tracks_added += 1,
Ok(false) => summary.tracks_already_owned += 1,
Err(e) => {
@@ -269,9 +285,8 @@ async fn resolve_artist_info(
return Ok((n.to_string(), mbid.map(String::from)));
}
let mbid = mbid.ok_or_else(|| {
WatchError::Other("either a name or --mbid is required".into())
})?;
let mbid =
mbid.ok_or_else(|| WatchError::Other("either a name or --mbid is required".into()))?;
// Search for artist by MBID to get the name
let results = provider
@@ -282,7 +297,10 @@ async fn resolve_artist_info(
if let Some(artist) = results.into_iter().next() {
Ok((artist.name, Some(mbid.to_string())))
} else {
Ok((format!("Artist [{}]", &mbid[..8.min(mbid.len())]), Some(mbid.to_string())))
Ok((
format!("Artist [{}]", &mbid[..8.min(mbid.len())]),
Some(mbid.to_string()),
))
}
}
@@ -297,7 +315,11 @@ async fn resolve_album_info(
album_name.filter(|s| !s.is_empty()),
artist_name.filter(|s| !s.is_empty()),
) {
return Ok((album.to_string(), artist.to_string(), mbid.map(String::from)));
return Ok((
album.to_string(),
artist.to_string(),
mbid.map(String::from),
));
}
let mbid = mbid.ok_or_else(|| {
@@ -317,7 +339,9 @@ async fn resolve_album_info(
.unwrap_or_else(|| release.artist.clone());
Ok((album, artist, Some(mbid.to_string())))
} else {
Err(WatchError::Other(format!("no release found for MBID {mbid}")))
Err(WatchError::Other(format!(
"no release found for MBID {mbid}"
)))
}
}
@@ -335,9 +359,8 @@ async fn resolve_track_info(
return Ok((t.to_string(), a.to_string(), mbid.map(String::from)));
}
let mbid = mbid.ok_or_else(|| {
WatchError::Other("either artist+title or --mbid is required".into())
})?;
let mbid =
mbid.ok_or_else(|| WatchError::Other("either artist+title or --mbid is required".into()))?;
let details = provider
.get_recording(mbid)
@@ -345,8 +368,14 @@ async fn resolve_track_info(
.map_err(|e| WatchError::Other(format!("MusicBrainz lookup failed: {e}")))?;
Ok((
title.filter(|s| !s.is_empty()).map(String::from).unwrap_or(details.title),
artist_name.filter(|s| !s.is_empty()).map(String::from).unwrap_or(details.artist),
title
.filter(|s| !s.is_empty())
.map(String::from)
.unwrap_or(details.title),
artist_name
.filter(|s| !s.is_empty())
.map(String::from)
.unwrap_or(details.artist),
Some(mbid.to_string()),
))
}