Mass yt publishing.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 19 Aug 2020 16:00:34 +0000 (18:00 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 19 Aug 2020 16:00:34 +0000 (18:00 +0200)
src/archive/constants.py
src/archive/models.py
src/archive/templates/archive/book.html
src/youtube/urls.py
src/youtube/views.py

index a5527ec..7114533 100644 (file)
@@ -2,8 +2,8 @@ from django.utils.translation import gettext_lazy as _
 
 
 class status:
 
 
 class status:
-    WAITING = 1
-    QUEUED = 10
+    QUEUED = 5
+    WAITING = 10
     ENCODING = 20
     TAGGING = 30
     CONVERTING_AUDIO = 40
     ENCODING = 20
     TAGGING = 30
     CONVERTING_AUDIO = 40
@@ -15,8 +15,8 @@ class status:
     SETTING_THUMBNAIL = 110
 
     choices = [
     SETTING_THUMBNAIL = 110
 
     choices = [
-        (WAITING, _('Waiting')),
         (QUEUED, _("Queued")),
         (QUEUED, _("Queued")),
+        (WAITING, _('Waiting')),
         (ENCODING, _('Encoding')),
         (TAGGING, _('Tagging')),
         (CONVERTING_AUDIO, _('Converting audio')),
         (ENCODING, _('Encoding')),
         (TAGGING, _('Tagging')),
         (CONVERTING_AUDIO, _('Converting audio')),
index 721ceee..3be61d4 100644 (file)
@@ -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.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
 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()
         )
 
             .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
     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
index b3ead74..6f7bf1c 100644 (file)
           {% endwith %}
         </tbody>
       </table>
           {% 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 %}
     </div>
 {% endblock %}
index 9de274e..8a4618b 100644 (file)
@@ -4,6 +4,7 @@ from . import views
 
 urlpatterns = [
     url(r'^publish/(\d+)/$', views.publish, name="youtube_publish"),
 
 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"),
     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"),
index 058178f..18bd1d7 100644 (file)
@@ -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.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
 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:
 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]))
 
 
     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:
 def thumbnail(request, aid, thumbnail_id=None):
     audiobook = get_object_or_404(Audiobook, id=aid)
     if thumbnail_id is None: