extend playlist_id with metadata and links

This commit is contained in:
simon 2021-11-12 15:01:39 +07:00
parent 94576b4b76
commit b1c82759bb
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
4 changed files with 62 additions and 9 deletions

View File

@ -121,6 +121,12 @@ class SearchHandler:
date_str = datetime.strftime(date_refresh, "%d %b, %Y") date_str = datetime.strftime(date_refresh, "%d %b, %Y")
hit["source"]["vid_last_refresh"] = date_str hit["source"]["vid_last_refresh"] = date_str
if "playlist_last_refresh" in hit_keys:
playlist_last_refresh = hit["source"]["playlist_last_refresh"]
date_refresh = datetime.fromtimestamp(playlist_last_refresh)
date_str = datetime.strftime(date_refresh, "%d %b, %Y")
hit["source"]["playlist_last_refresh"] = date_str
if "vid_thumb_url" in hit_keys: if "vid_thumb_url" in hit_keys:
youtube_id = hit["source"]["youtube_id"] youtube_id = hit["source"]["youtube_id"]
thumb_path = ThumbManager().vid_thumb_path(youtube_id) thumb_path = ThumbManager().vid_thumb_path(youtube_id)

View File

@ -57,11 +57,13 @@
{% for playlist in playlists %} {% for playlist in playlists %}
<div class="playlist-item {{ view_style }}"> <div class="playlist-item {{ view_style }}">
<div class="playlist-thumbnail"> <div class="playlist-thumbnail">
<a href="{% url 'playlist_id' playlist.source.playlist_id %}">
<img src="/cache/playlists/{{ playlist.source.playlist_id }}.jpg" alt="{{ playlist.source.playlist_id }}-thumbnail"> <img src="/cache/playlists/{{ playlist.source.playlist_id }}.jpg" alt="{{ playlist.source.playlist_id }}-thumbnail">
</a>
</div> </div>
<div class="playlist-desc {{ view_style }}"> <div class="playlist-desc {{ view_style }}">
<h3>{{ playlist.source.playlist_channel }}</h3> <a href="{% url 'channel_id' playlist.source.playlist_channel_id %}"><h3>{{ playlist.source.playlist_channel }}</h3></a>
<h2>{{ playlist.source.playlist_name }}</h2> <a href="{% url 'playlist_id' playlist.source.playlist_id %}"><h2>{{ playlist.source.playlist_name }}</h2></a>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -2,6 +2,9 @@
{% load static %} {% load static %}
{% load humanize %} {% load humanize %}
{% block content %} {% block content %}
<div class="title-bar">
<h1>{{ playlist_info.playlist_name }}</h1>
</div>
<div class="info-box info-box-3"> <div class="info-box info-box-3">
<div class="info-box-item"> <div class="info-box-item">
<div class="round-img"> <div class="round-img">
@ -18,7 +21,35 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
<div class="info-box-item">
<div>
<p>Last refreshed: {{ playlist_info.playlist_last_refresh }}</p>
<p>Subscribed:
{% if playlist_info.playlist_subscribed %}
<button type="button" id="{{ playlist_info.playlist_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ playlist_info.playlist_name }}">Unsubscribe</button>
{% else %}
false
{% endif %}
</p>
</div> </div>
</div>
<div class="info-box-item">
<div>
{% if max_hits %}
<p>Total Videos archived: {{ playlist_info.playlist_entries|length }}/{{ max_hits }}</p>
<p>Watched: <button title="Mark all videos from {{ playlist_info.playlist_name }} as watched" type="button" id="{{ playlist_info.playlist_id }}" onclick="isWatched(this.id)">Mark as watched</button></p>
{% endif %}
</div>
</div>
</div>
{% if playlist_info.playlist_description %}
<div class="info-box-item description-box">
<p>Description: <button onclick="textReveal()" id="text-reveal-button">Show</button></p>
<div id="text-reveal" class="description-text">
{{ playlist_info.playlist_description|linebreaks }}
</div>
</div>
{% endif %}
<div id="player" class="video-player"></div> <div id="player" class="video-player"></div>
<div class="view-controls"> <div class="view-controls">
<div class="toggle"> <div class="toggle">

View File

@ -601,18 +601,25 @@ class PlaylistIdView(View):
search = SearchHandler(url, data) search = SearchHandler(url, data)
videos_hits = search.get_data() videos_hits = search.get_data()
max_hits = search.max_hits max_hits = search.max_hits
playlist_info = self.get_playlist_info(
playlist_id_detail, view_config["es_url"]
)
playlist_name = playlist_info["playlist_name"]
if max_hits: if max_hits:
source = videos_hits[0]["source"] source = videos_hits[0]["source"]
channel_info = source["channel"] channel_info = source["channel"]
playlist_name = source["playlist"]["playlist_name"]
pagination_handler.validate(max_hits) pagination_handler.validate(max_hits)
pagination = pagination_handler.pagination pagination = pagination_handler.pagination
else: else:
channel_info = False channel_info = self.get_channel_info(
playlist_info["playlist_channel_id"], view_config["es_url"]
)
videos_hits = False
pagination = False pagination = False
context = { context = {
"playlist_info": playlist_info,
"playlist_name": playlist_name, "playlist_name": playlist_name,
"channel_info": channel_info, "channel_info": channel_info,
"videos": videos_hits, "videos": videos_hits,
@ -664,12 +671,19 @@ class PlaylistIdView(View):
def get_channel_info(channel_id_detail, es_url): def get_channel_info(channel_id_detail, es_url):
"""get channel info from channel index if no videos""" """get channel info from channel index if no videos"""
url = f"{es_url}/ta_channel/_doc/{channel_id_detail}" url = f"{es_url}/ta_channel/_doc/{channel_id_detail}"
data = False search = SearchHandler(url, data=False)
search = SearchHandler(url, data)
channel_data = search.get_data() channel_data = search.get_data()
channel_info = channel_data[0]["source"] channel_info = channel_data[0]["source"]
channel_name = channel_info["channel_name"] return channel_info
return channel_info, channel_name
@staticmethod
def get_playlist_info(playlist_id_detail, es_url):
"""get playlist info header to no fail if playlist is empty"""
url = f"{es_url}/ta_playlist/_doc/{playlist_id_detail}"
search = SearchHandler(url, data=False)
playlist_data = search.get_data()
playlist_info = playlist_data[0]["source"]
return playlist_info
class PlaylistView(View): class PlaylistView(View):