mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-23 02:10:15 +00:00
initial PlaylistIdView paths and basic template
This commit is contained in:
parent
16833a4377
commit
94576b4b76
71
tubearchivist/home/templates/home/playlist_id.html
Normal file
71
tubearchivist/home/templates/home/playlist_id.html
Normal file
@ -0,0 +1,71 @@
|
||||
{% extends "home/base.html" %}
|
||||
{% load static %}
|
||||
{% load humanize %}
|
||||
{% block content %}
|
||||
<div class="info-box info-box-3">
|
||||
<div class="info-box-item">
|
||||
<div class="round-img">
|
||||
<a href="{% url 'channel_id' channel_info.channel_id %}">
|
||||
<img src="/cache/channels/{{ channel_info.channel_id }}_thumb.jpg" alt="channel-thumb">
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<h3><a href="{% url 'channel_id' channel_info.channel_id %}">{{ channel_info.channel_name }}</a></h3>
|
||||
{% if channel_info.channel_subs >= 1000000 %}
|
||||
<span>Subscribers: {{ channel_info.channel_subs|intword }}</span>
|
||||
{% else %}
|
||||
<span>Subscribers: {{ channel_info.channel_subs|intcomma }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="player" class="video-player"></div>
|
||||
<div class="view-controls">
|
||||
<div class="toggle">
|
||||
<span>Hide watched videos:</span>
|
||||
<div class="toggleBox">
|
||||
<input id="hide_watched" onclick="toggleCheckbox(this)" type="checkbox"
|
||||
{% if hide_watched %}checked{% endif %}>
|
||||
<label for="" class="onbtn">On</label>
|
||||
<label for="" class="ofbtn">Off</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="view-icons">
|
||||
<img src="{% static 'img/icon-gridview.svg' %}" onclick="changeView(this)" data-origin="home" data-value="grid" alt="grid view">
|
||||
<img src="{% static 'img/icon-listview.svg' %}" onclick="changeView(this)" data-origin="home" data-value="list" alt="list view">
|
||||
</div>
|
||||
</div>
|
||||
<div class="video-list {{ view_style }}">
|
||||
{% if videos %}
|
||||
{% for video in videos %}
|
||||
<div class="video-item {{ view_style }}">
|
||||
<a href="#player" data-src="/media/{{ video.source.media_url }}" data-thumb="/cache/{{ video.source.vid_thumb_url }}" data-title="{{ video.source.title }}" data-channel="{{ video.source.channel.channel_name }}" data-id="{{ video.source.youtube_id }}" onclick="createPlayer(this)">
|
||||
<div class="video-thumb-wrap {{ view_style }}">
|
||||
<div class="video-thumb">
|
||||
<img src="/cache/{{ video.source.vid_thumb_url }}" alt="video-thumb">
|
||||
</div>
|
||||
<div class="video-play">
|
||||
<img src="{% static 'img/icon-play.svg' %}" alt="play-icon">
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="video-desc {{ view_style }}">
|
||||
<div class="video-desc-player" id="video-info-{{ video.source.youtube_id }}">
|
||||
{% if video.source.player.watched %}
|
||||
<img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" id="{{ video.source.youtube_id }}" onclick="isUnwatched(this.id)" class="seen-icon" title="Mark as unwatched">
|
||||
{% else %}
|
||||
<img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" id="{{ video.source.youtube_id }}" onclick="isWatched(this.id)" class="unseen-icon" title="Mark as watched.">
|
||||
{% endif %}
|
||||
<span>{{ video.source.published }} | {{ video.source.player.duration_str }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<a class="video-more" href="{% url 'video' video.source.youtube_id %}"><h2>{{ video.source.title }}</h2></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<h2>No videos found...</h2>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock content %}
|
@ -11,6 +11,7 @@ from home.views import (
|
||||
DownloadView,
|
||||
HomeView,
|
||||
LoginView,
|
||||
PlaylistIdView,
|
||||
PlaylistView,
|
||||
SettingsView,
|
||||
VideoView,
|
||||
@ -46,4 +47,9 @@ urlpatterns = [
|
||||
name="video",
|
||||
),
|
||||
path("playlist/", login_required(PlaylistView.as_view()), name="playlist"),
|
||||
path(
|
||||
"playlist/<slug:playlist_id_detail>/",
|
||||
login_required(PlaylistIdView.as_view()),
|
||||
name="playlist_id",
|
||||
),
|
||||
]
|
||||
|
@ -541,6 +541,137 @@ class ChannelView(View):
|
||||
return redirect("channel", permanent=True)
|
||||
|
||||
|
||||
class PlaylistIdView(View):
|
||||
"""resolves to /playlist/<playlist_id>
|
||||
show all videos in a playlist
|
||||
"""
|
||||
|
||||
def get(self, request, playlist_id_detail):
|
||||
"""handle get request"""
|
||||
view_config = self.read_config(user_id=request.user.id)
|
||||
context = self.get_playlist_videos(
|
||||
request, playlist_id_detail, view_config
|
||||
)
|
||||
context.update(view_config)
|
||||
return render(request, "home/playlist_id.html", context)
|
||||
|
||||
@staticmethod
|
||||
def read_config(user_id):
|
||||
"""build config dict"""
|
||||
config_handler = AppConfig(user_id)
|
||||
config = config_handler.config
|
||||
|
||||
view_key = f"{user_id}:view:home"
|
||||
view_style = RedisArchivist().get_message(view_key)["status"]
|
||||
if not view_style:
|
||||
view_style = config_handler.config["default_view"]["home"]
|
||||
|
||||
sort_by = RedisArchivist().get_message(f"{user_id}:sort_by")["status"]
|
||||
if not sort_by:
|
||||
sort_by = config["archive"]["sort_by"]
|
||||
|
||||
sort_order_key = f"{user_id}:sort_order"
|
||||
sort_order = RedisArchivist().get_message(sort_order_key)["status"]
|
||||
if not sort_order:
|
||||
sort_order = config["archive"]["sort_order"]
|
||||
|
||||
hide_watched_key = f"{user_id}:hide_watched"
|
||||
hide_watched = RedisArchivist().get_message(hide_watched_key)["status"]
|
||||
|
||||
view_config = {
|
||||
"colors": config_handler.colors,
|
||||
"es_url": config["application"]["es_url"],
|
||||
"view_style": view_style,
|
||||
"sort_by": sort_by,
|
||||
"sort_order": sort_order,
|
||||
"hide_watched": hide_watched,
|
||||
}
|
||||
return view_config
|
||||
|
||||
def get_playlist_videos(self, request, playlist_id_detail, view_config):
|
||||
"""get matching videos for playlist"""
|
||||
page_get = int(request.GET.get("page", 0))
|
||||
pagination_handler = Pagination(page_get, request.user.id)
|
||||
# get data
|
||||
url = view_config["es_url"] + "/ta_video/_search"
|
||||
data = self.build_data(
|
||||
pagination_handler, playlist_id_detail, view_config
|
||||
)
|
||||
|
||||
search = SearchHandler(url, data)
|
||||
videos_hits = search.get_data()
|
||||
max_hits = search.max_hits
|
||||
|
||||
if max_hits:
|
||||
source = videos_hits[0]["source"]
|
||||
channel_info = source["channel"]
|
||||
playlist_name = source["playlist"]["playlist_name"]
|
||||
pagination_handler.validate(max_hits)
|
||||
pagination = pagination_handler.pagination
|
||||
else:
|
||||
channel_info = False
|
||||
pagination = False
|
||||
|
||||
context = {
|
||||
"playlist_name": playlist_name,
|
||||
"channel_info": channel_info,
|
||||
"videos": videos_hits,
|
||||
"max_hits": max_hits,
|
||||
"pagination": pagination,
|
||||
"title": "Playlist: " + playlist_name,
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
@staticmethod
|
||||
def build_data(pagination_handler, playlist_id_detail, view_config):
|
||||
"""build data query for es"""
|
||||
sort_by = view_config["sort_by"]
|
||||
|
||||
# overwrite sort_by to match key
|
||||
if sort_by == "views":
|
||||
sort_by = "stats.view_count"
|
||||
elif sort_by == "likes":
|
||||
sort_by = "stats.like_count"
|
||||
elif sort_by == "downloaded":
|
||||
sort_by = "date_downloaded"
|
||||
|
||||
data = {
|
||||
"size": pagination_handler.pagination["page_size"],
|
||||
"from": pagination_handler.pagination["page_from"],
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"term": {
|
||||
"playlist.playlist_id": {
|
||||
"value": playlist_id_detail
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"sort": [{"playlist_position.playlist_index": {"order": "asc"}}],
|
||||
}
|
||||
if view_config["hide_watched"]:
|
||||
to_append = {"term": {"player.watched": {"value": False}}}
|
||||
data["query"]["bool"]["must"].append(to_append)
|
||||
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def get_channel_info(channel_id_detail, es_url):
|
||||
"""get channel info from channel index if no videos"""
|
||||
url = f"{es_url}/ta_channel/_doc/{channel_id_detail}"
|
||||
data = False
|
||||
search = SearchHandler(url, data)
|
||||
channel_data = search.get_data()
|
||||
channel_info = channel_data[0]["source"]
|
||||
channel_name = channel_info["channel_name"]
|
||||
return channel_info, channel_name
|
||||
|
||||
|
||||
class PlaylistView(View):
|
||||
"""resolves to /playlist/
|
||||
show all playlists indexed
|
||||
|
Loading…
Reference in New Issue
Block a user