X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4157358510703a54cde8f3b0f9814f2cd1c9f40a..9b999d1b69b2f5da8ec2b456240739344cf9e9a9:/src/catalogue/models/book.py diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index fc07fc5f7..85cfd63b9 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -15,7 +15,7 @@ import django.dispatch from django.contrib.contenttypes.fields import GenericRelation from django.template.loader import render_to_string from django.urls import reverse -from django.utils.translation import ugettext_lazy as _, get_language +from django.utils.translation import gettext_lazy as _, get_language from fnpdjango.storage import BofhFileSystemStorage from lxml import html from librarian.cover import WLCover @@ -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") @@ -510,6 +525,7 @@ class Book(models.Model): licenses.add(license) readme = render_to_string('catalogue/audiobook_zip_readme.txt', { 'licenses': licenses, + 'meta': self.wldocument2().meta, }) return create_zip(paths, "%s_%s" % (self.slug, format_), {'informacje.txt': readme})