<th>{% trans "Title" %}</th>
<th>MP3</th>
<th>Ogg</th>
- <th colspan="3">YouTube</th>
+ <th colspan="5">YouTube</th>
</tr>
</thead>
<tbody>
<em class="text-warning" title="ddd">
({{ audiobook }})
</em>
- {% endif %}
+ {% endif %}
</a>
</td>
<td>{% status audiobook "mp3" %}</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>
- <span class="text-secondary">
+ <span class="text-secondary" class="edit-youtube-volume" data-audiobook="{{ audiobook.id }}">
{{ audiobook.youtube_volume }}
</span>
</td>
<td>
</td>
+ <td>
+ </td>
+ <td>
+ {{ audiobook.duration }}
+ </td>
{% endifchanged %}
</tr>
{% endfor %}
"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}'
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"),
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)
+