Compare commits

...
Sign in to create a new pull request.

2 commits

3 changed files with 50 additions and 13 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "spotifyio-downloader"
description = "CLI for downloading music from Spotify"
version = "0.5.0"
version = "0.5.1"
edition.workspace = true
authors.workspace = true
license.workspace = true

View file

@ -1114,18 +1114,55 @@ impl SpotifyDownloader {
if let Some(item) = item {
return Ok(Some(item.subdir_path));
} else {
let row = sqlx::query!("select path from tracks where id=$1", id_str)
.fetch_optional(&self.i.pool)
.await?;
if let Some(subdir_path) = row.and_then(|r| r.path) {
let audio_path = path!(self.i.base_dir / subdir_path);
if audio_path.is_file() {
return Ok(Some(path!(subdir_path)));
let row = sqlx::query!(
"select album, album_id, path from tracks where id=$1",
id_str
)
.fetch_optional(&self.i.pool)
.await?;
if let Some(row) = row {
if let Some(subdir_path) = row.path {
let audio_path = path!(self.i.base_dir / subdir_path);
if audio_path.is_file() {
return Ok(Some(path!(subdir_path)));
} else {
if let (Some(album), Some(album_id)) =
(row.album, row.album_id)
{
// Try new path (with album ID)
let pb = PathBuf::from(subdir_path);
let mut cmp = pb.components().collect::<Vec<_>>();
if cmp.len() > 1 {
let album_dirname = better_filenamify(
&album,
Some(&format!(" [{}]", &album_id[..8])),
);
cmp[1] = std::path::Component::Normal(
std::ffi::OsStr::new(&album_dirname),
);
let subdir_path =
cmp.into_iter().collect::<PathBuf>();
let audio_path =
path!(self.i.base_dir / subdir_path);
if audio_path.is_file() {
tracing::info!(
"Audio file moved, new path: {}",
subdir_path.to_string_lossy()
);
return Ok(Some(subdir_path));
}
}
}
tracing::error!(
"[{id}] audio file not found: {}",
audio_path.to_string_lossy()
);
success.store(false, Ordering::SeqCst);
}
} else {
tracing::error!(
"[{id}] audio file not found: {}",
audio_path.to_string_lossy()
);
tracing::error!("[{id}] audio file path not found in db");
success.store(false, Ordering::SeqCst);
}
} else {

View file

@ -62,7 +62,7 @@ rand = "0.8"
rsa = "0.9.2"
httparse = "1.7"
base64 = "0.22"
oauth2 = { version = "5.0.0-rc.1", default-features = false, features = [
oauth2 = { version = "5.0.0", default-features = false, features = [
"reqwest",
], optional = true }
pin-project-lite = "0.2"