fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
37cb52d
)
Use actual sync for bookmarks.
author
Radek Czajka
<rczajka@rczajka.pl>
Wed, 10 Dec 2025 12:50:45 +0000
(13:50 +0100)
committer
Radek Czajka
<rczajka@rczajka.pl>
Wed, 10 Dec 2025 12:50:45 +0000
(13:50 +0100)
requirements/requirements.txt
patch
|
blob
|
history
src/bookmarks/models.py
patch
|
blob
|
history
src/catalogue/api/views.py
patch
|
blob
|
history
src/catalogue/models/book.py
patch
|
blob
|
history
src/catalogue/templates/catalogue/book_text.html
patch
|
blob
|
history
diff --git
a/requirements/requirements.txt
b/requirements/requirements.txt
index
396184d
..
5f7496e
100644
(file)
--- a/
requirements/requirements.txt
+++ b/
requirements/requirements.txt
@@
-42,7
+42,7
@@
mutagen==1.47
sorl-thumbnail==12.10.0
# home-brewed & dependencies
sorl-thumbnail==12.10.0
# home-brewed & dependencies
-librarian==2
4.5.10
+librarian==2
5.12
# celery tasks
celery[redis]==5.4.0
# celery tasks
celery[redis]==5.4.0
diff --git
a/src/bookmarks/models.py
b/src/bookmarks/models.py
index
8747ffb
..
7325e2d
100644
(file)
--- a/
src/bookmarks/models.py
+++ b/
src/bookmarks/models.py
@@
-34,16
+34,13
@@
class Bookmark(Syncable, models.Model):
audio_l = self.book.get_audio_length()
except:
audio_l = 60
audio_l = self.book.get_audio_length()
except:
audio_l = 60
+
if self.anchor:
self.mode = 'text'
if self.anchor:
self.mode = 'text'
- if audio_l:
- self.audio_timestamp = audio_l * .4
+ self.audio_timestamp = self.book.sync_elid(self.anchor)
if self.audio_timestamp:
self.mode = 'audio'
if self.audio_timestamp:
self.mode = 'audio'
- if self.audio_timestamp > audio_l:
- self.audio_timestamp = audio_l
- if audio_l:
- self.anchor = 'f20'
+ self.anchor = self.book.sync_ts(self.audio_timestamp)
return super().save(*args, **kwargs)
@classmethod
return super().save(*args, **kwargs)
@classmethod
diff --git
a/src/catalogue/api/views.py
b/src/catalogue/api/views.py
index
7457b6f
..
0f3a95f
100644
(file)
--- a/
src/catalogue/api/views.py
+++ b/
src/catalogue/api/views.py
@@
-259,7
+259,7
@@
class BookSyncView(RetrieveAPIView):
instance = self.get_object()
return Response([
{"id": i, "timestamp": ts}
instance = self.get_object()
return Response([
{"id": i, "timestamp": ts}
- for (i, ts) in
json.loads(instance.get_sync()
)
+ for (i, ts) in
instance.get_sync(
)
])
])
diff --git
a/src/catalogue/models/book.py
b/src/catalogue/models/book.py
index
10ba5b2
..
ee3aecb
100644
(file)
--- a/
src/catalogue/models/book.py
+++ b/
src/catalogue/models/book.py
@@
-471,10
+471,9
@@
class Book(models.Model):
None, ContentFile(sync)
)
None, ContentFile(sync)
)
-
def get_sync(self):
if not self.has_sync_file():
def get_sync(self):
if not self.has_sync_file():
- return
'[]'
+ return
[]
with self.get_media('sync').first().file.open('r') as f:
sync = f.read().split('\n')
offset = float(sync[0])
with self.get_media('sync').first().file.open('r') as f:
sync = f.read().split('\n')
offset = float(sync[0])
@@
-484,8
+483,22
@@
class Book(models.Model):
continue
start, end, elid = line.split()
items.append([elid, float(start) + offset])
continue
start, end, elid = line.split()
items.append([elid, float(start) + offset])
- return json.dumps(items)
-
+ return items
+
+ def sync_ts(self, ts):
+ elid = None
+ for cur_id, t in self.get_sync():
+ if ts >= t:
+ elid = cur_id
+ else:
+ break
+ return elid
+
+ def sync_elid(self, elid):
+ for cur_id, t in self.get_sync():
+ if cur_id == elid:
+ return t
+
def has_audio_epub_file(self):
return self.has_media("audio.epub")
def has_audio_epub_file(self):
return self.has_media("audio.epub")
diff --git
a/src/catalogue/templates/catalogue/book_text.html
b/src/catalogue/templates/catalogue/book_text.html
index
18e4bcc
..
e06f0f2
100644
(file)
--- a/
src/catalogue/templates/catalogue/book_text.html
+++ b/
src/catalogue/templates/catalogue/book_text.html
@@
-322,9
+322,7
@@
<div id="player-bar">
{% include 'catalogue/snippets/jplayer_reader.html' %}
</div>
<div id="player-bar">
{% include 'catalogue/snippets/jplayer_reader.html' %}
</div>
- <script type="application/json" id="smil">
- {{ book.get_sync|safe }}
- </script>
+ {{ book.get_sync|json_script:"smil" }}
{% endif %}
{% endif %}