From: Radek Czajka Date: Wed, 19 Aug 2020 16:00:34 +0000 (+0200) Subject: Mass yt publishing. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/2cd3809ad9d4d9ff445bb6cca3619b4017dc0de5?ds=sidebyside;hp=52421a3d925957f14d3fa2d8ce37ee82a4918e5e Mass yt publishing. --- diff --git a/src/archive/constants.py b/src/archive/constants.py index a5527ec..7114533 100644 --- a/src/archive/constants.py +++ b/src/archive/constants.py @@ -2,8 +2,8 @@ from django.utils.translation import gettext_lazy as _ class status: - WAITING = 1 - QUEUED = 10 + QUEUED = 5 + WAITING = 10 ENCODING = 20 TAGGING = 30 CONVERTING_AUDIO = 40 @@ -15,8 +15,8 @@ class status: SETTING_THUMBNAIL = 110 choices = [ - (WAITING, _('Waiting')), (QUEUED, _("Queued")), + (WAITING, _('Waiting')), (ENCODING, _('Encoding')), (TAGGING, _('Tagging')), (CONVERTING_AUDIO, _('Converting audio')), diff --git a/src/archive/models.py b/src/archive/models.py index 721ceee..3be61d4 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -4,6 +4,7 @@ import os.path 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 @@ -153,6 +154,13 @@ class Audiobook(models.Model): .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 diff --git a/src/archive/templates/archive/book.html b/src/archive/templates/archive/book.html index b3ead74..6f7bf1c 100644 --- a/src/archive/templates/archive/book.html +++ b/src/archive/templates/archive/book.html @@ -67,5 +67,11 @@ {% endwith %} +
+ {% csrf_token %} + +
{% endblock %} diff --git a/src/youtube/urls.py b/src/youtube/urls.py index 9de274e..8a4618b 100644 --- a/src/youtube/urls.py +++ b/src/youtube/urls.py @@ -4,6 +4,7 @@ from . import views urlpatterns = [ url(r'^publish/(\d+)/$', views.publish, name="youtube_publish"), + path('book//publish/', views.book_publish, name="youtube_book_publish"), path('thumbnail//', views.thumbnail, name='youtube_thumbnail'), path('thumbnail///', views.thumbnail, name='youtube_thumbnail'), path('preview//', views.Preview.as_view(), name="youtube_preview"), diff --git a/src/youtube/views.py b/src/youtube/views.py index 058178f..18bd1d7 100644 --- a/src/youtube/views.py +++ b/src/youtube/views.py @@ -3,7 +3,6 @@ from django.http import HttpResponse 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 @@ -19,12 +18,19 @@ from . import models, tasks 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: