class status:
- WAITING = 1
- QUEUED = 10
+ QUEUED = 5
+ WAITING = 10
ENCODING = 20
TAGGING = 30
CONVERTING_AUDIO = 40
SETTING_THUMBNAIL = 110
choices = [
- (WAITING, _('Waiting')),
(QUEUED, _("Queued")),
+ (WAITING, _('Waiting')),
(ENCODING, _('Encoding')),
(TAGGING, _('Tagging')),
(CONVERTING_AUDIO, _('Converting audio')),
from django.db import models
from time import sleep
from django.utils.functional import cached_property
+from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django_pglocks import advisory_lock
import requests
.exists()
)
+ def youtube_publish(self):
+ if not self.is_youtube_publishable:
+ return False
+ self.youtube_status = status.QUEUED
+ 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
{% endwith %}
</tbody>
</table>
+ <form method="post" action="{% url 'youtube_book_publish' view.kwargs.slug %}">
+ {% csrf_token %}
+ <button class="btn btn-primary">
+ Opublikuj wszystko na YouTube
+ </button>
+ </form>
</div>
{% endblock %}
urlpatterns = [
url(r'^publish/(\d+)/$', views.publish, name="youtube_publish"),
+ path('book/<slug:slug>/publish/', views.book_publish, name="youtube_book_publish"),
path('thumbnail/<int:aid>/', views.thumbnail, name='youtube_thumbnail'),
path('thumbnail/<int:aid>/<int:thumbnail_id>/', views.thumbnail, name='youtube_thumbnail'),
path('preview/<int:pk>/', views.Preview.as_view(), name="youtube_preview"),
from django.shortcuts import redirect, get_object_or_404
from django.urls import reverse
from django.utils.decorators import method_decorator
-from django.utils.timezone import now
from django.views import View
from django.views.decorators.http import require_POST
from django.views.generic import DetailView
def publish(request, aid, publish=True):
audiobook = get_object_or_404(Audiobook, id=aid)
if audiobook.is_youtube_publishable:
- audiobook.youtube_status = status.QUEUED
- audiobook.youtube_queued = now()
- audiobook.save(update_fields=['youtube_status', 'youtube_queued'])
+ audiobook.youtube_publish()
return redirect(reverse('file', args=[aid]))
+@require_POST
+@permission_required('archive.change_audiobook')
+def book_publish(request, slug):
+ for audiobook in Audiobook.objects.filter(slug=slug).order_by("index"):
+ if audiobook.is_youtube_publishable:
+ audiobook.youtube_publish()
+ return redirect(reverse('book', args=[slug]))
+
+
def thumbnail(request, aid, thumbnail_id=None):
audiobook = get_object_or_404(Audiobook, id=aid)
if thumbnail_id is None: