From: Radek Czajka Date: Tue, 27 Sep 2022 23:31:25 +0000 (+0200) Subject: Epub+mo support X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e1688333f557a60400fed09b4b087f4c8dddb432?hp=1610eb2c8c981232e53cbc58039fd3c00736a652 Epub+mo support --- diff --git a/src/catalogue/migrations/0037_auto_20220928_0124.py b/src/catalogue/migrations/0037_auto_20220928_0124.py new file mode 100644 index 000000000..4445eeff9 --- /dev/null +++ b/src/catalogue/migrations/0037_auto_20220928_0124.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2022-09-27 23:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0036_book_toc'), + ] + + operations = [ + migrations.AlterField( + model_name='bookmedia', + name='type', + field=models.CharField(choices=[('mp3', 'MP3 file'), ('ogg', 'Ogg Vorbis file'), ('daisy', 'DAISY file'), ('audio.epub', 'EPUB+audio file')], db_index=True, max_length=20, verbose_name='type'), + ), + ] diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index b624abcad..7d923ea3c 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -403,6 +403,9 @@ class Book(models.Model): def get_daisy(self): return self.get_media("daisy") + def get_audio_epub(self): + return self.get_media("audio.epub") + def media_url(self, format_): media = self.get_media(format_) if media: @@ -454,10 +457,17 @@ class Book(models.Model): has_daisy_file.short_description = 'DAISY' has_daisy_file.boolean = True + def has_audio_epub_file(self): + return self.has_media("audio.epub") + @property def media_daisy(self): return self.get_media('daisy') + @property + def media_audio_epub(self): + return self.get_media('audio.epub') + def get_audiobooks(self): ogg_files = {} for m in self.media.filter(type='ogg').order_by().iterator(): diff --git a/src/catalogue/models/bookmedia.py b/src/catalogue/models/bookmedia.py index c08ed1152..702dd01f8 100644 --- a/src/catalogue/models/bookmedia.py +++ b/src/catalogue/models/bookmedia.py @@ -30,6 +30,7 @@ class BookMedia(models.Model): ('mp3', FileFormat(name='MP3', ext='mp3')), ('ogg', FileFormat(name='Ogg Vorbis', ext='ogg')), ('daisy', FileFormat(name='DAISY', ext='daisy.zip')), + ('audio.epub', FileFormat(name='EPUB+audio', ext='audio.epub')), ]) format_choices = [(k, _('%s file' % t.name)) for k, t in formats.items()] diff --git a/src/catalogue/templates/catalogue/2022/book_detail.html b/src/catalogue/templates/catalogue/2022/book_detail.html index ea967becf..a3d50057f 100644 --- a/src/catalogue/templates/catalogue/2022/book_detail.html +++ b/src/catalogue/templates/catalogue/2022/book_detail.html @@ -261,14 +261,16 @@ {% endif %} - {% if book.has_synchro_file %} + {% if book.has_audio_epub_file %}
-

synchrobook

+

EPUB + audiobook

Książka elektroniczna i audiobook w jednym. Wymaga aplikacji obsługującej format.

- synchrobook + {% for epub in book.media_audio_epub %} + EPUB+audio + {% endfor %}
{% endif %} diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index f4f121d80..cddd273e1 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -424,6 +424,9 @@ def download_audio(book, daisy=True, mp3=True): if daisy and book.has_media('daisy'): for dsy in book.get_media('daisy'): links.append("%s" % (dsy.file.url, BookMedia.formats['daisy'].name)) + if daisy and book.has_media('audio.epub'): + for dsy in book.get_media('audio.epub'): + links.append("%s" % (dsy.file.url, BookMedia.formats['audio.epub'].name)) return mark_safe("".join(links))