Altersangaben: Genre-Signal-Chip (Kinder/Jugend aus Audible-Genres) + manuelle Altersnote pro Buch (labels.json, Inline-Edit mit Stift-Button)
This commit is contained in:
@ -32,6 +32,8 @@ pub struct Book {
|
||||
pub is_finished: bool,
|
||||
#[serde(default)]
|
||||
pub date_added: String,
|
||||
#[serde(default)]
|
||||
pub genres: String,
|
||||
/// lokal vorhanden (book.m4b im Datenverzeichnis) — vom Backend gesetzt
|
||||
#[serde(default, skip_deserializing)]
|
||||
pub local: bool,
|
||||
@ -263,6 +265,7 @@ pub fn local_books() -> Vec<Book> {
|
||||
percent_complete: 0.0,
|
||||
is_finished: false,
|
||||
date_added: String::new(),
|
||||
genres: String::new(),
|
||||
local: true,
|
||||
});
|
||||
}
|
||||
@ -306,6 +309,54 @@ fn probe_m4b(m4b: &Path) -> (String, String, i64) {
|
||||
(title, artist, minutes)
|
||||
}
|
||||
|
||||
// Manuelle Altersnotizen (bewertbar pro Buch, lokale JSON-Ablage)
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Labels(pub std::collections::BTreeMap<String, String>);
|
||||
|
||||
fn labels_path() -> PathBuf {
|
||||
books_dir()
|
||||
.parent()
|
||||
.map(|p| p.join("labels.json"))
|
||||
.unwrap_or_else(|| PathBuf::from("labels.json"))
|
||||
}
|
||||
|
||||
pub fn alter_notes() -> Labels {
|
||||
let map: std::collections::BTreeMap<String, String> = fs::read_to_string(labels_path())
|
||||
.ok()
|
||||
.and_then(|txt| serde_json::from_str(&txt).ok())
|
||||
.unwrap_or_default();
|
||||
Labels(map)
|
||||
}
|
||||
|
||||
pub fn set_alter_note(asin: &str, note: Option<String>) -> Result<(), String> {
|
||||
let asin = asin.trim().to_string();
|
||||
if asin.is_empty() {
|
||||
return Err("keine ASIN angegeben".to_string());
|
||||
}
|
||||
let mut l = alter_notes();
|
||||
let note = note.map(|n| n.trim().to_string()).filter(|n| !n.is_empty());
|
||||
match note {
|
||||
Some(n) => {
|
||||
l.0.insert(asin, n);
|
||||
}
|
||||
None => {
|
||||
l.0.remove(&asin);
|
||||
}
|
||||
}
|
||||
if let Some(parent) = labels_path().parent() {
|
||||
fs::create_dir_all(parent).map_err(|e| format!("Notiz-Ordner: {e}"))?;
|
||||
}
|
||||
let path = labels_path();
|
||||
let tmp = path.with_extension("json.tmp");
|
||||
fs::write(&tmp, serde_json::to_vec(&l).unwrap_or_default())
|
||||
.map_err(|e| format!("Notiz schreiben: {e}"))?;
|
||||
fs::rename(&tmp, &path).map_err(|e| format!("Notiz speichern: {e}")
|
||||
)
|
||||
}
|
||||
|
||||
// Manuelle Altersnotizen — lokale JSON-Ablage (siehe labels_path)
|
||||
|
||||
/// Taugt stderr von audible-cli: Warnungen und Passwort-Prompts raus,
|
||||
/// echte Fehlertexte bleiben.
|
||||
pub(crate) fn reduce_noise(s: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user