--- /dev/null
+# Generated by Django 3.0.4 on 2020-05-24 01:39
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archive', '0008_remove_audiobook_youtube_file'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='License',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('uri', models.CharField(max_length=255, unique=True)),
+ ('name', models.CharField(max_length=255)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='audiobook',
+ name='license',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='archive.License', verbose_name='license'),
+ ),
+ ]
--- /dev/null
+# Generated by Django 3.0.4 on 2020-05-24 01:40
+
+import json
+from django.db import migrations
+
+
+def populate_license(apps, schema_editor):
+ License = apps.get_model('archive.License')
+ Audiobook = apps.get_model('archive.Audiobook')
+ licenses = {}
+ for a in Audiobook.objects.all():
+ if a.mp3_tags:
+ tags = json.loads(a.mp3_tags)
+ uri = tags.get('license')
+ if not uri:
+ continue
+ if uri not in licenses:
+ licenses[uri], created = License.objects.get_or_create(uri=uri, defaults={"name": "?"})
+ a.license = licenses[uri]
+ a.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archive', '0009_auto_20200524_0139'),
+ ]
+
+ operations = [
+ migrations.RunPython(
+ populate_license,
+ migrations.RunPython.noop
+ )
+ ]
from django_pglocks import advisory_lock
import requests
from archive.constants import status
-from archive.settings import FILES_SAVE_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT
+from archive.settings import FILES_SAVE_PATH, ADVERT, ORGANIZATION, PROJECT
from archive.utils import OverwriteStorage, sha1_file
+class License(models.Model):
+ uri = models.CharField(max_length=255, unique=True)
+ name = models.CharField(max_length=255)
+
+
class Project(models.Model):
""" an audiobook project, needed for specyfing sponsors """
url = models.URLField(max_length=255, verbose_name=_('book url'))
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'))
# publishing process
mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
title += ' (tłum. %s)' % self.translator
copyright = "%s %s. Licensed to the public under %s verify at %s" % (
- self.date, ORGANIZATION, LICENSE, self.url)
+ self.date, ORGANIZATION, self.license.uri, self.url)
comment = "\n".join((
self.project.get_description(),
'date': self.date,
'genre': 'Speech',
'language': 'pol',
- 'license': LICENSE,
+ 'license': self.license.uri,
'organization': ORGANIZATION,
'title': title,
'project': self.project.name,
PROJECT = 'Wolne Lektury'
-LICENSE = getattr(
- settings,
- 'ARCHIVE_LICENSE',
- 'http://artlibre.org/licence/lal/pl/'
-)
-
-LICENSE_NAME = getattr(
- settings, 'ARCHIVE_LICENSE_NAME',
- 'Licencja Wolnej Sztuki 1.3'
-)
-
-
try:
ORGANIZATION = settings.ARCHIVE_ORGANIZATION
except AttributeError:
from django.utils.translation import gettext_lazy as _
from django.template import Template, Context
from apiclient import youtube_call
-from archive.settings import LICENSE, LICENSE_NAME
from .utils import (
concat_audio,
concat_videos,
from .thumbnail import create_thumbnail
+YOUTUBE_TITLE_LIMIT = 100
+
+
class YouTube(models.Model):
title_template = models.CharField(max_length=1024, blank=True)
description_template = models.TextField(blank=True)
def get_context(self, audiobook):
return Context(dict(
audiobook=audiobook,
- LICENSE=LICENSE,
- LICENSE_NAME=LICENSE_NAME,
))
def get_description(self, audiobook):
return Template(self.description_template).render(self.get_context(audiobook))
def get_title(self, audiobook):
- return Template(self.title_template).render(self.get_context(audiobook))
+ return Template(self.title_template).render(self.get_context(audiobook))[:YOUTUBE_TITLE_LIMIT]
def get_data(self, audiobook):
return dict(