From: Radek Czajka Date: Fri, 25 Jun 2021 15:32:17 +0000 (+0200) Subject: Easier cutting. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/5715ba5816c2773949689461f715a08caa8c5d11 Easier cutting. --- diff --git a/src/archive/templates/archive/book.html b/src/archive/templates/archive/book.html index 6f7bf1c..5a7f273 100644 --- a/src/archive/templates/archive/book.html +++ b/src/archive/templates/archive/book.html @@ -19,7 +19,7 @@ {% trans "Title" %} MP3 Ogg - YouTube + YouTube @@ -35,7 +35,7 @@ ({{ audiobook }}) - {% endif %} + {% endif %} {% status audiobook "mp3" %} @@ -45,7 +45,16 @@ {{ audiobook.youtube_volume_index }}/{{ volumes }} - {{ audiobook.youtube_volume }} +
+ {% csrf_token %} + +
+ + + {{ audiobook.total|duration }} + + + {{ audiobook.duration|duration }} {% status audiobook "youtube" %} @@ -55,12 +64,17 @@ – - + {{ audiobook.youtube_volume }} + + + + {{ audiobook.duration }} + {% endifchanged %} {% endfor %} diff --git a/src/archive/templatetags/tags.py b/src/archive/templatetags/tags.py index c3dfa23..2acc8b1 100755 --- a/src/archive/templatetags/tags.py +++ b/src/archive/templatetags/tags.py @@ -34,3 +34,13 @@ def status(audiobook, format): "format": format, "link": link, } + + + +@register.filter +def duration(s): + h = int(s / 3600) + s %= 3600 + m = int(s / 60) + s %= 60 + return f'{h}:{m:02d}:{s:02.1f}' diff --git a/src/archive/urls.py b/src/archive/urls.py index 4743227..826c0c3 100644 --- a/src/archive/urls.py +++ b/src/archive/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ url(r'^move_to_archive/(.+)/$', views.move_to_archive, name="move_to_archive"), url(r'^publishing/$', views.list_publishing, name="list_publishing"), path('book//', views.BookView.as_view(), name="book"), + path('book-youtube-volume//', views.book_youtube_volume, name="book_youtube_volume"), url(r'^file/(\d+)/$', views.file_managed, name="file"), url(r'^publish/(\d+)/$', views.publish, name="publish"), url(r'^convert/(\d+)/$', views.publish, {'publish': False}, name="convert"), diff --git a/src/archive/views.py b/src/archive/views.py index fab7a1c..cafda5d 100644 --- a/src/archive/views.py +++ b/src/archive/views.py @@ -299,6 +299,34 @@ class BookView(ListView): template_name = 'archive/book.html' def get_queryset(self): - return models.Audiobook.objects.filter(slug=self.kwargs["slug"]).order_by( + qs = models.Audiobook.objects.filter(slug=self.kwargs["slug"]).order_by( "index" ) + total = 0 + last_vol = None + for b in qs: + if last_vol != b.youtube_volume: + last_vol = b.youtube_volume + total = 0 + total = b.total = total + b.duration + return list(qs) + + +@permission_required('archive.change_audiobook') +def book_youtube_volume(request, aid): + audiobook = get_object_or_404(models.Audiobook, id=aid) + slug = audiobook.slug + cur_vol = audiobook.youtube_volume + new_vol = request.POST.get('volume', '') + + audiobook.youtube_volume = new_vol + audiobook.save() + + for a in models.Audiobook.objects.filter(youtube_volume=cur_vol, index__gt=audiobook.index).order_by('index'): + if a.youtube_volume != cur_vol: + break + a.youtube_volume = new_vol + a.save() + + return redirect('book', audiobook.slug) +