commit 62ba058fad473fb02b83e82619cdb92885a1379a
parent 4ebef8b76c10a03109be25637d00378bb9ed78fa
Author: egor-achkasov <eaachkasov@gmail.com>
Date: Fri, 8 May 2026 20:36:30 +0000
Redownload partially downloaded wiles on resume instead of skipping
Diffstat:
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/lib/lib.rs b/src/lib/lib.rs
@@ -25,9 +25,14 @@ pub fn run(config: config::Config, tx: std::sync::mpsc::Sender<Event>) -> Result
std::fs::create_dir_all(&config.output_dir)?;
for post in posts {
tx.send(Event::DownloadPostStarted(post.name.clone())).ok();
- if config.resume && config.output_dir.join(&post.filename).exists() {
- tx.send(Event::DownloadPostSkipped(post.name.clone())).ok();
- continue;
+ if config.resume {
+ let local_path = config.output_dir.join(&post.filename);
+ if let Ok(meta) = std::fs::metadata(&local_path) {
+ if post.content_length().map_or(false, |remote| meta.len() == remote) {
+ tx.send(Event::DownloadPostSkipped(post.name.clone())).ok();
+ continue;
+ }
+ }
}
match post.download(&config.output_dir) {
Ok(()) => tx.send(Event::DownloadPostFinished(post.name.clone())).ok(),
diff --git a/src/lib/post.rs b/src/lib/post.rs
@@ -31,6 +31,22 @@ impl Post {
Ok(Post { name, filename, streaming_url })
}
+ pub fn content_length(&self) -> Option<u64> {
+ ureq::head(&self.streaming_url)
+ .header("Referer", "https://odysee.com/")
+ .header("Origin", "https://odysee.com")
+ .call()
+ .ok()
+ .and_then(|r| {
+ r.headers()
+ .get("content-length")?
+ .to_str()
+ .ok()?
+ .parse()
+ .ok()
+ })
+ }
+
pub fn download(&self, dir: &std::path::Path) -> Result<(), Error> {
let path = dir.join(&self.filename);
let mut response = ureq::get(&self.streaming_url)