mirror of
https://gitverse.ru/ot/DownOnSpot
synced 2025-12-20 18:34:17 +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(())
|
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
|
/// Download track by id
|
||||||
async fn download_track(
|
async fn download_track(
|
||||||
session: &Session,
|
session: &Session,
|
||||||
|
|
@ -482,16 +492,11 @@ impl DownloaderInternal {
|
||||||
job_id: i64,
|
job_id: i64,
|
||||||
) -> Result<(PathBuf, AudioFormat), SpotifyError> {
|
) -> Result<(PathBuf, AudioFormat), SpotifyError> {
|
||||||
let id = SpotifyId::from_base62(id)?;
|
let id = SpotifyId::from_base62(id)?;
|
||||||
let track = Track::get(session, id).await?;
|
let mut track = Track::get(session, id).await?;
|
||||||
|
|
||||||
// Fallback if unavailable
|
// Fallback if unavailable
|
||||||
if !track.available {
|
if !track.available {
|
||||||
for alt in track.alternatives {
|
track = DownloaderInternal::find_alternative(session, track).await?;
|
||||||
let t = Track::get(session, alt).await?;
|
|
||||||
if t.available {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Err(SpotifyError::Unavailable);
|
|
||||||
}
|
}
|
||||||
// Quality fallback
|
// Quality fallback
|
||||||
let mut quality = config.quality;
|
let mut quality = config.quality;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue