From: Radek Czajka Date: Thu, 21 Jan 2021 11:51:20 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.mdrn.pl:2223/audio X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/c20c52d415f7cebb44fb06721bd5f6860c0616ee?hp=-c Merge branch 'master' of ssh://git.mdrn.pl:2223/audio --- c20c52d415f7cebb44fb06721bd5f6860c0616ee diff --combined src/archive/models.py index 11917b8,b15bec2..03cd816 --- a/src/archive/models.py +++ b/src/archive/models.py @@@ -1,3 -1,4 +1,4 @@@ + import io import json import os.path @@@ -27,6 -28,7 +28,7 @@@ class Project(models.Model) name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa") sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy") description = models.TextField(blank=True, verbose_name="Opis") + youtube = models.ForeignKey('youtube.YouTube', models.PROTECT) class Meta: verbose_name = _("project") @@@ -63,7 -65,6 +65,7 @@@ class Audiobook(models.Model) source_file = models.FileField(upload_to=source_upload_to, max_length=255, verbose_name=_('source file'), editable=False) source_sha1 = models.CharField(max_length=40, editable=False) + duration = models.FloatField(null=True, editable=False) title = models.CharField(max_length=255, verbose_name=_('title')) part_name = models.CharField(max_length=255, verbose_name=_('part name'), help_text=_('eg. chapter in a novel'), @@@ -82,7 -83,7 +84,7 @@@ encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by')) date = models.CharField(max_length=255, verbose_name=_('date')) project = models.ForeignKey(Project, models.PROTECT, verbose_name=_('project')) - slug = models.SlugField(max_length=120, help_text=_('WL catalogue slug of the book.')) + slug = models.SlugField(max_length=120, blank=True, help_text=_('WL catalogue slug of the book.')) translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator')) modified = models.DateTimeField(null=True, editable=False) license = models.ForeignKey(License, models.PROTECT, null=True, blank=True, verbose_name=_('license')) @@@ -223,5 -224,26 +225,26 @@@ @cached_property def book(self): - apidata = requests.get(f'https://wolnelektury.pl/api/books/{self.slug}/').json() + if self.slug: + apidata = requests.get(f'https://wolnelektury.pl/api/books/{self.slug}/').json() + else: + return {} return apidata + + @property + def document(self): + from librarian.document import WLDocument, parser + from lxml import etree + + xml_url = self.book.get('xml', None) + if xml_url is None: + return None + + return WLDocument( + etree.parse( + io.BytesIO( + requests.get(xml_url).content + ) + ,parser = parser + ) + )