From: Radek Czajka Date: Tue, 25 Oct 2022 11:41:35 +0000 (+0200) Subject: Remove unused fields, add more project settings. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/201dd39ec21858e2b4e82dc7bed4bf6aea0262cb Remove unused fields, add more project settings. --- diff --git a/src/archive/forms.py b/src/archive/forms.py index 3b68c28..eca8f1a 100644 --- a/src/archive/forms.py +++ b/src/archive/forms.py @@ -15,7 +15,9 @@ from archive.utils import ExistingFile, sha1_file class AudiobookForm(forms.ModelForm): class Meta: model = Audiobook - exclude = [] + exclude = [ + 'youtube_id', 'youtube_queued' + ] def save(self, commit=True, path=None): """ Performs normal save, with given file as an source audiobook. diff --git a/src/archive/migrations/0027_auto_20221025_1336.py b/src/archive/migrations/0027_auto_20221025_1336.py new file mode 100644 index 0000000..6e6e8a8 --- /dev/null +++ b/src/archive/migrations/0027_auto_20221025_1336.py @@ -0,0 +1,55 @@ +# Generated by Django 3.1.14 on 2022-10-25 13:36 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0026_auto_20211222_1605'), + ] + + operations = [ + migrations.RemoveField( + model_name='audiobook', + name='mp3_published_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='mp3_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='mp3_task', + ), + migrations.RemoveField( + model_name='audiobook', + name='ogg_published_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='ogg_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='ogg_task', + ), + migrations.RemoveField( + model_name='audiobook', + name='youtube_published_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='youtube_tags', + ), + migrations.RemoveField( + model_name='audiobook', + name='youtube_task', + ), + migrations.AddField( + model_name='audiobook', + name='license_secondary', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='secondary', to='archive.license', verbose_name='license'), + ), + ] diff --git a/src/archive/migrations/0028_auto_20221025_1341.py b/src/archive/migrations/0028_auto_20221025_1341.py new file mode 100644 index 0000000..bff3f8c --- /dev/null +++ b/src/archive/migrations/0028_auto_20221025_1341.py @@ -0,0 +1,29 @@ +# Generated by Django 3.1.14 on 2022-10-25 13:41 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0027_auto_20221025_1336'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='can_sell', + field=models.BooleanField(default=True, verbose_name='Do sprzedaży'), + ), + migrations.AddField( + model_name='project', + name='private_notes', + field=models.TextField(blank=True, verbose_name='Prywatne notatki'), + ), + migrations.AddField( + model_name='project', + name='required_license', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='archive.license', verbose_name='Wymagana licencja'), + ), + ] diff --git a/src/archive/models.py b/src/archive/models.py index b467a68..f218c88 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -32,7 +32,10 @@ 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") + private_notes = models.TextField(blank=True, verbose_name="Prywatne notatki") config = models.ForeignKey('Config', models.PROTECT) + can_sell = models.BooleanField(default=True, verbose_name="Do sprzedaży") + required_license = models.ForeignKey('License', models.PROTECT, blank=True, null=True, verbose_name='Wymagana licencja') youtube = models.ForeignKey('youtube.YouTube', models.PROTECT) icon = models.FileField(upload_to='archive/project', blank=True, null=True) info_flac = models.FileField(upload_to='archive/info_flac', blank=True) @@ -121,26 +124,18 @@ class Audiobook(models.Model): 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')) + license_secondary = models.ForeignKey(License, models.PROTECT, null=True, blank=True, verbose_name=_('license'), related_name='secondary') # publishing process mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) - mp3_task = models.CharField(max_length=64, null=True, editable=False) - mp3_tags = models.TextField(null=True, editable=False) mp3_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) - mp3_published_tags = models.TextField(null=True, editable=False) mp3_published = models.DateTimeField(null=True, editable=False) ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) - ogg_task = models.CharField(max_length=64, null=True, editable=False) - ogg_tags = models.TextField(null=True, editable=False) ogg_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) - ogg_published_tags = models.TextField(null=True, editable=False) ogg_published = models.DateTimeField(null=True, editable=False) youtube_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) - youtube_task = models.CharField(max_length=64, null=True, editable=False) - youtube_tags = models.TextField(null=True, editable=False) - youtube_published_tags = models.TextField(null=True, editable=False) youtube_published = models.DateTimeField(null=True, editable=False) youtube_id = models.CharField(max_length=255, blank=True, default='') youtube_queued = models.DateTimeField(null=True, blank=True) @@ -209,33 +204,15 @@ class Audiobook(models.Model): self.youtube_queued = now() self.save(update_fields=['youtube_status', 'youtube_queued']) - def get_mp3_tags(self): return json.loads(self.mp3_tags) if self.mp3_tags else None - def get_ogg_tags(self): return json.loads(self.ogg_tags) if self.ogg_tags else None - def get_mp3_published_tags(self): return json.loads(self.mp3_published_tags) if self.mp3_published_tags else None - def get_ogg_published_tags_tags(self): return json.loads(self.ogg_published_tags) if self.ogg_published_tags else None - def set_mp3_tags(self, tags): self.mp3_tags = json.dumps(tags) - def set_ogg_tags(self, tags): self.ogg_tags = json.dumps(tags) - def published(self): return self.mp3_published and self.ogg_published - def prepare_for_publish(self): - tags = { - 'name': self.title, - 'url': self.url, - 'tags': self.new_publish_tags(), - } - self.set_mp3_tags(tags) - self.set_ogg_tags(tags) - self.mp3_status = self.ogg_status = status.WAITING - self.save() - def publish(self, user, publish=True): from . import tasks - # isn't there a race here? - self.mp3_task = tasks.Mp3Task.delay(user.id, self.pk, publish=publish).task_id - self.ogg_task = tasks.OggTask.delay(user.id, self.pk, publish=publish).task_id - self.save() + self.mp3_status = self.ogg_status = status.WAITING + self.save(update_fields=['mp3_status', 'ogg_status']) + tasks.Mp3Task.delay(user.id, self.pk, publish=publish).task_id + tasks.OggTask.delay(user.id, self.pk, publish=publish).task_id def get_source_sha1(self): assert self.pk or self.source_sha1 @@ -282,8 +259,8 @@ class Audiobook(models.Model): if self.project.sponsors: tags['funded_by'] = self.project.sponsors - if self.source_sha1: - tags['flac_sha1'] = self.source_sha1 + tags['flac_sha1'] = self.get_source_sha1() + return tags def prepare_audio(self): @@ -306,11 +283,9 @@ class Audiobook(models.Model): if xml_url is None: return None - return WLDocument( - etree.parse( - io.BytesIO( - requests.get(xml_url).content - ) - ,parser = parser - ) - ) + return WLDocument(url=xml_url) + + @property + def cover(self): + from librarian.cover import LogoWLCover + return LogoWLCover(self.document.meta).output_file.get_bytes() diff --git a/src/archive/tasks.py b/src/archive/tasks.py index 796b83c..d95baac 100644 --- a/src/archive/tasks.py +++ b/src/archive/tasks.py @@ -39,10 +39,7 @@ class AudioFormatTask(Task): raise NotImplemented @classmethod - def set_tags(cls, audiobook, file_name): - tags = getattr(audiobook, "get_%s_tags" % cls.prefix)()['tags'] - if not tags.get('flac_sha1'): - tags['flac_sha1'] = audiobook.get_source_sha1() + def set_tags(cls, tags, file_name): audio = File(file_name) for k, v in tags.items(): audio[k] = v @@ -61,10 +58,8 @@ class AudioFormatTask(Task): **{field: getattr(audiobook, field)}) @classmethod - def published(cls, aid): + def published(cls, aid, tags): kwargs = { - "%s_published_tags" % cls.prefix: F("%s_tags" % cls.prefix), - "%s_tags" % cls.prefix: None, "%s_published" % cls.prefix: datetime.now(), '%s_status' % cls.prefix: None, } @@ -72,11 +67,10 @@ class AudioFormatTask(Task): @classmethod def put(cls, user, audiobook, path): - tags = getattr(audiobook, "get_%s_tags" % cls.prefix)() data = { - 'book': tags['url'], + 'book': audiobook.url, 'type': cls.ext, - 'name': tags['name'], + 'name': audiobook.title, ##### IS IT USED? 'part_name': audiobook.part_name, 'part_index': audiobook.index, 'parts_count': audiobook.parts_count, @@ -108,12 +102,14 @@ class AudioFormatTask(Task): out_file.close() self.encode(self.get_source_file_paths(audiobook), out_file.name) self.set_status(aid, status.TAGGING) - self.set_tags(audiobook, out_file.name) + + tags = audiobook.new_publish_tags() + self.set_tags(tags, out_file.name) self.set_status(aid, status.SENDING) if publish: self.put(user, audiobook, out_file.name) - self.published(aid) + self.published(aid, tags) else: self.set_status(aid, None) @@ -175,12 +171,9 @@ class Mp3Task(AudioFormatTask): ]) @classmethod - def set_tags(cls, audiobook, file_name): - mp3_tags = audiobook.get_mp3_tags()['tags'] - if not mp3_tags.get('flac_sha1'): - mp3_tags['flac_sha1'] = audiobook.get_source_sha1() + def set_tags(cls, tags, file_name): audio = id3.ID3(file_name) - for k, v in mp3_tags.items(): + for k, v in tags.items(): factory_tuple = cls.TAG_MAP[k] factory, tagtype = factory_tuple[:2] audio.add(factory(tagtype, v, *factory_tuple[2:])) diff --git a/src/archive/templates/archive/file_managed.html b/src/archive/templates/archive/file_managed.html index 60d6b6c..813ca46 100644 --- a/src/archive/templates/archive/file_managed.html +++ b/src/archive/templates/archive/file_managed.html @@ -17,7 +17,7 @@
-
+

{% if audiobook.slug %}{% endif %}{{ audiobook.title }}{% if audiobook.slug %}{% endif %}

@@ -25,14 +25,103 @@
{% csrf_token %} - {% bootstrap_form form %} + {% bootstrap_form form layout="horizontal" %}
+
+
+
+ + +
+ + + + + + + + +
+ +
+
+
+

+ YouTube + {% if audiobook.youtube_status %} + {{ audiobook.get_youtube_status_display }} + {% endif %} +

+
+
+ + {{ youtube_title }}

+ {{ youtube_description|linebreaksbr }} + + + + {% if audiobook.is_youtube_publishable %} +
+

+ + {% trans "Preview YouTube metadata" %} + +

+ + {% endif %} + +
+ {% csrf_token %} + + +
+ +
+ {% csrf_token %} + +
+ {% endif %} +
+ {% csrf_token %} + +
+ {% endif %} + +
+
+
+ +
+
+

Metadane dla MP3, Ogg

+
+
+ + tagi, które zostałyby zapisane do pliku, gdyby go teraz opublikować + {% tags_table audiobook.new_publish_tags 0 %} +
+
+
+ +
+ +
{% if audiobook.mp3_status or audiobook.ogg_status or audiobook.youtube_status %}

{% trans "Publishing pending" %}

@@ -52,8 +141,6 @@

MP3

- {% tags_table audiobook.get_mp3_tags.tags %} -

Status: {{ audiobook.get_mp3_status_display }}

{% endif %} @@ -61,8 +148,6 @@

Ogg Vorbis

- {% tags_table audiobook.get_ogg_tags.tags %} -

Status: {{ audiobook.get_ogg_status_display }}

{% endif %} @@ -71,9 +156,6 @@

{% trans "Download MP3 file." %}

{% if audiobook.mp3_published %}

{% trans "Published:" %} {{ audiobook.mp3_published }}

- {% if audiobook.get_mp3_published_tags.tags %} - {% tags_table audiobook.get_mp3_published_tags.tags %} - {% endif %} {% else %}

{% trans "Not published yet." %}

{% endif %} @@ -85,9 +167,6 @@

{% trans "Download Ogg Vorbis file." %}

{% if audiobook.ogg_published %}

{% trans "Published:" %} {{ audiobook.ogg_published }}

- {% if audiobook.get_ogg_published_tags.tags %} - {% tags_table audiobook.get_ogg_published_tags.tags %} - {% endif %} {% else %}

{% trans "Not published yet." %}

{% endif %} @@ -115,122 +194,51 @@
-
-
-

YouTube

-
-
- {% if audiobook.youtube_status %} -
-

YouTube

- -

Status: {{ audiobook.get_youtube_status_display }}

- {% endif %} - - {% if audiobook.youtube_id %} - {% if audiobook.youtube_id %} -

- - - - -

- {% endif %} - {% if audiobook.youtube_published %} -

{% trans "Published:" %} {{ audiobook.youtube_published }}

- {% if audiobook.get_youtube_published_tags.tags %} - {% tags_table audiobook.get_youtube_published_tags.tags %} - {% endif %} - {% else %} -

{% trans "Not published yet." %}

- {% endif %} - {% else %} -

{% trans "YouTube file hasn't been generated yet." %}

- {% endif %} - - {% if audiobook.youtube_id %} -
- {% csrf_token %} - -
-
- -
- {% csrf_token %} - -
- {% endif %} - - {% if audiobook.is_youtube_publishable %} -
-

- - {% trans "Preview YouTube metadata" %} - -

-
- {% csrf_token %} - -
- {% endif %} - -
-
-
-
- -
-
-

Metadane dla MP3, Ogg

-
-
- - {% tags_table audiobook.new_publish_tags 0 %} -
-
-
- -
-
-
-
-

Metadane dla YouTube

-
-
- - {{ youtube_title }}

- {{ youtube_description|linebreaksbr }} -
-
-
- -

Plik źródłowy

+ (informacje fizycznie ze źródłowego pliku)
-

Last modified: {{ audiobook.modified }}

-

Plik źródłowy: {{ path }} - (sha1: {{ audiobook.source_sha1 }}). -

- {% multiple_tags_table tags %} - -
- {% csrf_token %} - -
+
+
+ +

Last modified: {{ audiobook.modified }}

+

Plik źródłowy: {{ path }} + (sha1: {{ audiobook.source_sha1 }}). +

+ {% multiple_tags_table tags %} +
+ +
+
+
+
+ {% csrf_token %} + +

+ Jeśli ten plik nie jest potrzebny, możesz usunąć informacje o nim z systemu, + zachowując go tylko w postaci samego źródłowego pliku. +

+ + +
+
+
+
+
+ {% endblock %} diff --git a/src/archive/views.py b/src/archive/views.py index 0b5a5ac..4865203 100644 --- a/src/archive/views.py +++ b/src/archive/views.py @@ -157,9 +157,7 @@ def move_to_new(request, filename): def publish(request, aid, publish=True): """ mark file for publishing """ audiobook = get_object_or_404(models.Audiobook, id=aid) - audiobook.prepare_for_publish() - if publish: - audiobook.publish(request.user) + audiobook.publish(request.user, publish=publish) return redirect(file_managed, aid) diff --git a/src/youtube/management/commands/youtube.py b/src/youtube/management/commands/youtube.py index fd50e0c..c480830 100644 --- a/src/youtube/management/commands/youtube.py +++ b/src/youtube/management/commands/youtube.py @@ -16,8 +16,8 @@ class Command(BaseCommand): .exclude(youtube_queued=None) .order_by("youtube_queued")[: options["limit"]] ): - audiobook.youtube_task = tasks.YouTubeTask.delay( + tasks.YouTubeTask.delay( None, audiobook.id, True ).task_id audiobook.youtube_status = status.WAITING - audiobook.save(update_fields=["youtube_task", "youtube_status"]) + audiobook.save(update_fields=["youtube_status"]) diff --git a/src/youtube/tasks.py b/src/youtube/tasks.py index d7ca67e..7cf5eac 100644 --- a/src/youtube/tasks.py +++ b/src/youtube/tasks.py @@ -10,7 +10,7 @@ class YouTubeTask(AudioFormatTask): def encode(self, in_paths, out_path): self.audiobook.project.youtube.prepare_file(in_paths, out_path) - def set_tags(self, audiobook, filename): + def set_tags(self, tags, filename): pass @classmethod