Crude relink, pin dep, FLAC support (?)

This commit is contained in:
grufkork 2024-09-08 23:05:21 +02:00
parent ec66b5ad91
commit d98a84e1d0
5 changed files with 39 additions and 27 deletions

16
Cargo.lock generated
View file

@ -1858,7 +1858,7 @@ dependencies = [
[[package]]
name = "librespot"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"data-encoding",
"env_logger",
@ -1884,7 +1884,7 @@ dependencies = [
[[package]]
name = "librespot-audio"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"aes",
"byteorder",
@ -1906,7 +1906,7 @@ dependencies = [
[[package]]
name = "librespot-connect"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"form_urlencoded",
"futures-util",
@ -1926,7 +1926,7 @@ dependencies = [
[[package]]
name = "librespot-core"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"aes",
"base64 0.22.1",
@ -1979,7 +1979,7 @@ dependencies = [
[[package]]
name = "librespot-discovery"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"aes",
"base64 0.22.1",
@ -2006,7 +2006,7 @@ dependencies = [
[[package]]
name = "librespot-metadata"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"async-trait",
"byteorder",
@ -2024,7 +2024,7 @@ dependencies = [
[[package]]
name = "librespot-playback"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"byteorder",
"cpal",
@ -2047,7 +2047,7 @@ dependencies = [
[[package]]
name = "librespot-protocol"
version = "0.5.0-dev"
source = "git+https://github.com/librespot-org/librespot#f6473319f6309b2702a20ff5371763c48e129676"
source = "git+https://github.com/librespot-org/librespot?rev=f647331#f6473319f6309b2702a20ff5371763c48e129676"
dependencies = [
"protobuf",
"protobuf-codegen",

View file

@ -30,7 +30,7 @@ reqwest = "0"
colored = "2"
lame = "0"
aspotify = "0"
librespot = { git = "https://github.com/librespot-org/librespot" }
librespot = { git = "https://github.com/librespot-org/librespot", rev = "f647331" }
async-std = { version = "1", features = ["attributes", "tokio1"] }
serde_json = "1"
async-stream = "0"

View file

@ -201,6 +201,7 @@ async fn communication_thread(
}
/// Spotify downloader
pub struct DownloaderInternal {
spotify: Spotify,
pub tx: Sender<DownloaderMessage>,
@ -485,21 +486,24 @@ impl DownloaderInternal {
Ok(())
}
async fn find_alternative(session: &Session, track: Track) -> Result<Track, SpotifyError> {
let librespot::metadata::track::Tracks(ids) = track.alternatives;
for alt in ids {
let t = Track::get(session, &alt).await.unwrap(); // TODO ?
let librespot::metadata::availability::Availabilities(avalabilities) = t.availability;
for a in avalabilities {
// TODO: figure out if available
for id in ids {
let t = Track::get(session, &id).await?;
if !Self::track_has_alternatives(&t) {
return Ok(t);
}
}
Err(SpotifyError::Unavailable)
}
fn track_has_alternatives(track: &Track) -> bool {
let librespot::metadata::track::Tracks(alts) = &track.alternatives;
!alts.is_empty()
}
/// Download track by id
async fn download_track(
session: &Session,
@ -513,9 +517,15 @@ impl DownloaderInternal {
let mut track = Track::get(session, &id).await?;
// Fallback if unavailable
/*if !track.available {
track = DownloaderInternal::find_alternative(session, track).await?;
}*/ //TODO
if Self::track_has_alternatives(&track) {
track = Self::find_alternative(session, track).await?;
}
// if !track.available {
// track = DownloaderInternal::find_alternative(session, track).await?;
// } //TODO
// Quality fallback
let mut quality = config.quality;
@ -689,6 +699,7 @@ pub enum AudioFormat {
Aac,
Mp3,
Mp4,
Flac,
Unknown,
}
@ -700,6 +711,7 @@ impl AudioFormat {
AudioFormat::Aac => "m4a",
AudioFormat::Mp3 => "mp3",
AudioFormat::Mp4 => "mp4",
AudioFormat::Flac => "flac",
AudioFormat::Unknown => "",
}
.to_string()
@ -719,7 +731,7 @@ impl From<FileFormat> for AudioFormat {
FileFormat::MP3_160_ENC => Self::Mp3,
FileFormat::AAC_24 => Self::Aac,
FileFormat::AAC_48 => Self::Aac,
FileFormat::FLAC_FLAC => Self::Unknown
FileFormat::FLAC_FLAC => Self::Flac
}
}
}

View file

@ -68,6 +68,12 @@ impl From<librespot::core::mercury::MercuryError> for SpotifyError {
}
}
impl From<librespot::core::error::Error> for SpotifyError {
fn from(e: librespot::core::error::Error) -> Self {
SpotifyError::Error(e.to_string())
}
}
impl From<librespot::core::session::SessionError> for SpotifyError {
fn from(e: librespot::core::session::SessionError) -> Self {
match e {

View file

@ -27,12 +27,6 @@ async fn main() {
start().await;
}
impl From<librespot::core::error::Error> for SpotifyError {
fn from(e: librespot::core::error::Error) -> Self {
SpotifyError::Error(e.to_string())
}
}
#[cfg(windows)]
#[tokio::main]
async fn main() {