T-012: Bibliothek komplett — Cover-Raster, Suche (Titel/Autor/Sprecher), Sortierung (5 Optionen), Status-Chips (lokal/fertig), Fortschrittsbalken

This commit is contained in:
2026-11-06 19:40:47 +01:00
parent 7b63719e41
commit 5ef2eb0145
5 changed files with 245 additions and 46 deletions

View File

@ -30,6 +30,11 @@ pub struct Book {
pub percent_complete: f64,
#[serde(default)]
pub is_finished: bool,
#[serde(default)]
pub date_added: String,
/// lokal vorhanden (book.m4b im Datenverzeichnis) — vom Backend gesetzt
#[serde(default, skip_deserializing)]
pub local: bool,
}
/// Zugriffsschicht auf Audible — hinter diesem Trait kapseln, damit
@ -95,6 +100,18 @@ fn default_auth_dir() -> PathBuf {
.unwrap_or_else(|| PathBuf::from("."))
}
/// Lokale Bücherablage (spec): ~/.local/share/hoerwerk/books/<ASIN>/book.m4b,
/// per HOERWERK_BOOKS_DIR überschreibbar.
fn books_dir() -> PathBuf {
env::var("HOERWERK_BOOKS_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| {
home_dir()
.map(|h| h.join(".local/share/hoerwerk/books"))
.unwrap_or_else(|| PathBuf::from("books"))
})
}
impl AudibleClient for CliAudibleClient {
fn auth_status(&self) -> Result<AuthStatus, String> {
let mut profiles = Vec::new();
@ -167,7 +184,12 @@ impl AudibleClient for CliAudibleClient {
}
};
let _ = fs::remove_file(&out);
parse_library(&content)
let mut books = parse_library(&content)?;
let dir = books_dir();
for b in &mut books {
b.local = dir.join(&b.asin).join("book.m4b").is_file();
}
Ok(books)
}
}
@ -282,12 +304,14 @@ mod tests {
#[test]
fn parse_library_nimmt_pfelder() {
let json = r#"[{"asin":"B08L4WJMDM","title":"Elfe 2"}]"#;
let json = r#"[{"asin":"B08L4WJMDM","title":"Elfe 2","date_added":"2020-01-01"}]"#;
let books = parse_library(json).unwrap();
assert_eq!(books.len(), 1);
assert_eq!(books[0].asin, "B08L4WJMDM");
assert_eq!(books[0].runtime_length_min, 0);
assert!(!books[0].is_finished);
assert!(!books[0].local);
assert_eq!(books[0].date_added, "2020-01-01");
assert!(parse_library("kaputt").is_err());
}