mirror of
https://gitverse.ru/ot/DownOnSpot
synced 2025-12-19 09:54:19 +00:00
feat; skip existing songs before downloading (#40)
This commit is contained in:
parent
811991b609
commit
8e06c9bdf3
2 changed files with 11 additions and 0 deletions
|
|
@ -531,6 +531,13 @@ impl DownloaderInternal {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let path = Path::new(&path).to_owned();
|
let path = Path::new(&path).to_owned();
|
||||||
|
|
||||||
|
// Don't download if we are skipping and the path exists.
|
||||||
|
if config.skip_existing && path.is_file() {
|
||||||
|
return Err(SpotifyError::AlreadyDownloaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let path_clone = path.clone();
|
let path_clone = path.clone();
|
||||||
|
|
||||||
let key = session.audio_key().request(track.id, *file_id).await?;
|
let key = session.audio_key().request(track.id, *file_id).await?;
|
||||||
|
|
@ -861,6 +868,7 @@ pub struct DownloaderConfig {
|
||||||
pub id3v24: bool,
|
pub id3v24: bool,
|
||||||
pub convert_to_mp3: bool,
|
pub convert_to_mp3: bool,
|
||||||
pub separator: String,
|
pub separator: String,
|
||||||
|
pub skip_existing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DownloaderConfig {
|
impl DownloaderConfig {
|
||||||
|
|
@ -874,6 +882,7 @@ impl DownloaderConfig {
|
||||||
id3v24: true,
|
id3v24: true,
|
||||||
convert_to_mp3: false,
|
convert_to_mp3: false,
|
||||||
separator: ", ".to_string(),
|
separator: ", ".to_string(),
|
||||||
|
skip_existing: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ pub enum SpotifyError {
|
||||||
ID3Error(String, String),
|
ID3Error(String, String),
|
||||||
Reqwest(String),
|
Reqwest(String),
|
||||||
InvalidFormat,
|
InvalidFormat,
|
||||||
|
AlreadyDownloaded,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for SpotifyError {}
|
impl std::error::Error for SpotifyError {}
|
||||||
|
|
@ -42,6 +43,7 @@ impl fmt::Display for SpotifyError {
|
||||||
SpotifyError::ID3Error(k, e) => write!(f, "ID3 Error: {} {}", k, e),
|
SpotifyError::ID3Error(k, e) => write!(f, "ID3 Error: {} {}", k, e),
|
||||||
SpotifyError::Reqwest(e) => write!(f, "Reqwest Error: {}", e),
|
SpotifyError::Reqwest(e) => write!(f, "Reqwest Error: {}", e),
|
||||||
SpotifyError::InvalidFormat => write!(f, "Invalid Format!"),
|
SpotifyError::InvalidFormat => write!(f, "Invalid Format!"),
|
||||||
|
SpotifyError::AlreadyDownloaded => write!(f, "Already Downloaded")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue