Fixes: Buchende-Position → Start von vorn (EOF-Idle-Bug: 'nichts abspielbar'), lokale Covers über Asset-URI, Test-Env-Races entfernt

This commit is contained in:
2026-11-06 21:10:17 +01:00
parent 51ad41ec34
commit 0e43e37cc3
4 changed files with 38 additions and 29 deletions

View File

@ -255,13 +255,19 @@ pub fn local_books() -> Vec<Book> {
.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(),

View File

@ -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::<Vec<_>>());
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]

View File

@ -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);
}