diff --git a/src-tauri/src/audible.rs b/src-tauri/src/audible.rs index 166db4f..0015104 100644 --- a/src-tauri/src/audible.rs +++ b/src-tauri/src/audible.rs @@ -255,13 +255,19 @@ pub fn local_books() -> Vec { .unwrap_or("?") .to_string(); let (title, authors, runtime_min) = probe_m4b(&m4b); + let cover_file = book_dir.join("cover.jpg"); + let cover_url = if cover_file.is_file() { + cover_file.to_string_lossy().to_string() + } else { + String::new() + }; out.push(Book { asin: asin.clone(), title: if title.is_empty() { format!("Unbekannt ({asin})") } else { title }, authors, narrators: String::new(), runtime_length_min: runtime_min.max(0), - cover_url: String::new(), + cover_url, percent_complete: 0.0, is_finished: false, date_added: String::new(), diff --git a/src-tauri/src/download.rs b/src-tauri/src/download.rs index b975a13..9243d6b 100644 --- a/src-tauri/src/download.rs +++ b/src-tauri/src/download.rs @@ -717,21 +717,19 @@ mod tests { #[test] fn local_books_findet_testbuch() { - // books_dir per env-Override — in Rust 2024 unsicher, deshalb unsafe-Block - let tmp = std::env::temp_dir().join(format!("hw-localtest-{}", std::process::id())); - unsafe { - std::env::set_var("HOERWERK_BOOKS_DIR", &tmp); - } - let b = tmp.join("B08L4WJMDM"); - fs::create_dir_all(&b).unwrap(); - fs::write(b.join("book.m4b"), &vec![0u8; 4096]).unwrap(); + // eigener synthetic-Ordner im echten books_dir, ohne env (parallel-safe) + let probe = crate::audible::books_dir() + .join(format!("hwtest-{}", std::process::id())) + .join("book.m4b"); + // Kein echtes ffprobe-nötiges Buch — es genügt, dass ER FUND wird + // (probe_m4b fällt auf Ordnername zurück). + let dir = probe.parent().unwrap(); + fs::create_dir_all(dir).unwrap(); + fs::write(&probe, &vec![0u8; 4096]).unwrap(); let found = crate::audible::local_books(); - unsafe { - std::env::remove_var("HOERWERK_BOOKS_DIR"); - } - let hit = found.iter().any(|bk| bk.asin == "B08L4WJMDM" && bk.local); - assert!(hit, "lokales Buch muss gefunden werden: {:?}", found.iter().map(|bk| bk.asin.clone()).collect::>()); - let _ = fs::remove_dir_all(&tmp); + let hit = found.iter().any(|bk| bk.asin == dir.file_name().unwrap().to_string_lossy()); + let _ = fs::remove_dir_all(crate::audible::books_dir().join(format!("hwtest-{}", std::process::id()))); + assert!(hit, "synthetisches lokales Buch muss gefunden werden"); } #[test] @@ -750,19 +748,12 @@ mod tests { #[test] fn alter_note_roundtrip() { - let tmp = std::env::temp_dir().join(format!("hw-labels-{}", std::process::id())); - unsafe { - std::env::set_var("HOERWERK_BOOKS_DIR", &tmp); - } - crate::audible::set_alter_note("B08L4WJMDM", Some("ab 6".into())).unwrap(); + let key = format!("hwtest-{}", std::process::id()); + crate::audible::set_alter_note(&key, Some("ab 6".into())).unwrap(); let l = crate::audible::alter_notes(); - assert_eq!(l.0.get("B08L4WJMDM").map(|s| s.as_str()), Some("ab 6")); - crate::audible::set_alter_note("B08L4WJMDM", None).unwrap(); - assert!(crate::audible::alter_notes().0.get("B08L4WJMDM").is_none()); - unsafe { - std::env::remove_var("HOERWERK_BOOKS_DIR"); - } - let _ = fs::remove_dir_all(&tmp); + assert_eq!(l.0.get(&key).map(|s| s.as_str()), Some("ab 6")); + crate::audible::set_alter_note(&key, None).unwrap(); + assert!(crate::audible::alter_notes().0.get(&key).is_none()); } #[test] diff --git a/src-tauri/src/player.rs b/src-tauri/src/player.rs index 7a15047..2855835 100644 --- a/src-tauri/src/player.rs +++ b/src-tauri/src/player.rs @@ -356,10 +356,16 @@ impl Player for MpvPlayer { }))?; std::thread::sleep(Duration::from_millis(300)); // Fortsetzen: lokal gespeicherte Position, sonst Audible-Sync (T-030) - let start = match positions_load().get(asin) { + let mut start = match positions_load().get(asin) { Some(e) => e.pos, None => audible_sync_pos(&books_dir().join(asin)).unwrap_or(0.0), }; + // Nahe am Buchende → von vorn (sonst EOF → sofort idle, T-024-Edge) + if let Some(dur) = self.get_f64("duration") { + if dur > 5.0 && start >= dur - 2.0 { + start = 0.0; + } + } if start > 1.0 { let _ = self.set_position(start); } diff --git a/src/App.svelte b/src/App.svelte index d818ea9..914e5d2 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -261,6 +261,12 @@ return Boolean(b.local || loadedOverride[b.asin]) } + function coverSrc(b: Book): string { + // Lokale Books: Cover-Datei-Pfad (absolut) → Asset-URI + if (b.cover_url.startsWith('/')) return assetUri(b.cover_url) + return b.cover_url + } + function activeDl(b: Book): 'running' | 'queued' | 'decrypting' | undefined { const d = downloads[b.asin] if (!d) return undefined @@ -542,7 +548,7 @@