requests-oauthlib==1.3.0
PyYAML==5.3.1
Pillow==7.2.0
+librarian==1.9
+py3-aeneas==1.1.0
--- /dev/null
+# Generated by Django 3.1.2 on 2020-10-22 14:14
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('youtube', '0015_auto_20201022_1414'),
+ ('archive', '0018_auto_20200703_1718'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='project',
+ name='youtube',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='youtube.youtube'),
+ ),
+ migrations.AlterField(
+ model_name='audiobook',
+ name='mp3_status',
+ field=models.SmallIntegerField(choices=[(5, 'Queued'), (10, 'Waiting'), (20, 'Encoding'), (30, 'Tagging'), (40, 'Converting audio'), (50, 'Converting video'), (60, 'Assembling audio'), (70, 'Assembling video'), (80, 'Joining audio and video'), (100, 'Sending'), (110, 'Setting thumbnail')], editable=False, null=True),
+ ),
+ migrations.AlterField(
+ model_name='audiobook',
+ name='ogg_status',
+ field=models.SmallIntegerField(choices=[(5, 'Queued'), (10, 'Waiting'), (20, 'Encoding'), (30, 'Tagging'), (40, 'Converting audio'), (50, 'Converting video'), (60, 'Assembling audio'), (70, 'Assembling video'), (80, 'Joining audio and video'), (100, 'Sending'), (110, 'Setting thumbnail')], editable=False, null=True),
+ ),
+ migrations.AlterField(
+ model_name='audiobook',
+ name='slug',
+ field=models.SlugField(blank=True, help_text='WL catalogue slug of the book.', max_length=120),
+ ),
+ migrations.AlterField(
+ model_name='audiobook',
+ name='youtube_status',
+ field=models.SmallIntegerField(choices=[(5, 'Queued'), (10, 'Waiting'), (20, 'Encoding'), (30, 'Tagging'), (40, 'Converting audio'), (50, 'Converting video'), (60, 'Assembling audio'), (70, 'Assembling video'), (80, 'Joining audio and video'), (100, 'Sending'), (110, 'Setting thumbnail')], editable=False, null=True),
+ ),
+ ]
--- /dev/null
+# Generated by Django 3.1.2 on 2020-10-22 15:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('youtube', '0017_auto_20201022_1535'),
+ ('archive', '0019_auto_20201022_1414'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='project',
+ name='youtube',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='youtube.youtube'),
+ ),
+ ]
+import io
import json
import os.path
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")
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'))
@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
+ )
+ )
def run(self, uid, aid, publish=True):
aid = int(aid)
audiobook = Audiobook.objects.get(id=aid)
+ self.audiobook = audiobook
self.set_status(aid, status.ENCODING)
if uid:
--- /dev/null
+# Generated by Django 3.1.2 on 2020-10-22 14:14
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('youtube', '0014_auto_20200706_1219'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='thumbnailtemplate',
+ name='youtube',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='youtube.youtube'),
+ ),
+ migrations.AddField(
+ model_name='youtube',
+ name='name',
+ field=models.CharField(default='Wolne Lektury', max_length=255),
+ preserve_default=False,
+ ),
+ ]
--- /dev/null
+# Generated by Django 3.1.2 on 2020-10-22 14:15
+
+from django.db import migrations
+
+
+def populate_youtube_relations(apps, schema_editor):
+ YouTube = apps.get_model('youtube', 'YouTube')
+ ThumbnailTemplate = apps.get_model('youtube', 'ThumbnailTemplate')
+ Project = apps.get_model('archive', 'Project')
+
+ try:
+ yt = YouTube.objects.first()
+ except YouTube.DoesNotExist:
+ yt = YouTube.objects.create(name='default')
+
+ Project.objects.filter(youtube=None).update(youtube=yt)
+ ThumbnailTemplate.objects.filter(youtube=None).update(youtube=yt)
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('youtube', '0015_auto_20201022_1414'),
+ ('archive', '0019_auto_20201022_1414'),
+ ]
+
+ operations = [
+ migrations.RunPython(
+ populate_youtube_relations,
+ migrations.RunPython.noop
+ )
+ ]
--- /dev/null
+# Generated by Django 3.1.2 on 2020-10-22 15:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('youtube', '0016_populate_youtube_relations'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='thumbnailtemplate',
+ name='youtube',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='youtube.youtube'),
+ ),
+ ]
class YouTube(models.Model):
+ name = models.CharField(max_length=255)
title_template = models.CharField(max_length=1024, blank=True)
description_template = models.TextField(blank=True)
category = models.IntegerField(null=True, blank=True, choices=[
verbose_name = _("YouTube configuration")
verbose_name_plural = _("YouTube configurations")
+ def __str__(self):
+ return self.name
+
def get_context(self, audiobook):
return Context(dict(
audiobook=audiobook,
class ThumbnailTemplate(models.Model):
+ youtube = models.ForeignKey(YouTube, models.CASCADE)
order = models.SmallIntegerField()
is_active = models.BooleanField()
background = models.FileField(upload_to='youtube/thumbnail')
prefix = 'youtube'
def encode(self, in_paths, out_path):
- YouTube.objects.first().prepare_file(in_paths, out_path)
+ self.audiobook.project.youtube.prepare_file(in_paths, out_path)
def set_tags(self, audiobook, filename):
pass
os.unlink(file_name)
def put(self, user, audiobook, filename):
- YouTube.objects.first().publish(audiobook, filename)
+ audiobook.project.youtube.publish(audiobook, filename)
def get_source_file_paths(self, audiobook):
if not audiobook.youtube_volume:
def thumbnail(request, aid, thumbnail_id=None):
audiobook = get_object_or_404(Audiobook, id=aid)
if thumbnail_id is None:
- yt = models.YouTube.objects.first()
+ yt = audiobook.project.youtube
buf = yt.prepare_thumbnail(audiobook)
else:
template = get_object_or_404(models.ThumbnailTemplate, id=thumbnail_id)
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
- yt = models.YouTube.objects.first()
+ yt = ctx['object'].project.youtube
ctx['data'] = yt.get_data(ctx['object'])
ctx['title'] = yt.get_title(ctx['object'])
ctx['description'] = yt.get_description(ctx['object'])
model = Audiobook
def post(self, request, pk):
- yt = models.YouTube.objects.first()
- yt.update_data(self.get_object())
+ obj = self.get_object()
+ yt = obj.project.youtube
+ yt.update_data(obj)
return redirect(reverse('file', args=[pk]))
model = Audiobook
def post(self, request, pk):
- yt = models.YouTube.objects.first()
- yt.update_thumbnail(self.get_object())
+ obj = self.get_object()
+ yt = obj.project.youtube
+ yt.update_thumbnail(obj)
return redirect(reverse('file', args=[pk]))