Reduce error proneness

This commit is contained in:
jude
2024-08-16 21:27:49 +01:00
parent eb30bc11d9
commit bca4cd4eb1
5 changed files with 19 additions and 19 deletions

View File

@ -2,7 +2,7 @@ use crate::listenbrainz::StatsRange;
use crate::models::TrackedPlaylist;
use crate::subsonic::Subsonic;
use crate::{listenbrainz, CONFIG};
use log::error;
use log::{error, warn};
use sqlx::postgres::PgPool;
use std::time::Duration;
use thiserror::Error;
@ -44,8 +44,9 @@ pub async fn update_playlists_daemon(
match records_res {
Ok(records) => {
for record in records {
// todo handle me
update_playlist(media_client.clone(), record).await.unwrap();
if let Err(e) = update_playlist(media_client.clone(), record).await {
warn!("Could not update playlist: {:?}", e);
}
}
}
@ -74,11 +75,16 @@ async fn update_playlist(
let mut tracks = vec![];
for recording in recordings {
if recording.artists.clone().map_or(true, |o| o.is_empty()) {
continue;
}
let search_results = media_client
.as_ref()
.song_search(format!(
"{} {}",
recording.track_name, recording.artists[0].artist_credit_name
recording.track_name,
recording.artists.unwrap_or(vec![])[0].artist_credit_name
))
.await?;

View File

@ -71,18 +71,10 @@ struct RecordingsResponse {
#[derive(Deserialize)]
pub struct RecordingsPayload {
count: u64,
from_ts: u64,
to_ts: u64,
last_updated: u64,
total_recording_count: u64,
user_id: String,
offset: u64,
range: String,
pub recordings: Vec<RecordingsEntry>,
}
#[derive(Deserialize)]
#[derive(Deserialize, Clone)]
pub struct Artist {
pub artist_credit_name: String,
}
@ -92,9 +84,7 @@ pub struct RecordingsEntry {
pub track_name: String,
pub release_name: String,
pub artist_name: String,
pub artists: Vec<Artist>,
pub recording_mbid: String,
pub release_mbid: String,
pub artists: Option<Vec<Artist>>,
}
pub async fn recordings(