X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/a9925ebffe713307d6bedecd670df1490aa206c8..aed70facf3a26e27b1a96b04cad8139de600e42f:/src/catalogue/models/book.py diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index f002158a3..85cfd63b9 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -414,6 +414,21 @@ class Book(models.Model): has_daisy_file.short_description = 'DAISY' has_daisy_file.boolean = True + def has_sync_file(self): + return self.has_media("sync") + + def get_sync(self): + with self.get_media('sync').first().file.open('r') as f: + sync = f.read().split('\n') + offset = float(sync[0]) + items = [] + for line in sync[1:]: + if not line: + continue + start, end, elid = line.split() + items.append([elid, float(start) + offset]) + return json.dumps(items) + def has_audio_epub_file(self): return self.has_media("audio.epub")