embed podcast player
This commit is contained in:
parent
64509b7f7b
commit
66a91ea42b
6 changed files with 176 additions and 67 deletions
24
catalog/templates/embed_base.html
Normal file
24
catalog/templates/embed_base.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load l10n %}
|
||||
{% load humanize %}
|
||||
{% load admin_url %}
|
||||
{% load mastodon %}
|
||||
{% load oauth_token %}
|
||||
{% load truncate %}
|
||||
{% load strip_scheme %}
|
||||
{% load thumb %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="https://cdn.staticfile.org/cash/8.1.3/cash.min.js"></script>
|
||||
{% block head %}
|
||||
{% endblock %}
|
||||
<title>{{ site_name }} - {% trans item.category.label %} | {{ item.title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
49
catalog/templates/embed_podcast.html
Normal file
49
catalog/templates/embed_podcast.html
Normal file
|
@ -0,0 +1,49 @@
|
|||
{% extends "embed_base.html" %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load l10n %}
|
||||
{% load humanize %}
|
||||
{% load admin_url %}
|
||||
{% load mastodon %}
|
||||
{% load oauth_token %}
|
||||
{% load truncate %}
|
||||
{% load strip_scheme %}
|
||||
{% load thumb %}
|
||||
|
||||
{% block head %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/shikwasa@2.2.0/dist/shikwasa.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/shikwasa@2.2.0/dist/style.min.css" rel="stylesheet"></link>
|
||||
<style>
|
||||
.shk-player {
|
||||
font-family: sans-serif;
|
||||
background: unset;
|
||||
box-shadow: unset;
|
||||
}
|
||||
body {
|
||||
background: #333;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
$(()=>{
|
||||
{% if focus_item %}
|
||||
var position = 1 * "{{request.GET.position|escapejs}}";
|
||||
window.current_item_uuid = "{{focus_item.uuid}}";
|
||||
window.player = new Shikwasa.Player({
|
||||
container: () => document.querySelector('body'),
|
||||
preload: 'metadata',
|
||||
autoplay: true,
|
||||
theme: 'dark',
|
||||
themeColor: '#837FFF',
|
||||
audio: {
|
||||
title: "{{ focus_item.title | escapejs }}",
|
||||
cover: "{{ focus_item.cover_url | default:item.cover.url | escapejs }}",
|
||||
src: "{{ focus_item.media_url | escapejs }}",
|
||||
album: "{{ item.title|escapejs }}",
|
||||
artist: "{{ item.hosts|join:' / '|escapejs }}"
|
||||
}
|
||||
});
|
||||
if (position) window.player._initSeek = position;
|
||||
{% endif %}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -18,7 +18,9 @@
|
|||
<meta property="og:title" content="{{ site_name }}{% trans item.category.label %} - {{ item.title }}">
|
||||
<meta property="og:type" content="{{ item.category }}">
|
||||
<meta property="og:url" content="{{ request.build_absolute_uri }}">
|
||||
<meta property="og:image" content="{{ request.scheme }}://{{ request.get_host }}{{ item.cover.url }}">
|
||||
{% if item.has_cover %}
|
||||
<meta property="og:image" content="{{ item.cover.url }}">
|
||||
{% endif %}
|
||||
<meta property="og:site_name" content="{{ site_name }}">
|
||||
<meta property="og:description" content="{{ item.brief }}">
|
||||
{% block head %}
|
||||
|
|
|
@ -12,4 +12,12 @@
|
|||
|
||||
{% block head %}
|
||||
<meta http-equiv="refresh" content="0;url={{ item.program.absolute_url }}?focus={{ item.uuid }}{% if request.GET.position %}&position={{ request.GET.position }}{% endif %}" />
|
||||
<meta property="og:image" content="{{ item.cover_url | default:item.program.cover.url }">
|
||||
<meta property="twitter:image" content="{{ item.cover_url | default:item.program.cover.url }}">
|
||||
{% if item.media_url %}
|
||||
<meta property="twitter:card" content="player">
|
||||
<meta property="twitter:player" content="{{ item.program.absolute_url }}/embed?focus={{ item.uuid }}{% if request.GET.position %}&position={{ request.GET.position }}{% endif %}" />
|
||||
<meta property="twitter:player:width" content="300">
|
||||
<meta property="twitter:player:height" content="120">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -22,6 +22,13 @@ urlpatterns = [
|
|||
retrieve_by_uuid,
|
||||
name="retrieve_by_uuid",
|
||||
),
|
||||
re_path(
|
||||
r"^(?P<item_path>"
|
||||
+ _get_all_url_paths()
|
||||
+ ")/(?P<item_uuid>[A-Za-z0-9]{21,22})/embed$",
|
||||
embed,
|
||||
name="embed",
|
||||
),
|
||||
re_path(
|
||||
r"^(?P<item_path>"
|
||||
+ _get_all_url_paths()
|
||||
|
|
151
catalog/views.py
151
catalog/views.py
|
@ -9,6 +9,7 @@ from django.utils import timezone
|
|||
from django.core.paginator import Paginator
|
||||
from catalog.common.models import ExternalResource
|
||||
from .models import *
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from django.utils.baseconv import base62
|
||||
from journal.models import Mark, ShelfMember, Review
|
||||
from journal.models import (
|
||||
|
@ -35,73 +36,91 @@ def retrieve_by_uuid(request, item_uid):
|
|||
return redirect(item.url)
|
||||
|
||||
|
||||
def retrieve(request, item_path, item_uuid):
|
||||
if request.method == "GET":
|
||||
# item = get_object_or_404(Item, uid=base62.decode(item_uuid))
|
||||
item = Item.get_by_url(item_uuid)
|
||||
if item is None:
|
||||
raise Http404()
|
||||
item_url = f"/{item_path}/{item_uuid}"
|
||||
if item.url != item_url:
|
||||
return redirect(item.url)
|
||||
skipcheck = request.GET.get("skipcheck", False) and request.user.is_staff
|
||||
if not skipcheck and item.merged_to_item:
|
||||
return redirect(item.merged_to_item.url)
|
||||
if not skipcheck and item.is_deleted:
|
||||
raise Http404()
|
||||
focus_item = None
|
||||
if request.GET.get("focus"):
|
||||
focus_item = get_object_or_404(
|
||||
Item, uid=base62.decode(request.GET.get("focus"))
|
||||
)
|
||||
mark = None
|
||||
review = None
|
||||
mark_list = None
|
||||
review_list = None
|
||||
collection_list = []
|
||||
shelf_types = [
|
||||
(n[1], n[2]) for n in iter(ShelfTypeNames) if n[0] == item.category
|
||||
]
|
||||
if request.user.is_authenticated:
|
||||
visible = query_visible(request.user)
|
||||
mark = Mark(request.user, item)
|
||||
review = mark.review
|
||||
collection_list = (
|
||||
item.collections.all()
|
||||
.filter(visible)
|
||||
.annotate(like_counts=Count("likes"))
|
||||
.order_by("-like_counts")
|
||||
)
|
||||
mark_query = (
|
||||
ShelfMember.objects.filter(item=item)
|
||||
.filter(visible)
|
||||
.order_by("-created_time")
|
||||
)
|
||||
mark_list = [
|
||||
member.mark for member in mark_query[:NUM_REVIEWS_ON_ITEM_PAGE]
|
||||
]
|
||||
review_list = (
|
||||
Review.objects.filter(item=item)
|
||||
.filter(visible)
|
||||
.order_by("-created_time")[:NUM_REVIEWS_ON_ITEM_PAGE]
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
item.class_name + ".html",
|
||||
{
|
||||
"item": item,
|
||||
"focus_item": focus_item,
|
||||
"mark": mark,
|
||||
"review": review,
|
||||
"mark_list": mark_list,
|
||||
"review_list": review_list,
|
||||
"collection_list": collection_list,
|
||||
"shelf_types": shelf_types,
|
||||
},
|
||||
)
|
||||
else:
|
||||
@xframe_options_exempt
|
||||
def embed(request, item_path, item_uuid):
|
||||
if request.method != "GET":
|
||||
raise BadRequest()
|
||||
item = Item.get_by_url(item_uuid)
|
||||
if item is None:
|
||||
raise Http404()
|
||||
if item.merged_to_item:
|
||||
return redirect(item.merged_to_item.url)
|
||||
if item.is_deleted:
|
||||
raise Http404()
|
||||
focus_item = None
|
||||
if request.GET.get("focus"):
|
||||
focus_item = get_object_or_404(
|
||||
Item, uid=base62.decode(request.GET.get("focus"))
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"embed_" + item.class_name + ".html",
|
||||
{"item": item, "focus_item": focus_item},
|
||||
)
|
||||
|
||||
|
||||
def retrieve(request, item_path, item_uuid):
|
||||
if request.method != "GET":
|
||||
raise BadRequest()
|
||||
# item = get_object_or_404(Item, uid=base62.decode(item_uuid))
|
||||
item = Item.get_by_url(item_uuid)
|
||||
if item is None:
|
||||
raise Http404()
|
||||
item_url = f"/{item_path}/{item_uuid}"
|
||||
if item.url != item_url:
|
||||
return redirect(item.url)
|
||||
skipcheck = request.GET.get("skipcheck", False) and request.user.is_staff
|
||||
if not skipcheck and item.merged_to_item:
|
||||
return redirect(item.merged_to_item.url)
|
||||
if not skipcheck and item.is_deleted:
|
||||
raise Http404()
|
||||
focus_item = None
|
||||
if request.GET.get("focus"):
|
||||
focus_item = get_object_or_404(
|
||||
Item, uid=base62.decode(request.GET.get("focus"))
|
||||
)
|
||||
mark = None
|
||||
review = None
|
||||
mark_list = None
|
||||
review_list = None
|
||||
collection_list = []
|
||||
shelf_types = [(n[1], n[2]) for n in iter(ShelfTypeNames) if n[0] == item.category]
|
||||
if request.user.is_authenticated:
|
||||
visible = query_visible(request.user)
|
||||
mark = Mark(request.user, item)
|
||||
review = mark.review
|
||||
collection_list = (
|
||||
item.collections.all()
|
||||
.filter(visible)
|
||||
.annotate(like_counts=Count("likes"))
|
||||
.order_by("-like_counts")
|
||||
)
|
||||
mark_query = (
|
||||
ShelfMember.objects.filter(item=item)
|
||||
.filter(visible)
|
||||
.order_by("-created_time")
|
||||
)
|
||||
mark_list = [member.mark for member in mark_query[:NUM_REVIEWS_ON_ITEM_PAGE]]
|
||||
review_list = (
|
||||
Review.objects.filter(item=item)
|
||||
.filter(visible)
|
||||
.order_by("-created_time")[:NUM_REVIEWS_ON_ITEM_PAGE]
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
item.class_name + ".html",
|
||||
{
|
||||
"item": item,
|
||||
"focus_item": focus_item,
|
||||
"mark": mark,
|
||||
"review": review,
|
||||
"mark_list": mark_list,
|
||||
"review_list": review_list,
|
||||
"collection_list": collection_list,
|
||||
"shelf_types": shelf_types,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Add table
Reference in a new issue