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

@ -14,8 +14,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="52900e09-9584-4b6c-95ff-fbd4ed5d8b2c" name="Changes" comment="Add interface package. Start adding auth stuff for refreshing tokens."> <list default="true" id="52900e09-9584-4b6c-95ff-fbd4ed5d8b2c" name="Changes" comment="Add interface package. Start adding auth stuff for refreshing tokens.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/daemon/update_playlists.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/daemon/update_playlists.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/daemon/update_playlists.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/daemon/update_playlists.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/listenbrainz.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/listenbrainz.rs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -165,7 +167,9 @@
<workItem from="1716043707662" duration="542000" /> <workItem from="1716043707662" duration="542000" />
<workItem from="1716046070333" duration="1484000" /> <workItem from="1716046070333" duration="1484000" />
<workItem from="1716640392358" duration="367000" /> <workItem from="1716640392358" duration="367000" />
<workItem from="1716642009543" duration="1073000" /> <workItem from="1716642009543" duration="1546000" />
<workItem from="1716650511971" duration="14000" />
<workItem from="1723834879628" duration="4009000" />
</task> </task>
<task id="LOCAL-00001" summary="Structure"> <task id="LOCAL-00001" summary="Structure">
<created>1692008860369</created> <created>1692008860369</created>

2
Cargo.lock generated
View File

@ -1456,7 +1456,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]] [[package]]
name = "playlistd" name = "playlistd"
version = "0.2.3" version = "0.2.4"
dependencies = [ dependencies = [
"chrono", "chrono",
"config", "config",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "playlistd" name = "playlistd"
version = "0.2.3" version = "0.2.4"
edition = "2021" edition = "2021"
authors = ["Jude Southworth (judesouthworth@pm.me)"] authors = ["Jude Southworth (judesouthworth@pm.me)"]
license = "AGPL-3.0 only" license = "AGPL-3.0 only"

View File

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

View File

@ -71,18 +71,10 @@ struct RecordingsResponse {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct RecordingsPayload { 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>, pub recordings: Vec<RecordingsEntry>,
} }
#[derive(Deserialize)] #[derive(Deserialize, Clone)]
pub struct Artist { pub struct Artist {
pub artist_credit_name: String, pub artist_credit_name: String,
} }
@ -92,9 +84,7 @@ pub struct RecordingsEntry {
pub track_name: String, pub track_name: String,
pub release_name: String, pub release_name: String,
pub artist_name: String, pub artist_name: String,
pub artists: Vec<Artist>, pub artists: Option<Vec<Artist>>,
pub recording_mbid: String,
pub release_mbid: String,
} }
pub async fn recordings( pub async fn recordings(