From: Radek Czajka Date: Thu, 21 Jan 2021 11:50:17 +0000 (+0100) Subject: Add duration to audiobook model. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/09bb079af644f53690f40028f4af49f35a6a4378?ds=sidebyside Add duration to audiobook model. --- diff --git a/src/archive/admin.py b/src/archive/admin.py index 279c6dc..d9b662b 100644 --- a/src/archive/admin.py +++ b/src/archive/admin.py @@ -5,10 +5,11 @@ admin.site.register(Project) class AudiobookAdmin(admin.ModelAdmin): - list_display = ["title", "slug", "index", "part_name", "license", "youtube_volume"] + list_display = ["title", "slug", "index", "part_name", "duration", "license", "youtube_volume"] list_filter = ["license"] search_fields = ["title", "slug", "part_name", "youtube_volume"] list_editable = ["youtube_volume"] + readonly_fields = ['duration'] admin.site.register(Audiobook, AudiobookAdmin) diff --git a/src/archive/forms.py b/src/archive/forms.py index 22c426e..3b68c28 100644 --- a/src/archive/forms.py +++ b/src/archive/forms.py @@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _ import mutagen from django.utils.encoding import force_bytes +from youtube.utils import get_duration from archive.models import Audiobook from archive.settings import FILES_PATH, NEW_PATH from archive.utils import ExistingFile, sha1_file @@ -31,6 +32,7 @@ class AudiobookForm(forms.ModelForm): # save the file in model abs_path = os.path.join(NEW_PATH, path) + m.duration = get_duration(abs_path) m.source_file.save( path, ExistingFile(abs_path)) diff --git a/src/archive/migrations/0019_auto_20210121_1249.py b/src/archive/migrations/0019_auto_20210121_1249.py new file mode 100644 index 0000000..9790f1c --- /dev/null +++ b/src/archive/migrations/0019_auto_20210121_1249.py @@ -0,0 +1,33 @@ +# Generated by Django 3.1.2 on 2021-01-21 12:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0018_auto_20200703_1718'), + ] + + operations = [ + migrations.AddField( + model_name='audiobook', + name='duration', + field=models.FloatField(editable=False, null=True), + ), + 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='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), + ), + ] diff --git a/src/archive/models.py b/src/archive/models.py index 3be61d4..11917b8 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -63,6 +63,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'), diff --git a/src/archive/templates/archive/file_managed.html b/src/archive/templates/archive/file_managed.html index d6e8be8..60d6b6c 100644 --- a/src/archive/templates/archive/file_managed.html +++ b/src/archive/templates/archive/file_managed.html @@ -20,7 +20,7 @@
@@ -219,7 +219,7 @@

Last modified: {{ audiobook.modified }}

-

Plik źródłowy: {{ path }} +

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

{% multiple_tags_table tags %}