Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb0a63a173 |
Generated
+5
-5
@@ -327,7 +327,7 @@ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "liber-audio"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -337,7 +337,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "liber-format"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chardetng",
|
||||
@@ -357,7 +357,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "liber-habit"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"liber-library",
|
||||
"proptest",
|
||||
@@ -367,7 +367,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "liber-lang"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
@@ -379,7 +379,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "liber-library"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
dependencies = [
|
||||
"csv",
|
||||
"encoding_rs",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
||||
members = ["crates/liber-format", "crates/liber-library", "crates/liber-habit", "crates/liber-lang", "crates/liber-audio"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
edition = "2024"
|
||||
license = "MPL-2.0"
|
||||
repository = "https://gitea.marek-novak.cz/mnovak/Liber-public"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -94,3 +94,23 @@ fn familiar_and_editions_on_a_book_and_through_an_export() {
|
||||
evs2.push(ev("7", "x", &mut c, 7, Op::Edition { book: "b".into(), sha256: sha, language: None }));
|
||||
assert!(Library::from_events(&evs2).books["b"].editions.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_audiobook_position_is_the_latest_write_and_survives_an_export() {
|
||||
let (mut pc, mut dc) = (Clock::default(), Clock::default());
|
||||
let sha = "cd".repeat(32);
|
||||
let pos = |ms: u64| Op::AudioPosition { book: "b".into(), sha256: sha.clone(), ms };
|
||||
let evs = vec![
|
||||
ev("0", "desk", &mut dc, 1, Op::BookAdd { book: "b".into(), info: info(1), restore: false }),
|
||||
ev("1", "desk", &mut dc, 1_000, pos(61_000)),
|
||||
ev("2", "phone", &mut pc, 2_000, pos(95_250)),
|
||||
ev("3", "phone", &mut pc, 3_000, Op::AudioPosition { book: "b".into(), sha256: "nope".into(), ms: 5 }),
|
||||
];
|
||||
let mut rev = evs.clone();
|
||||
rev.reverse();
|
||||
let lib = Library::from_events(&evs);
|
||||
assert_eq!(lib, Library::from_events(&rev));
|
||||
assert_eq!(lib.books["b"].audio_position, Some((sha.clone(), 95_250)), "to the millisecond, the latest write");
|
||||
let back = Library::from_events(&events_from(&lib, "restore", 10));
|
||||
assert_eq!(back.books.values().next().and_then(|b| b.audio_position.clone()), Some((sha, 95_250)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user