[library] Listening: the audiobook position as an event (latest write wins), replayed by the export

This commit is contained in:
2026-11-17 21:27:26 +01:00
parent 5f2cd1b7c1
commit bb0a63a173
6 changed files with 48 additions and 6 deletions
+6
View File
@@ -180,6 +180,12 @@ pub enum Op {
list: String,
upto: u32,
},
/// Day 4: where an audiobook file is, to the millisecond (the latest write wins, so any device resumes there).
AudioPosition {
book: String,
sha256: String,
ms: u64,
},
/// Day 3: a book file is an edition in another language (`None`: it is the book's own language again).
Edition {
book: String,
+3
View File
@@ -129,6 +129,9 @@ pub fn ops_from(lib: &Library) -> Vec<Op> {
if b.to_read {
ops.push(set(Field::ToRead, json!(true)));
}
if let Some((sha, ms)) = &b.audio_position {
ops.push(Op::AudioPosition { book: id.clone(), sha256: sha.clone(), ms: *ms });
}
if b.familiar {
ops.push(set(Field::Familiar, json!(true)));
}
+13
View File
@@ -212,6 +212,9 @@ pub struct Book {
pub position: Option<Position>,
/// The most recent position, when it is behind the furthest: "Jump back to page X?".
pub last_position: Option<Position>,
/// Day 4: the audiobook's place: (file sha256, milliseconds).
#[serde(default)]
pub audio_position: Option<(String, u64)>,
/// Day 3: read before in the reader's own language.
#[serde(default)]
pub familiar: bool,
@@ -242,6 +245,7 @@ impl Book {
last_position: None,
familiar: false,
editions: BTreeMap::new(),
audio_position: None,
}
}
@@ -773,6 +777,15 @@ impl Library {
self.bands.insert(lang.clone(), Band { list: list.clone(), upto: (*upto).min(1_000_000) });
}
}
Op::AudioPosition { book, sha256, ms } => {
let ok =
sha256.len() == 64 && sha256.bytes().all(|b| b.is_ascii_hexdigit()) && *ms < 1_000 * 3_600 * 1_000;
if let Some(b) = self.book_mut(book)
&& ok
{
b.audio_position = Some((sha256.to_ascii_lowercase(), *ms));
}
}
Op::Edition { book, sha256, language } => {
let ok = sha256.len() == 64 && sha256.bytes().all(|b| b.is_ascii_hexdigit());
if let Some(b) = self.book_mut(book)