sorl-thumbnail==12.10.0
# home-brewed & dependencies
-librarian==24.5.10
+librarian==25.12
# celery tasks
celery[redis]==5.4.0
audio_l = self.book.get_audio_length()
except:
audio_l = 60
+
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 > 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
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()
])
None, ContentFile(sync)
)
-
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])
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")
<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 %}