Tastatursteuerung (SPACE Play/Pause, ←/→ ±30 s, ESC schließt Overlays) + Klappentext-Cache in books/<asin>/details.json

This commit is contained in:
2026-11-07 11:55:05 +01:00
parent 235b81cf24
commit 677793e9a7
2 changed files with 40 additions and 1 deletions

View File

@ -363,6 +363,7 @@ pub fn set_alter_note(asin: &str, note: Option<String>) -> Result<(), String> {
/// Einzeldetails per Audible-API (Beschreibung u. a.) — on demand.
#[derive(Debug, Clone, Serialize)]
#[derive(serde::Deserialize)]
pub struct BookExtra {
pub description: String,
pub language: String,
@ -371,6 +372,21 @@ pub struct BookExtra {
}
pub fn fetch_details(asin: &str) -> Result<BookExtra, String> {
// Cache im Buchordner (falls lokal vorhanden): einmalig holen, danach offline nutzbar
let cache = books_dir().join(asin).join("details.json");
if let Ok(txt) = fs::read_to_string(&cache) {
if let Ok(x) = serde_json::from_str::<BookExtra>(&txt) {
return Ok(x);
}
}
let fetched = fetch_details_online(asin)?;
if cache.parent().is_some_and(|p| p.is_dir()) {
let _ = fs::write(&cache, serde_json::to_vec(&fetched).unwrap_or_default());
}
Ok(fetched)
}
fn fetch_details_online(asin: &str) -> Result<BookExtra, String> {
let bin = audible_binary().ok_or_else(|| {
"audible-cli nicht gefunden — pipx install audible-cli".to_string()
})?;