Skip to content

Commit d7ec924

Browse files
committed
fix(tidal): skipping songs with null album
1 parent c317519 commit d7ec924

8 files changed

Lines changed: 28 additions & 19 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sync_dis_boi"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
edition = "2024"
55
license-file = "LICENSE.txt"
66
description = "a music streaming platform synchronization tool"

src/spotify/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct SpotifyEmptyResponse {}
77
#[allow(dead_code)]
88
pub struct SpotifyUserResponse {
99
pub country: String,
10-
pub display_name: String,
10+
pub display_name: Option<String>,
1111
pub email: String,
1212
}
1313

@@ -52,7 +52,7 @@ pub struct SpotifyPlaylistResponse {
5252
pub id: String,
5353
pub name: String,
5454
#[allow(dead_code)]
55-
pub public: bool,
55+
pub public: Option<bool>,
5656
}
5757

5858
#[derive(Deserialize, Debug)]

src/spotify/response.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ impl TryInto<Song> for SpotifySongResponse {
106106
let artists = self
107107
.artists
108108
.into_iter()
109-
.filter(|a| a.id.is_some())
110-
.map(|i| Artist {
111-
id: Some(i.id.unwrap()),
112-
name: i.name,
109+
.filter_map(|i| {
110+
Some(Artist {
111+
id: Some(i.id?),
112+
name: i.name,
113+
})
113114
})
114115
.collect();
115116
let album = Album {

src/tidal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl TidalApi {
8888
config.debug,
8989
)
9090
.await?;
91-
let country_code = me_res.data.attributes.country.unwrap();
91+
let country_code = me_res.data.attributes.country.unwrap_or("US".into());
9292

9393
Ok(Self {
9494
client,

src/tidal/model.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct TidalOAuthDeviceRes {
1919
#[serde(rename_all = "camelCase")]
2020
pub struct TidalPageResponse<T> {
2121
pub items: Vec<T>,
22+
#[allow(dead_code)]
2223
pub offset: usize,
2324
pub total_number_of_items: usize,
2425
}
@@ -41,10 +42,10 @@ pub struct TidalSongItemResponse {
4142
pub struct TidalSongResponse {
4243
pub id: usize,
4344
pub title: String,
44-
pub isrc: String,
45+
pub isrc: Option<String>,
4546
pub duration: usize,
4647
pub artists: Vec<TidalArtistResponse>,
47-
pub album: TidalAlbumResponse,
48+
pub album: Option<TidalAlbumResponse>,
4849
}
4950

5051
#[derive(Deserialize, Debug)]

src/tidal/response.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ impl TryInto<Songs> for TidalSearchResponse {
5656
match track.try_into() {
5757
Ok(s) => res.push(s),
5858
Err(e) => {
59-
error!("failed to parse song in response, skipping it: {}", e);
59+
error!(
60+
"failed to parse song in response, skipping it. error log: `{}`",
61+
e
62+
);
6063
continue;
6164
}
6265
}
@@ -81,9 +84,12 @@ impl TryInto<Playlist> for TidalPlaylistResponse {
8184
impl TryInto<Song> for TidalSongResponse {
8285
type Error = Error;
8386
fn try_into(self) -> Result<Song, Self::Error> {
87+
let Some(album) = self.album else {
88+
return Err(eyre!("{}: missing song album data", self.title));
89+
};
8490
let album = Album {
85-
id: Some(self.album.id.to_string()),
86-
name: self.album.title,
91+
id: Some(album.id.to_string()),
92+
name: album.title,
8793
};
8894
let artists = self
8995
.artists
@@ -98,7 +104,7 @@ impl TryInto<Song> for TidalSongResponse {
98104
source: MusicApiType::Tidal,
99105
id: self.id.to_string(),
100106
sid: None,
101-
isrc: Some(self.isrc.to_uppercase()),
107+
isrc: self.isrc.map(|i| i.to_uppercase()),
102108
name: self.title,
103109
album: Some(album),
104110
artists,
@@ -175,7 +181,9 @@ fn media_data_to_song(data: TidalMediaData, included: &[TidalMediaData]) -> Resu
175181
if album_rel.len() != 1 {
176182
return Err(eyre!("invalid song with multiple albums"));
177183
}
178-
let album_rel = album_rel.first().unwrap();
184+
let Some(album_rel) = album_rel.first() else {
185+
return Err(eyre!("missing song album data"));
186+
};
179187
let album_data = included
180188
.iter()
181189
.find(|i| i.id == album_rel.id)
@@ -217,7 +225,7 @@ fn media_data_to_song(data: TidalMediaData, included: &[TidalMediaData]) -> Resu
217225
source: MusicApiType::Tidal,
218226
id: data.id,
219227
sid: None,
220-
isrc: Some(data.attributes.isrc.ok_or_eyre("missing song isrc")?),
228+
isrc: data.attributes.isrc.map(|i| i.to_uppercase()),
221229
name: data.attributes.title.ok_or_eyre("missing song title")?,
222230
album,
223231
artists,

src/yt_music/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ impl YtMusicApi {
188188
.proxy(reqwest::Proxy::all(proxy)?)
189189
.danger_accept_invalid_certs(true)
190190
}
191-
192-
let client = client.build().unwrap();
191+
let client = client.build()?;
193192

194193
Ok(YtMusicApi { client, config })
195194
}

0 commit comments

Comments
 (0)