{% endif %}
</div>
<div class="col-md-6">
+ <p>
+ <a href="{% url 'youtube_preview' audiobook.id %}">
+ {% trans "Preview YouTube metadata" %}
+ </a>
+ </p>
<form method="post" action="{% url 'youtube_publish' audiobook.id %}">
{% csrf_token %}
<input class="btn btn-primary" type="submit" value="{% trans "Publish on YouTube" %}" />
{% csrf_token %}
<input class="btn btn-secondary" type="submit" value="{% trans "Convert without publishing" %}" />
</form>
-
</div>
</div>
</td></tr>
<h2>{% trans "YouTube" %}</h2>
</div>
<div class="card-body">
- {% if audiobook.youtube_file %}
- <p><a href="{% url 'download' audiobook.id 'mkv' %}">{% trans "Download YouTube file." %}</a></p>
+ {% if audiobook.youtube_id %}
+ {% if audiobook.youtube_id %}
+ <p>
+ <a href="https://youtu.be/{{ audiobook.youtube_id }}" target="_blank">{% trans "See on YouTube" %}</a>
+ </p>
+ <form method="post" action="{% url 'youtube_update' audiobook.id %}">
+ {% csrf_token %}
+ <input class="btn btn-secondary" type="submit" value="{% trans "Update YouTube metadata" %}">
+ </form>
+ {% endif %}
{% if audiobook.youtube_published %}
<p>{% trans "Published:" %} {{ audiobook.youtube_published }}</a></p>
{% if audiobook.get_youtube_published_tags.tags %}
--- /dev/null
+{% extends "archive/base.html" %}
+
+
+{% block content %}
+ <div class="card mt-4">
+ <div class="card-header">
+ <h2>
+ <a href="{% url 'file' object.id %}">
+ ← {{ object.title }}
+ </a>
+ </h2>
+ </div>
+ <div class="card-body">
+ <img src="{% url 'youtube_thumbnail' object.id %}" style="width:100%">
+ </div>
+ </div>
+
+
+ <div class="card mt-4 mb-4">
+ <div class="card-header">
+ <h2>{{ title }}</h2>
+ </div>
+ <div class="card-body">
+ {{ description|linebreaksbr }}
+ </div>
+ </div>
+{% endblock %}
--- /dev/null
+import django.template
+
+
+register = django.template.Library()
+
+
+@register.simple_tag
+def last_name(author):
+ # TODO: we should reference the Catalogue to get proper last name.
+ if author.lower() == 'autor nieznany':
+ return
+ parts = author.split(' ')
+ for part in reversed(parts):
+ if part.startswith('('): continue
+ return part
realheight = draw.textsize(line, font=font)[1]
if cursor + realheight > newimg.size[1]:
return False
- print('x', draw.text((0, cursor), line, font=font, fill=item.get('color')))
cursor += item['line-height']
img.paste(newimg, (d.get('x', 0), d.get('y', 0)), newimg)
url(r'^publish/(\d+)/$', views.publish, name="youtube_publish"),
url(r'^convert/(\d+)/$', views.publish, {'publish': False}, name="youtube_convert"),
path('thumbnail/<int:aid>/', views.thumbnail, name='youtube_thumbnail'),
+ path('preview/<int:pk>/', views.Preview.as_view(), name="youtube_preview"),
+ path('update/<int:pk>/', views.Update.as_view(), name="youtube_update"),
]
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.views import View
from django.views.decorators.http import require_POST
+from django.views.generic import DetailView
+from django.views.generic.detail import SingleObjectMixin
from archive.constants import status
from archive.models import Audiobook
from . import models, tasks
yt = models.YouTube.objects.first()
buf = yt.prepare_thumbnail(audiobook)
return HttpResponse(buf.getvalue(), content_type='image/png')
+
+
+class Preview(DetailView):
+ model = Audiobook
+ template_name = 'youtube/preview.html'
+
+ def get_context_data(self, **kwargs):
+ ctx = super().get_context_data(**kwargs)
+ yt = models.YouTube.objects.first()
+ ctx['data'] = yt.get_data(ctx['object'])
+ ctx['title'] = yt.get_title(ctx['object'])
+ ctx['description'] = yt.get_description(ctx['object'])
+ return ctx
+
+
+@method_decorator(permission_required('archive.change_audiobook'), name='dispatch')
+class Update(SingleObjectMixin, View):
+ model = Audiobook
+
+ def post(self, request, pk):
+ yt = models.YouTube.objects.first()
+ yt.update_data(self.get_object())
+ return redirect(reverse('file', args=[pk]))