mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 05:32:21 +01:00
api: Add image endpoint for use on tosti.science.ru.nl
This commit is contained in:
@ -19,4 +19,5 @@ urlpatterns = [
|
|||||||
url(r'^volumedown', views.volume_down),
|
url(r'^volumedown', views.volume_down),
|
||||||
url(r'^volumeup', views.volume_up),
|
url(r'^volumeup', views.volume_up),
|
||||||
url(r'^mute', views.mute),
|
url(r'^mute', views.mute),
|
||||||
|
url(r'^hier-heb-je-je-endpoint-voor-tosti.png$', views.queue_png),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q, Sum, Value
|
from django.db.models import Q, Sum, Value
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
from django.http import JsonResponse, HttpResponseForbidden
|
from django.http import JsonResponse, HttpResponseForbidden, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
@ -349,3 +349,26 @@ def _request_weight(ps):
|
|||||||
return float(ps.song.duration)
|
return float(ps.song.duration)
|
||||||
# Count other requests for 10%
|
# Count other requests for 10%
|
||||||
return 0.10 * float(ps.song.duration)
|
return 0.10 * float(ps.song.duration)
|
||||||
|
|
||||||
|
|
||||||
|
def queue_png(request):
|
||||||
|
current_song = request.user.queue.current_song()
|
||||||
|
|
||||||
|
requestor = 'Marietje' if current_song.user is 'Marietje' else 'privacy™' # Anonymous
|
||||||
|
artist, title = current_song.song.artist, current_song.song.title
|
||||||
|
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
width, height = 640, 480
|
||||||
|
ttf = 'marietje/static/fonts/comic-serif.tff'
|
||||||
|
zuidSerifRequestor = ImageFont.truetype(ttf, 64)
|
||||||
|
zuidSerifArtist = ImageFont.truetype(ttf, 80)
|
||||||
|
zuidSerifTitle = ImageFont.truetype(ttf, 64)
|
||||||
|
img = Image.new('RGB', (width, height), color='#BE311A')
|
||||||
|
imgDraw = ImageDraw.Draw(img)
|
||||||
|
imgDraw.text((10, 110), requestor, fill='#FFFFFF', font=zuidSerifRequestor)
|
||||||
|
imgDraw.text((10, 200), artist, fill='#FFFFFF', font=zuidSerifArtist)
|
||||||
|
imgDraw.text((10, 280), title, fill='#FFFFFF', font=zuidSerifTitle)
|
||||||
|
|
||||||
|
response = HttpResponse(content_type='image/png')
|
||||||
|
img.save(response, 'png')
|
||||||
|
return response
|
||||||
|
|||||||
@ -3,3 +3,4 @@ mutagen
|
|||||||
argon2-cffi
|
argon2-cffi
|
||||||
prometheus_client
|
prometheus_client
|
||||||
pylint==2.5.3
|
pylint==2.5.3
|
||||||
|
pillow
|
||||||
|
|||||||
Reference in New Issue
Block a user