mirror of
https://gitverse.ru/ot/DownOnSpot
synced 2025-12-20 10:24:16 +00:00
Fix available tracks returned as unavailable
This commit is contained in:
parent
bf0b8b2bad
commit
514e88537f
1 changed files with 13 additions and 8 deletions
|
|
@ -472,6 +472,16 @@ impl DownloaderInternal {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_alternative(session: &Session, track : Track) -> Result<Track, SpotifyError> {
|
||||
for alt in track.alternatives {
|
||||
let t = Track::get(&session, alt).await?;
|
||||
if t.available {
|
||||
return Ok(t);
|
||||
}
|
||||
}
|
||||
return Err(SpotifyError::Unavailable);
|
||||
}
|
||||
|
||||
/// Download track by id
|
||||
async fn download_track(
|
||||
session: &Session,
|
||||
|
|
@ -482,16 +492,11 @@ impl DownloaderInternal {
|
|||
job_id: i64,
|
||||
) -> Result<(PathBuf, AudioFormat), SpotifyError> {
|
||||
let id = SpotifyId::from_base62(id)?;
|
||||
let track = Track::get(session, id).await?;
|
||||
let mut track = Track::get(session, id).await?;
|
||||
|
||||
// Fallback if unavailable
|
||||
if !track.available {
|
||||
for alt in track.alternatives {
|
||||
let t = Track::get(session, alt).await?;
|
||||
if t.available {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Err(SpotifyError::Unavailable);
|
||||
track = DownloaderInternal::find_alternative(session, track).await?;
|
||||
}
|
||||
// Quality fallback
|
||||
let mut quality = config.quality;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue