mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 23:39:18 +00:00
add video detail playlist nav
This commit is contained in:
@@ -139,7 +139,7 @@
|
||||
<div class="playlist-nav-item">
|
||||
{% if playlist_item.playlist_previous %}
|
||||
<a href="{% url 'video' playlist_item.playlist_previous.youtube_id %}">
|
||||
<img src="/cache/{{ playlist_item.playlist_previous.vid_thumb }}" alt="previous thumbnail">
|
||||
<img src="{{ playlist_item.playlist_previous.vid_thumb }}" alt="previous thumbnail">
|
||||
</a>
|
||||
<div class="playlist-desc">
|
||||
<p>Previous:</p>
|
||||
@@ -158,7 +158,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<a href="{% url 'video' playlist_item.playlist_next.youtube_id %}">
|
||||
<img src="/cache/{{ playlist_item.playlist_next.vid_thumb }}" alt="previous thumbnail">
|
||||
<img src="{{ playlist_item.playlist_next.vid_thumb }}" alt="previous thumbnail">
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ import json
|
||||
from datetime import datetime
|
||||
|
||||
from channel.src import index as channel
|
||||
from common.src.env_settings import EnvironmentSettings
|
||||
from common.src.es_connect import ElasticWrap, IndexPaginate
|
||||
from common.src.index_generic import YouTubeItem
|
||||
from download.src.thumbnails import ThumbManager
|
||||
@@ -190,6 +191,7 @@ class YoutubePlaylist(YouTubeItem):
|
||||
|
||||
def build_nav(self, youtube_id):
|
||||
"""find next and previous in playlist of a given youtube_id"""
|
||||
cache_root = EnvironmentSettings().get_cache_root()
|
||||
all_entries_available = self.json_data["playlist_entries"]
|
||||
all_entries = [i for i in all_entries_available if i["downloaded"]]
|
||||
current = [i for i in all_entries if i["youtube_id"] == youtube_id]
|
||||
@@ -203,14 +205,16 @@ class YoutubePlaylist(YouTubeItem):
|
||||
else:
|
||||
previous_item = all_entries[current_idx - 1]
|
||||
prev_id = previous_item["youtube_id"]
|
||||
previous_item["vid_thumb"] = ThumbManager(prev_id).vid_thumb_path()
|
||||
prev_thumb_path = ThumbManager(prev_id).vid_thumb_path()
|
||||
previous_item["vid_thumb"] = f"{cache_root}/{prev_thumb_path}"
|
||||
|
||||
if current_idx == len(all_entries) - 1:
|
||||
next_item = False
|
||||
else:
|
||||
next_item = all_entries[current_idx + 1]
|
||||
next_id = next_item["youtube_id"]
|
||||
next_item["vid_thumb"] = ThumbManager(next_id).vid_thumb_path()
|
||||
next_thumb_path = ThumbManager(next_id).vid_thumb_path()
|
||||
next_item["vid_thumb"] = f"{cache_root}/{next_thumb_path}"
|
||||
|
||||
self.nav = {
|
||||
"playlist_meta": {
|
||||
|
||||
@@ -10,6 +10,11 @@ urlpatterns = [
|
||||
views.VideoApiView.as_view(),
|
||||
name="api-video",
|
||||
),
|
||||
path(
|
||||
"<slug:video_id>/nav/",
|
||||
views.VideoApiNavView.as_view(),
|
||||
name="api-video-nav",
|
||||
),
|
||||
path(
|
||||
"<slug:video_id>/progress/",
|
||||
views.VideoProgressView.as_view(),
|
||||
|
||||
@@ -2,10 +2,26 @@
|
||||
|
||||
from common.src.ta_redis import RedisArchivist
|
||||
from common.views_base import AdminWriteOnly, ApiBaseView
|
||||
from playlist.src.index import YoutubePlaylist
|
||||
from rest_framework.response import Response
|
||||
from video.src.index import YoutubeVideo
|
||||
|
||||
|
||||
class VideoApiListView(ApiBaseView):
|
||||
"""resolves to /api/video/
|
||||
GET: returns list of videos
|
||||
"""
|
||||
|
||||
search_base = "ta_video/_search/"
|
||||
|
||||
def get(self, request):
|
||||
"""get request"""
|
||||
self.data.update({"sort": [{"published": {"order": "desc"}}]})
|
||||
self.get_document_list(request)
|
||||
|
||||
return Response(self.response)
|
||||
|
||||
|
||||
class VideoApiView(ApiBaseView):
|
||||
"""resolves to /api/video/<video_id>/
|
||||
GET: returns metadata dict of video
|
||||
@@ -35,19 +51,35 @@ class VideoApiView(ApiBaseView):
|
||||
return Response(message, status=status_code)
|
||||
|
||||
|
||||
class VideoApiListView(ApiBaseView):
|
||||
"""resolves to /api/video/
|
||||
GET: returns list of videos
|
||||
class VideoApiNavView(ApiBaseView):
|
||||
"""resolves to /api/video/<video-id>/nav/
|
||||
GET: returns playlist nav
|
||||
"""
|
||||
|
||||
search_base = "ta_video/_search/"
|
||||
search_base = "ta_video/_doc/"
|
||||
|
||||
def get(self, request):
|
||||
def get(self, request, video_id):
|
||||
# pylint: disable=unused-argument
|
||||
"""get request"""
|
||||
self.data.update({"sort": [{"published": {"order": "desc"}}]})
|
||||
self.get_document_list(request)
|
||||
self.get_document(video_id)
|
||||
if self.status_code != 200:
|
||||
return Response(status=self.status_code)
|
||||
|
||||
return Response(self.response)
|
||||
print(self.response)
|
||||
|
||||
playlist_nav = []
|
||||
|
||||
if not self.response["data"].get("playlist"):
|
||||
return Response(playlist_nav)
|
||||
|
||||
for playlist_id in self.response["data"]["playlist"]:
|
||||
playlist = YoutubePlaylist(playlist_id)
|
||||
playlist.get_from_es()
|
||||
playlist.build_nav(video_id)
|
||||
if playlist.nav:
|
||||
playlist_nav.append(playlist.nav)
|
||||
|
||||
return Response(playlist_nav, status=self.status_code)
|
||||
|
||||
|
||||
class VideoProgressView(ApiBaseView):
|
||||
|
||||
Reference in New Issue
Block a user