Easier cutting.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 25 Jun 2021 15:32:17 +0000 (17:32 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 25 Jun 2021 15:32:17 +0000 (17:32 +0200)
src/archive/templates/archive/book.html
src/archive/templatetags/tags.py
src/archive/urls.py
src/archive/views.py

index 6f7bf1c..5a7f273 100644 (file)
@@ -19,7 +19,7 @@
             <th>{% trans "Title" %}</th>
             <th>MP3</th>
             <th>Ogg</th>
             <th>{% trans "Title" %}</th>
             <th>MP3</th>
             <th>Ogg</th>
-            <th colspan="3">YouTube</th>
+            <th colspan="5">YouTube</th>
           </tr>
         </thead>
         <tbody>
           </tr>
         </thead>
         <tbody>
@@ -35,7 +35,7 @@
                       <em class="text-warning" title="ddd">
                         ({{ audiobook }})
                       </em>
                       <em class="text-warning" title="ddd">
                         ({{ audiobook }})
                       </em>
-                      {% endif %}
+                    {% endif %}
                   </a>
                 </td>
                 <td>{% status audiobook "mp3" %}</td>
                   </a>
                 </td>
                 <td>{% status audiobook "mp3" %}</td>
                     {{ audiobook.youtube_volume_index }}/{{ volumes }}
                   </td>
                   <td>
                     {{ audiobook.youtube_volume_index }}/{{ volumes }}
                   </td>
                   <td>
-                    {{ audiobook.youtube_volume }}
+                    <form method="POST" action="{% url 'book_youtube_volume' audiobook.id %}">
+                      {% csrf_token %}
+                      <input name='volume' value="{{ audiobook.youtube_volume }}" class="form-control">
+                    </form>
+                  </td>
+                  <td>
+                    {{ audiobook.total|duration }}
+                  </td>
+                  <td>
+                    {{ audiobook.duration|duration }}
                   </td>
                   <td>
                     {% status audiobook "youtube" %}
                   </td>
                   <td>
                     {% status audiobook "youtube" %}
                     –
                   </td>
                   <td>
                     –
                   </td>
                   <td>
-                    <span class="text-secondary">
+                    <span class="text-secondary" class="edit-youtube-volume" data-audiobook="{{ audiobook.id }}">
                       {{ audiobook.youtube_volume }}
                     </span>
                   </td>
                   <td>
                   </td>
                       {{ audiobook.youtube_volume }}
                     </span>
                   </td>
                   <td>
                   </td>
+                  <td>
+                  </td>
+                  <td>
+                    {{ audiobook.duration }}
+                  </td>
                 {% endifchanged %}
               </tr>
             {% endfor %}
                 {% endifchanged %}
               </tr>
             {% endfor %}
index c3dfa23..2acc8b1 100755 (executable)
@@ -34,3 +34,13 @@ def status(audiobook, format):
         "format": format,
         "link": link,
     }
         "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}'
index 4743227..826c0c3 100644 (file)
@@ -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/<slug:slug>/', views.BookView.as_view(), name="book"),
     url(r'^move_to_archive/(.+)/$', views.move_to_archive, name="move_to_archive"),
     url(r'^publishing/$', views.list_publishing, name="list_publishing"),
     path('book/<slug:slug>/', views.BookView.as_view(), name="book"),
+    path('book-youtube-volume/<int:aid>/', 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"),
     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"),
index fab7a1c..cafda5d 100644 (file)
@@ -299,6 +299,34 @@ class BookView(ListView):
     template_name = 'archive/book.html'
 
     def get_queryset(self):
     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"
         )
             "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)
+