diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py
index 8533585b..29ee565c 100644
--- a/tubearchivist/home/views.py
+++ b/tubearchivist/home/views.py
@@ -31,7 +31,7 @@ from home.src.frontend.forms import (
UserSettingsForm,
)
from home.src.frontend.searching import SearchHandler
-from home.src.index.channel import channel_overwrites
+from home.src.index.channel import YoutubeChannel, channel_overwrites
from home.src.index.generic import Pagination
from home.src.index.playlist import YoutubePlaylist
from home.src.ta.config import AppConfig, ScheduleBuilder
@@ -387,6 +387,15 @@ class DownloadView(ArchivistResultsView):
{"term": {"channel_id": {"value": channel_filter}}}
)
+ channel = YoutubeChannel(channel_filter)
+ channel.get_from_es()
+ self.context.update(
+ {
+ "channel_filter_id": channel_filter,
+ "channel_filter_name": channel.json_data["channel_name"],
+ }
+ )
+
self.data.update(
{
"query": {"bool": {"must": must_list}},
@@ -423,7 +432,37 @@ class DownloadView(ArchivistResultsView):
return redirect("downloads", permanent=True)
-class ChannelIdView(ArchivistResultsView):
+class ChannelIdBaseView(ArchivistResultsView):
+ """base class for all channel-id views"""
+
+ def get_channel_meta(self, channel_id):
+ """get metadata for channel"""
+ path = f"ta_channel/_doc/{channel_id}"
+ response, _ = ElasticWrap(path).get()
+ channel_info = SearchProcess(response).process()
+
+ return channel_info
+
+ def channel_has_pending(self, channel_id):
+ """check if channel has pending videos in queue"""
+ path = "ta_download/_search"
+ data = {
+ "size": 1,
+ "query": {
+ "bool": {
+ "must": [
+ {"term": {"status": {"value": "pending"}}},
+ {"term": {"channel_id": {"value": channel_id}}},
+ ]
+ }
+ },
+ }
+ response, _ = ElasticWrap(path).get(data=data)
+
+ self.context.update({"has_pending": bool(response["hits"]["hits"])})
+
+
+class ChannelIdView(ChannelIdBaseView):
"""resolves to /channel//
display single channel page from channel_id
"""
@@ -437,6 +476,7 @@ class ChannelIdView(ArchivistResultsView):
self._update_view_data(channel_id)
self.find_results()
self.match_progress()
+ self.channel_has_pending(channel_id)
if self.context["results"]:
channel_info = self.context["results"][0]["source"]["channel"]
@@ -487,7 +527,7 @@ class ChannelIdView(ArchivistResultsView):
return redirect("channel_id", channel_id, permanent=True)
-class ChannelIdAboutView(ArchivistResultsView):
+class ChannelIdAboutView(ChannelIdBaseView):
"""resolves to /channel//about/
show metadata, handle per channel conf
"""
@@ -497,6 +537,7 @@ class ChannelIdAboutView(ArchivistResultsView):
def get(self, request, channel_id):
"""handle get request"""
self.initiate_vars(request)
+ self.channel_has_pending(channel_id)
path = f"ta_channel/_doc/{channel_id}"
response, _ = ElasticWrap(path).get()
@@ -530,7 +571,7 @@ class ChannelIdAboutView(ArchivistResultsView):
return redirect("channel_id_about", channel_id, permanent=True)
-class ChannelIdPlaylistView(ArchivistResultsView):
+class ChannelIdPlaylistView(ChannelIdBaseView):
"""resolves to /channel//playlist/
show all playlists of channel
"""
@@ -543,8 +584,9 @@ class ChannelIdPlaylistView(ArchivistResultsView):
self.initiate_vars(request)
self._update_view_data(channel_id)
self.find_results()
+ self.channel_has_pending(channel_id)
- channel_info = self._get_channel_meta(channel_id)
+ channel_info = self.get_channel_meta(channel_id)
channel_name = channel_info["channel_name"]
self.context.update(
{
@@ -565,14 +607,6 @@ class ChannelIdPlaylistView(ArchivistResultsView):
self.data["query"] = {"bool": {"must": must_list}}
- def _get_channel_meta(self, channel_id):
- """get metadata for channel"""
- path = f"ta_channel/_doc/{channel_id}"
- response, _ = ElasticWrap(path).get()
- channel_info = SearchProcess(response).process()
-
- return channel_info
-
class ChannelView(ArchivistResultsView):
"""resolves to /channel/