2021-09-05 17:10:14 +00:00
|
|
|
"""
|
|
|
|
Functionality:
|
|
|
|
- all views for home app
|
2021-09-18 10:28:16 +00:00
|
|
|
- process post data received from frontend via ajax
|
2021-09-05 17:10:14 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import json
|
2021-09-18 13:02:54 +00:00
|
|
|
import urllib.parse
|
2021-09-05 17:10:14 +00:00
|
|
|
from time import sleep
|
|
|
|
|
2021-10-21 12:33:27 +00:00
|
|
|
from django import forms
|
|
|
|
from django.contrib.auth import login
|
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
2021-09-05 17:10:14 +00:00
|
|
|
from django.http import JsonResponse
|
2021-09-18 13:02:54 +00:00
|
|
|
from django.shortcuts import redirect, render
|
2021-09-05 17:10:14 +00:00
|
|
|
from django.utils.http import urlencode
|
2021-09-18 13:02:54 +00:00
|
|
|
from django.views import View
|
2021-10-29 16:43:19 +00:00
|
|
|
from home.forms import (
|
2021-10-30 07:14:16 +00:00
|
|
|
AddToQueueForm,
|
2021-10-29 16:43:19 +00:00
|
|
|
ApplicationSettingsForm,
|
2021-10-30 06:19:16 +00:00
|
|
|
ChannelSearchForm,
|
2021-10-29 16:43:19 +00:00
|
|
|
CustomAuthForm,
|
2021-10-30 08:00:10 +00:00
|
|
|
SubscribeToChannelForm,
|
2021-10-29 16:43:19 +00:00
|
|
|
UserSettingsForm,
|
2021-10-30 06:19:16 +00:00
|
|
|
VideoSearchForm,
|
2021-10-29 16:43:19 +00:00
|
|
|
)
|
2021-09-05 17:10:14 +00:00
|
|
|
from home.src.config import AppConfig
|
2021-09-18 13:02:54 +00:00
|
|
|
from home.src.download import ChannelSubscription, PendingList
|
2021-10-31 09:04:28 +00:00
|
|
|
from home.src.helper import RedisArchivist, RedisQueue, UrlListParser
|
2021-10-09 12:54:36 +00:00
|
|
|
from home.src.index import WatchState, YoutubeChannel, YoutubeVideo
|
2021-09-22 04:43:38 +00:00
|
|
|
from home.src.searching import Pagination, SearchForm, SearchHandler
|
2021-09-21 09:25:22 +00:00
|
|
|
from home.tasks import (
|
|
|
|
download_pending,
|
|
|
|
download_single,
|
|
|
|
extrac_dl,
|
2021-09-24 16:37:26 +00:00
|
|
|
kill_dl,
|
2021-11-01 09:42:07 +00:00
|
|
|
re_sync_thumbs,
|
2021-10-08 07:56:07 +00:00
|
|
|
rescan_filesystem,
|
2021-09-21 09:25:22 +00:00
|
|
|
run_backup,
|
|
|
|
run_manual_import,
|
|
|
|
run_restore_backup,
|
2021-10-30 08:00:10 +00:00
|
|
|
subscribe_to,
|
2021-09-21 09:25:22 +00:00
|
|
|
update_subscribed,
|
|
|
|
)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomeView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /
|
2021-09-09 09:45:46 +00:00
|
|
|
handle home page and video search post functionality
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
CONFIG = AppConfig().config
|
2021-09-21 09:25:22 +00:00
|
|
|
ES_URL = CONFIG["application"]["es_url"]
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
def get(self, request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""return home search results"""
|
2021-10-29 15:37:31 +00:00
|
|
|
user_id = request.user.id
|
|
|
|
view_config = self.read_config(user_id)
|
2021-09-05 17:10:14 +00:00
|
|
|
# handle search
|
2021-09-21 09:25:22 +00:00
|
|
|
search_get = request.GET.get("search", False)
|
2021-09-05 17:10:14 +00:00
|
|
|
if search_get:
|
|
|
|
search_encoded = urllib.parse.quote(search_get)
|
|
|
|
else:
|
|
|
|
search_encoded = False
|
|
|
|
# define page size
|
2021-09-21 09:25:22 +00:00
|
|
|
page_get = int(request.GET.get("page", 0))
|
2021-10-29 15:37:31 +00:00
|
|
|
pagination_handler = Pagination(
|
|
|
|
page_get, user_id, search_get=search_encoded
|
|
|
|
)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
url = self.ES_URL + "/ta_video/_search"
|
2021-09-05 17:10:14 +00:00
|
|
|
data = self.build_data(
|
2021-10-27 04:01:09 +00:00
|
|
|
pagination_handler,
|
2021-10-27 08:29:17 +00:00
|
|
|
view_config["sort_by"],
|
2021-10-27 04:01:09 +00:00
|
|
|
view_config["sort_order"],
|
|
|
|
search_get,
|
|
|
|
view_config["hide_watched"],
|
2021-09-05 17:10:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
search = SearchHandler(url, data)
|
|
|
|
videos_hits = search.get_data()
|
|
|
|
max_hits = search.max_hits
|
|
|
|
pagination_handler.validate(max_hits)
|
2021-10-30 06:19:16 +00:00
|
|
|
|
|
|
|
search_form = VideoSearchForm()
|
2021-09-05 17:10:14 +00:00
|
|
|
context = {
|
2021-10-30 06:19:16 +00:00
|
|
|
"search_form": search_form,
|
2021-09-21 09:25:22 +00:00
|
|
|
"videos": videos_hits,
|
|
|
|
"pagination": pagination_handler.pagination,
|
2021-10-27 08:29:17 +00:00
|
|
|
"sort_by": view_config["sort_by"],
|
|
|
|
"sort_order": view_config["sort_order"],
|
2021-10-27 04:01:09 +00:00
|
|
|
"hide_watched": view_config["hide_watched"],
|
|
|
|
"colors": view_config["colors"],
|
|
|
|
"view_style": view_config["view_style"],
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
2021-09-21 09:25:22 +00:00
|
|
|
return render(request, "home/home.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2021-10-27 08:29:17 +00:00
|
|
|
def build_data(
|
|
|
|
pagination_handler, sort_by, sort_order, search_get, hide_watched
|
|
|
|
):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""build the data dict for the search query"""
|
|
|
|
page_size = pagination_handler.pagination["page_size"]
|
|
|
|
page_from = pagination_handler.pagination["page_from"]
|
2021-10-27 08:29:17 +00:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
data = {
|
2021-09-21 09:25:22 +00:00
|
|
|
"size": page_size,
|
|
|
|
"from": page_from,
|
|
|
|
"query": {"match_all": {}},
|
2021-10-27 08:29:17 +00:00
|
|
|
"sort": [{sort_by: {"order": sort_order}}],
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
|
|
|
if hide_watched:
|
2021-09-21 09:25:22 +00:00
|
|
|
data["query"] = {"term": {"player.watched": {"value": False}}}
|
2021-09-05 17:10:14 +00:00
|
|
|
if search_get:
|
2021-10-27 08:29:17 +00:00
|
|
|
del data["sort"]
|
2021-09-05 17:10:14 +00:00
|
|
|
query = {
|
|
|
|
"multi_match": {
|
|
|
|
"query": search_get,
|
|
|
|
"fields": ["title", "channel.channel_name", "tags"],
|
|
|
|
"type": "cross_fields",
|
2021-09-21 09:25:22 +00:00
|
|
|
"operator": "and",
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-21 09:25:22 +00:00
|
|
|
data["query"] = query
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
@staticmethod
|
2021-10-29 04:45:13 +00:00
|
|
|
def read_config(user_id):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""read needed values from redis"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(user_id)
|
2021-10-29 04:45:13 +00:00
|
|
|
|
|
|
|
view_key = f"{user_id}:view:home"
|
|
|
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
|
|
|
if not view_style:
|
2021-10-29 16:43:19 +00:00
|
|
|
view_style = config_handler.config["default_view"]["home"]
|
2021-10-27 08:29:17 +00:00
|
|
|
|
2021-10-29 07:42:12 +00:00
|
|
|
sort_by = RedisArchivist().get_message(f"{user_id}:sort_by")["status"]
|
|
|
|
if not sort_by:
|
2021-10-29 16:43:19 +00:00
|
|
|
sort_by = config_handler.config["archive"]["sort_by"]
|
2021-10-29 07:42:12 +00:00
|
|
|
|
|
|
|
sort_order_key = f"{user_id}:sort_order"
|
|
|
|
sort_order = RedisArchivist().get_message(sort_order_key)["status"]
|
|
|
|
if not sort_order:
|
2021-10-29 16:43:19 +00:00
|
|
|
sort_order = config_handler.config["archive"]["sort_order"]
|
2021-10-27 08:29:17 +00:00
|
|
|
|
2021-10-29 07:02:21 +00:00
|
|
|
hide_watched_key = f"{user_id}:hide_watched"
|
|
|
|
hide_watched = RedisArchivist().get_message(hide_watched_key)["status"]
|
2021-10-27 04:01:09 +00:00
|
|
|
view_config = {
|
2021-10-29 16:43:19 +00:00
|
|
|
"colors": config_handler.colors,
|
2021-10-27 04:01:09 +00:00
|
|
|
"view_style": view_style,
|
2021-10-27 08:29:17 +00:00
|
|
|
"sort_by": sort_by,
|
2021-10-27 04:01:09 +00:00
|
|
|
"sort_order": sort_order,
|
|
|
|
"hide_watched": hide_watched,
|
|
|
|
}
|
|
|
|
return view_config
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def post(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle post from search form"""
|
2021-10-30 06:19:16 +00:00
|
|
|
search_form = VideoSearchForm(data=request.POST)
|
|
|
|
if search_form.is_valid():
|
|
|
|
search_query = request.POST.get("searchInput")
|
|
|
|
print(search_query)
|
|
|
|
search_url = "/?" + urlencode({"search": search_query})
|
|
|
|
return redirect(search_url, permanent=True)
|
|
|
|
|
|
|
|
return redirect("home")
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
2021-10-18 10:14:59 +00:00
|
|
|
class LoginView(View):
|
|
|
|
"""resolves to /login/
|
|
|
|
Greeting and login page
|
|
|
|
"""
|
|
|
|
|
2021-10-29 16:43:19 +00:00
|
|
|
@staticmethod
|
|
|
|
def get(request):
|
2021-10-18 10:14:59 +00:00
|
|
|
"""handle get requests"""
|
2021-10-24 08:34:00 +00:00
|
|
|
failed = bool(request.GET.get("failed"))
|
2021-10-29 16:43:19 +00:00
|
|
|
colors = AppConfig(request.user.id).colors
|
2021-10-21 12:33:27 +00:00
|
|
|
form = CustomAuthForm()
|
2021-10-24 08:34:00 +00:00
|
|
|
context = {"colors": colors, "form": form, "form_error": failed}
|
2021-10-18 10:14:59 +00:00
|
|
|
return render(request, "home/login.html", context)
|
|
|
|
|
2021-10-21 12:33:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def post(request):
|
|
|
|
"""handle login post request"""
|
|
|
|
form = AuthenticationForm(data=request.POST)
|
|
|
|
if form.is_valid():
|
2021-10-22 11:23:06 +00:00
|
|
|
next_url = request.POST.get("next") or "home"
|
2021-10-21 12:33:27 +00:00
|
|
|
user = form.get_user()
|
|
|
|
login(request, user)
|
2021-10-22 05:01:30 +00:00
|
|
|
return redirect(next_url)
|
2021-10-21 12:33:27 +00:00
|
|
|
|
2021-10-24 08:34:00 +00:00
|
|
|
return redirect("/login?failed=true")
|
2021-10-21 12:33:27 +00:00
|
|
|
|
2021-10-18 10:14:59 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
class AboutView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /about/
|
2021-09-05 17:10:14 +00:00
|
|
|
show helpful how to information
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle http get"""
|
2021-10-29 16:43:19 +00:00
|
|
|
colors = AppConfig(request.user.id).colors
|
2021-09-21 09:25:22 +00:00
|
|
|
context = {"title": "About", "colors": colors}
|
|
|
|
return render(request, "home/about.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DownloadView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /download/
|
2021-09-05 17:10:14 +00:00
|
|
|
takes POST for downloading youtube links
|
|
|
|
"""
|
|
|
|
|
2021-09-16 15:01:30 +00:00
|
|
|
def get(self, request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle get requests"""
|
2021-10-29 15:37:31 +00:00
|
|
|
user_id = request.user.id
|
|
|
|
view_config = self.read_config(user_id)
|
2021-09-16 15:01:30 +00:00
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
page_get = int(request.GET.get("page", 0))
|
2021-10-29 15:37:31 +00:00
|
|
|
pagination_handler = Pagination(page_get, user_id)
|
2021-09-16 15:01:30 +00:00
|
|
|
|
2021-10-29 04:45:13 +00:00
|
|
|
url = view_config["es_url"] + "/ta_download/_search"
|
|
|
|
data = self.build_data(
|
|
|
|
pagination_handler, view_config["show_ignored_only"]
|
|
|
|
)
|
2021-10-14 07:42:35 +00:00
|
|
|
search = SearchHandler(url, data)
|
2021-09-16 15:01:30 +00:00
|
|
|
|
|
|
|
videos_hits = search.get_data()
|
|
|
|
max_hits = search.max_hits
|
|
|
|
|
|
|
|
if videos_hits:
|
2021-09-28 09:53:45 +00:00
|
|
|
all_video_hits = [i["source"] for i in videos_hits]
|
2021-09-16 15:01:30 +00:00
|
|
|
pagination_handler.validate(max_hits)
|
|
|
|
pagination = pagination_handler.pagination
|
|
|
|
else:
|
2021-09-28 09:53:45 +00:00
|
|
|
all_video_hits = False
|
2021-09-16 15:01:30 +00:00
|
|
|
pagination = False
|
|
|
|
|
2021-10-30 07:14:16 +00:00
|
|
|
add_form = AddToQueueForm()
|
2021-09-05 17:10:14 +00:00
|
|
|
context = {
|
2021-10-30 07:14:16 +00:00
|
|
|
"add_form": add_form,
|
2021-09-28 09:53:45 +00:00
|
|
|
"all_video_hits": all_video_hits,
|
2021-09-21 09:25:22 +00:00
|
|
|
"max_hits": max_hits,
|
|
|
|
"pagination": pagination,
|
|
|
|
"title": "Downloads",
|
2021-10-29 04:45:13 +00:00
|
|
|
"colors": view_config["colors"],
|
|
|
|
"show_ignored_only": view_config["show_ignored_only"],
|
|
|
|
"view_style": view_config["view_style"],
|
|
|
|
}
|
|
|
|
return render(request, "home/downloads.html", context)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def read_config(user_id):
|
|
|
|
"""read config vars"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(user_id)
|
2021-10-29 04:45:13 +00:00
|
|
|
view_key = f"{user_id}:view:downloads"
|
|
|
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
|
|
|
if not view_style:
|
2021-10-29 16:43:19 +00:00
|
|
|
view_style = config_handler.config["default_view"]["downloads"]
|
2021-10-29 04:45:13 +00:00
|
|
|
|
2021-10-29 05:23:33 +00:00
|
|
|
ignored = RedisArchivist().get_message(f"{user_id}:show_ignored_only")
|
2021-10-29 04:45:13 +00:00
|
|
|
show_ignored_only = ignored["status"]
|
|
|
|
|
2021-10-29 16:43:19 +00:00
|
|
|
es_url = config_handler.config["application"]["es_url"]
|
2021-10-29 04:45:13 +00:00
|
|
|
|
|
|
|
view_config = {
|
|
|
|
"es_url": es_url,
|
2021-10-29 16:43:19 +00:00
|
|
|
"colors": config_handler.colors,
|
2021-10-02 11:37:22 +00:00
|
|
|
"view_style": view_style,
|
2021-10-29 05:23:33 +00:00
|
|
|
"show_ignored_only": show_ignored_only,
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
2021-10-29 04:45:13 +00:00
|
|
|
return view_config
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-09-16 15:01:30 +00:00
|
|
|
@staticmethod
|
2021-10-03 11:17:07 +00:00
|
|
|
def build_data(pagination_handler, show_ignored_only):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""build data dict for search"""
|
|
|
|
page_size = pagination_handler.pagination["page_size"]
|
|
|
|
page_from = pagination_handler.pagination["page_from"]
|
2021-10-03 11:17:07 +00:00
|
|
|
if show_ignored_only:
|
|
|
|
filter_view = "ignore"
|
|
|
|
else:
|
|
|
|
filter_view = "pending"
|
|
|
|
|
2021-09-16 15:01:30 +00:00
|
|
|
data = {
|
2021-09-21 09:25:22 +00:00
|
|
|
"size": page_size,
|
|
|
|
"from": page_from,
|
2021-09-28 09:53:45 +00:00
|
|
|
"query": {"term": {"status": {"value": filter_view}}},
|
2021-09-23 11:09:46 +00:00
|
|
|
"sort": [{"timestamp": {"order": "asc"}}],
|
2021-09-16 15:01:30 +00:00
|
|
|
}
|
|
|
|
return data
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
@staticmethod
|
|
|
|
def post(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle post requests"""
|
2021-10-30 07:14:16 +00:00
|
|
|
to_queue = AddToQueueForm(data=request.POST)
|
|
|
|
if to_queue.is_valid():
|
2021-10-31 09:04:28 +00:00
|
|
|
url_str = request.POST.get("vid_url")
|
|
|
|
print(url_str)
|
2021-09-23 03:50:44 +00:00
|
|
|
try:
|
2021-10-31 09:04:28 +00:00
|
|
|
youtube_ids = UrlListParser(url_str).process_list()
|
2021-09-23 03:50:44 +00:00
|
|
|
except ValueError:
|
2021-09-10 08:00:10 +00:00
|
|
|
# failed to process
|
2021-10-31 09:04:28 +00:00
|
|
|
print(f"failed to parse: {url_str}")
|
2021-09-10 08:00:10 +00:00
|
|
|
mess_dict = {
|
|
|
|
"status": "downloading",
|
|
|
|
"level": "error",
|
2021-09-21 09:25:22 +00:00
|
|
|
"title": "Failed to extract links.",
|
2021-09-23 03:50:44 +00:00
|
|
|
"message": "Not a video, channel or playlist ID or URL",
|
2021-09-10 08:00:10 +00:00
|
|
|
}
|
2021-09-28 03:33:00 +00:00
|
|
|
RedisArchivist().set_message("progress:download", mess_dict)
|
2021-09-21 09:25:22 +00:00
|
|
|
return redirect("downloads")
|
2021-09-10 08:00:10 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
print(youtube_ids)
|
|
|
|
extrac_dl.delay(youtube_ids)
|
|
|
|
|
|
|
|
sleep(2)
|
2021-09-21 09:25:22 +00:00
|
|
|
return redirect("downloads", permanent=True)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChannelIdView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /channel/<channel-id>/
|
2021-09-09 09:45:46 +00:00
|
|
|
display single channel page from channel_id
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
def get(self, request, channel_id_detail):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""get method"""
|
2021-10-28 11:00:59 +00:00
|
|
|
# es_url, colors, view_style = self.read_config()
|
2021-10-29 07:02:21 +00:00
|
|
|
view_config = self.read_config(user_id=request.user.id)
|
2021-10-28 11:00:59 +00:00
|
|
|
context = self.get_channel_videos(
|
|
|
|
request, channel_id_detail, view_config
|
|
|
|
)
|
|
|
|
context.update(view_config)
|
2021-09-21 09:25:22 +00:00
|
|
|
return render(request, "home/channel_id.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2021-10-29 07:02:21 +00:00
|
|
|
def read_config(user_id):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""read config file"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(user_id)
|
|
|
|
config = config_handler.config
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-31 09:15:33 +00:00
|
|
|
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"]
|
|
|
|
|
2021-10-29 07:42:12 +00:00
|
|
|
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"]
|
|
|
|
|
2021-10-29 07:02:21 +00:00
|
|
|
hide_watched_key = f"{user_id}:hide_watched"
|
|
|
|
hide_watched = RedisArchivist().get_message(hide_watched_key)["status"]
|
2021-10-28 11:00:59 +00:00
|
|
|
|
|
|
|
view_config = {
|
2021-10-29 16:43:19 +00:00
|
|
|
"colors": config_handler.colors,
|
2021-10-28 11:00:59 +00:00
|
|
|
"es_url": config["application"]["es_url"],
|
2021-10-31 09:15:33 +00:00
|
|
|
"view_style": view_style,
|
2021-10-28 11:00:59 +00:00
|
|
|
"sort_by": sort_by,
|
|
|
|
"sort_order": sort_order,
|
|
|
|
"hide_watched": hide_watched,
|
|
|
|
}
|
|
|
|
return view_config
|
|
|
|
|
|
|
|
def get_channel_videos(self, request, channel_id_detail, view_config):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""get channel from video index"""
|
|
|
|
page_get = int(request.GET.get("page", 0))
|
2021-10-29 15:37:31 +00:00
|
|
|
pagination_handler = Pagination(page_get, request.user.id)
|
2021-09-05 17:10:14 +00:00
|
|
|
# get data
|
2021-10-28 11:00:59 +00:00
|
|
|
url = view_config["es_url"] + "/ta_video/_search"
|
|
|
|
data = self.build_data(
|
|
|
|
pagination_handler, channel_id_detail, view_config
|
|
|
|
)
|
2021-09-05 17:10:14 +00:00
|
|
|
search = SearchHandler(url, data)
|
|
|
|
videos_hits = search.get_data()
|
|
|
|
max_hits = search.max_hits
|
|
|
|
if max_hits:
|
2021-09-21 09:25:22 +00:00
|
|
|
channel_info = videos_hits[0]["source"]["channel"]
|
|
|
|
channel_name = channel_info["channel_name"]
|
2021-09-05 17:10:14 +00:00
|
|
|
pagination_handler.validate(max_hits)
|
|
|
|
pagination = pagination_handler.pagination
|
|
|
|
else:
|
|
|
|
# get details from channel index when when no hits
|
|
|
|
channel_info, channel_name = self.get_channel_info(
|
2021-10-28 11:00:59 +00:00
|
|
|
channel_id_detail, view_config["es_url"]
|
2021-09-05 17:10:14 +00:00
|
|
|
)
|
|
|
|
videos_hits = False
|
|
|
|
pagination = False
|
|
|
|
|
|
|
|
context = {
|
2021-09-21 09:25:22 +00:00
|
|
|
"channel_info": channel_info,
|
|
|
|
"videos": videos_hits,
|
|
|
|
"max_hits": max_hits,
|
|
|
|
"pagination": pagination,
|
|
|
|
"title": "Channel: " + channel_name,
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
@staticmethod
|
2021-10-28 11:00:59 +00:00
|
|
|
def build_data(pagination_handler, channel_id_detail, view_config):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""build data dict for search"""
|
2021-10-28 11:00:59 +00:00
|
|
|
sort_by = view_config["sort_by"]
|
|
|
|
sort_order = view_config["sort_order"]
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
data = {
|
2021-10-28 11:00:59 +00:00
|
|
|
"size": pagination_handler.pagination["page_size"],
|
|
|
|
"from": pagination_handler.pagination["page_from"],
|
2021-09-05 17:10:14 +00:00
|
|
|
"query": {
|
2021-10-28 11:00:59 +00:00
|
|
|
"bool": {
|
|
|
|
"must": [
|
|
|
|
{
|
|
|
|
"term": {
|
|
|
|
"channel.channel_id": {
|
|
|
|
"value": channel_id_detail
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2021-09-05 17:10:14 +00:00
|
|
|
},
|
2021-10-28 11:00:59 +00:00
|
|
|
"sort": [{sort_by: {"order": sort_order}}],
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
2021-10-28 11:00:59 +00:00
|
|
|
if view_config["hide_watched"]:
|
|
|
|
to_append = {"term": {"player.watched": {"value": False}}}
|
|
|
|
data["query"]["bool"]["must"].append(to_append)
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
return data
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_channel_info(channel_id_detail, es_url):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""get channel info from channel index if no videos"""
|
|
|
|
url = f"{es_url}/ta_channel/_doc/{channel_id_detail}"
|
2021-09-05 17:10:14 +00:00
|
|
|
data = False
|
|
|
|
search = SearchHandler(url, data)
|
|
|
|
channel_data = search.get_data()
|
2021-09-21 09:25:22 +00:00
|
|
|
channel_info = channel_data[0]["source"]
|
|
|
|
channel_name = channel_info["channel_name"]
|
2021-09-05 17:10:14 +00:00
|
|
|
return channel_info, channel_name
|
|
|
|
|
|
|
|
|
|
|
|
class ChannelView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /channel/
|
2021-09-09 09:45:46 +00:00
|
|
|
handle functionality for channel overview page, subscribe to channel,
|
|
|
|
search as you type for channel name
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
def get(self, request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle http get requests"""
|
2021-10-29 06:35:37 +00:00
|
|
|
user_id = request.user.id
|
|
|
|
view_config = self.read_config(user_id=user_id)
|
2021-09-21 09:25:22 +00:00
|
|
|
page_get = int(request.GET.get("page", 0))
|
2021-10-29 15:37:31 +00:00
|
|
|
pagination_handler = Pagination(page_get, user_id)
|
2021-10-30 08:00:10 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
# get
|
2021-10-29 06:35:37 +00:00
|
|
|
url = view_config["es_url"] + "/ta_channel/_search"
|
2021-09-05 17:10:14 +00:00
|
|
|
data = {
|
2021-10-30 08:00:10 +00:00
|
|
|
"size": pagination_handler.pagination["page_size"],
|
|
|
|
"from": pagination_handler.pagination["page_from"],
|
2021-09-21 09:25:22 +00:00
|
|
|
"query": {"match_all": {}},
|
|
|
|
"sort": [{"channel_name.keyword": {"order": "asc"}}],
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
2021-10-29 06:35:37 +00:00
|
|
|
if view_config["show_subed_only"]:
|
2021-09-21 09:25:22 +00:00
|
|
|
data["query"] = {"term": {"channel_subscribed": {"value": True}}}
|
2021-09-05 17:10:14 +00:00
|
|
|
search = SearchHandler(url, data)
|
|
|
|
channel_hits = search.get_data()
|
|
|
|
pagination_handler.validate(search.max_hits)
|
2021-10-30 06:19:16 +00:00
|
|
|
search_form = ChannelSearchForm()
|
2021-10-30 08:00:10 +00:00
|
|
|
subscribe_form = SubscribeToChannelForm()
|
2021-09-05 17:10:14 +00:00
|
|
|
context = {
|
2021-10-30 06:19:16 +00:00
|
|
|
"search_form": search_form,
|
2021-10-30 08:00:10 +00:00
|
|
|
"subscribe_form": subscribe_form,
|
2021-09-21 09:25:22 +00:00
|
|
|
"channels": channel_hits,
|
2021-10-30 08:00:10 +00:00
|
|
|
"max_hits": search.max_hits,
|
2021-09-21 09:25:22 +00:00
|
|
|
"pagination": pagination_handler.pagination,
|
2021-10-29 06:35:37 +00:00
|
|
|
"show_subed_only": view_config["show_subed_only"],
|
2021-09-21 09:25:22 +00:00
|
|
|
"title": "Channels",
|
2021-10-29 06:35:37 +00:00
|
|
|
"colors": view_config["colors"],
|
|
|
|
"view_style": view_config["view_style"],
|
2021-10-31 10:48:56 +00:00
|
|
|
"running": view_config["running"],
|
2021-09-05 17:10:14 +00:00
|
|
|
}
|
2021-09-21 09:25:22 +00:00
|
|
|
return render(request, "home/channel.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2021-10-29 04:45:13 +00:00
|
|
|
def read_config(user_id):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""read config file"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(user_id)
|
2021-10-29 04:45:13 +00:00
|
|
|
view_key = f"{user_id}:view:channel"
|
|
|
|
view_style = RedisArchivist().get_message(view_key)["status"]
|
2021-10-31 10:48:56 +00:00
|
|
|
running = RedisArchivist().get_message("progress:subscribe")["status"]
|
2021-10-29 04:45:13 +00:00
|
|
|
if not view_style:
|
2021-10-29 16:43:19 +00:00
|
|
|
view_style = config_handler.config["default_view"]["channel"]
|
2021-10-29 04:45:13 +00:00
|
|
|
|
2021-10-29 06:35:37 +00:00
|
|
|
sub_only_key = f"{user_id}:show_subed_only"
|
|
|
|
show_subed_only = RedisArchivist().get_message(sub_only_key)["status"]
|
|
|
|
|
|
|
|
view_config = {
|
2021-10-29 16:43:19 +00:00
|
|
|
"es_url": config_handler.config["application"]["es_url"],
|
2021-10-29 06:35:37 +00:00
|
|
|
"view_style": view_style,
|
|
|
|
"show_subed_only": show_subed_only,
|
2021-10-29 16:43:19 +00:00
|
|
|
"colors": config_handler.colors,
|
2021-10-31 10:48:56 +00:00
|
|
|
"running": running,
|
2021-10-29 06:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view_config
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-30 08:00:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def post(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle http post requests"""
|
2021-10-30 08:00:10 +00:00
|
|
|
subscribe_form = SubscribeToChannelForm(data=request.POST)
|
|
|
|
if subscribe_form.is_valid():
|
2021-10-31 10:48:56 +00:00
|
|
|
RedisArchivist().set_message(
|
|
|
|
"progress:subscribe", {"status": "subscribing"}
|
|
|
|
)
|
2021-10-31 09:04:28 +00:00
|
|
|
url_str = request.POST.get("subscribe")
|
2021-10-31 10:48:56 +00:00
|
|
|
print(url_str)
|
|
|
|
subscribe_to.delay(url_str)
|
2021-09-15 14:09:46 +00:00
|
|
|
|
|
|
|
sleep(1)
|
2021-09-21 09:25:22 +00:00
|
|
|
return redirect("channel", permanent=True)
|
2021-09-15 14:09:46 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-11-08 07:52:46 +00:00
|
|
|
class PlaylistView(View):
|
|
|
|
"""resolves to /playlist/
|
|
|
|
show all playlists indexed
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
"""handle http get requests"""
|
|
|
|
view_config = self.read_config(user_id=request.user.id)
|
|
|
|
context = {"title": "Playlists", "colors": view_config["colors"]}
|
|
|
|
return render(request, "home/playlist.html", context)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def read_config(user_id):
|
|
|
|
"""read config file"""
|
|
|
|
config_handler = AppConfig(user_id)
|
|
|
|
view_config = {
|
|
|
|
"es_url": config_handler.config["application"]["es_url"],
|
|
|
|
"colors": config_handler.colors,
|
|
|
|
}
|
|
|
|
return view_config
|
|
|
|
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
class VideoView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /video/<video-id>/
|
2021-09-09 09:45:46 +00:00
|
|
|
display details about a single video
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
def get(self, request, video_id):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""get single video"""
|
2021-10-29 16:43:19 +00:00
|
|
|
es_url, colors = self.read_config(user_id=request.user.id)
|
2021-09-21 09:25:22 +00:00
|
|
|
url = f"{es_url}/ta_video/_doc/{video_id}"
|
2021-09-05 17:10:14 +00:00
|
|
|
data = None
|
|
|
|
look_up = SearchHandler(url, data)
|
|
|
|
video_hit = look_up.get_data()
|
2021-09-21 09:25:22 +00:00
|
|
|
video_data = video_hit[0]["source"]
|
2021-10-10 09:09:02 +00:00
|
|
|
try:
|
|
|
|
rating = video_data["stats"]["average_rating"]
|
|
|
|
video_data["stats"]["average_rating"] = self.star_creator(rating)
|
|
|
|
except KeyError:
|
|
|
|
video_data["stats"]["average_rating"] = False
|
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
video_title = video_data["title"]
|
|
|
|
context = {"video": video_data, "title": video_title, "colors": colors}
|
|
|
|
return render(request, "home/video.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2021-10-29 16:43:19 +00:00
|
|
|
def read_config(user_id):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""read config file"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(user_id)
|
|
|
|
es_url = config_handler.config["application"]["es_url"]
|
|
|
|
colors = config_handler.colors
|
2021-09-05 17:10:14 +00:00
|
|
|
return es_url, colors
|
|
|
|
|
2021-10-10 09:09:02 +00:00
|
|
|
@staticmethod
|
|
|
|
def star_creator(rating):
|
|
|
|
"""convert rating float to stars"""
|
|
|
|
stars = []
|
|
|
|
for _ in range(1, 6):
|
|
|
|
if rating >= 0.75:
|
|
|
|
stars.append("full")
|
|
|
|
elif 0.25 < rating < 0.75:
|
|
|
|
stars.append("half")
|
|
|
|
else:
|
|
|
|
stars.append("empty")
|
|
|
|
rating = rating - 1
|
|
|
|
return stars
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
class SettingsView(View):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""resolves to /settings/
|
2021-09-09 09:45:46 +00:00
|
|
|
handle the settings page, display current settings,
|
|
|
|
take post request from the form to update settings
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""read and display current settings"""
|
2021-10-29 16:43:19 +00:00
|
|
|
config_handler = AppConfig(request.user.id)
|
|
|
|
colors = config_handler.colors
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-29 15:37:31 +00:00
|
|
|
user_form = UserSettingsForm()
|
|
|
|
app_form = ApplicationSettingsForm()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"title": "Settings",
|
2021-10-29 16:43:19 +00:00
|
|
|
"config": config_handler.config,
|
2021-10-29 15:37:31 +00:00
|
|
|
"colors": colors,
|
|
|
|
"user_form": user_form,
|
|
|
|
"app_form": app_form,
|
|
|
|
}
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
return render(request, "home/settings.html", context)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def post(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle form post to update settings"""
|
2021-10-29 15:37:31 +00:00
|
|
|
|
|
|
|
form_response = forms.Form(request.POST)
|
|
|
|
if form_response.is_valid():
|
|
|
|
form_post = dict(request.POST)
|
|
|
|
print(form_post)
|
|
|
|
del form_post["csrfmiddlewaretoken"]
|
|
|
|
config_handler = AppConfig()
|
|
|
|
if "application-settings" in form_post:
|
|
|
|
del form_post["application-settings"]
|
|
|
|
config_handler.update_config(form_post)
|
|
|
|
elif "user-settings" in form_post:
|
|
|
|
del form_post["user-settings"]
|
|
|
|
config_handler.set_user_config(form_post, request.user.id)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
return redirect("settings", permanent=True)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def progress(request):
|
|
|
|
# pylint: disable=unused-argument
|
2021-09-21 09:25:22 +00:00
|
|
|
"""endpoint for download progress ajax calls"""
|
2021-09-05 17:10:14 +00:00
|
|
|
config = AppConfig().config
|
2021-09-21 09:25:22 +00:00
|
|
|
cache_dir = config["application"]["cache_dir"]
|
2021-09-28 03:33:00 +00:00
|
|
|
json_data = RedisArchivist().get_dl_message(cache_dir)
|
2021-09-05 17:10:14 +00:00
|
|
|
return JsonResponse(json_data)
|
|
|
|
|
|
|
|
|
|
|
|
def process(request):
|
2021-09-21 09:25:22 +00:00
|
|
|
"""handle all the buttons calls via POST ajax"""
|
|
|
|
if request.method == "POST":
|
2021-10-29 04:45:13 +00:00
|
|
|
current_user = request.user.id
|
2021-09-05 17:10:14 +00:00
|
|
|
post_dict = json.loads(request.body.decode())
|
2021-10-29 04:45:13 +00:00
|
|
|
post_handler = PostData(post_dict, current_user)
|
2021-09-22 04:43:38 +00:00
|
|
|
if post_handler.to_exec:
|
2021-09-05 17:10:14 +00:00
|
|
|
task_result = post_handler.run_task()
|
|
|
|
return JsonResponse(task_result)
|
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
return JsonResponse({"success": False})
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PostData:
|
2021-09-22 04:43:38 +00:00
|
|
|
"""
|
|
|
|
map frontend http post values to backend funcs
|
|
|
|
handover long running tasks to celery
|
|
|
|
"""
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-29 04:45:13 +00:00
|
|
|
def __init__(self, post_dict, current_user):
|
2021-09-05 17:10:14 +00:00
|
|
|
self.post_dict = post_dict
|
2021-09-22 04:43:38 +00:00
|
|
|
self.to_exec, self.exec_val = list(post_dict.items())[0]
|
2021-10-29 04:45:13 +00:00
|
|
|
self.current_user = current_user
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
def run_task(self):
|
2021-09-22 04:43:38 +00:00
|
|
|
"""execute and return task result"""
|
|
|
|
to_exec = self.exec_map()
|
|
|
|
task_result = to_exec()
|
|
|
|
return task_result
|
|
|
|
|
|
|
|
def exec_map(self):
|
|
|
|
"""map dict key and return function to execute"""
|
|
|
|
exec_map = {
|
|
|
|
"watched": self.watched,
|
2021-10-07 16:38:17 +00:00
|
|
|
"un_watched": self.un_watched,
|
2021-10-01 07:42:17 +00:00
|
|
|
"change_view": self.change_view,
|
2021-09-22 04:43:38 +00:00
|
|
|
"rescan_pending": self.rescan_pending,
|
|
|
|
"ignore": self.ignore,
|
|
|
|
"dl_pending": self.dl_pending,
|
2021-09-24 11:03:22 +00:00
|
|
|
"queue": self.queue_handler,
|
2021-09-22 04:43:38 +00:00
|
|
|
"unsubscribe": self.unsubscribe,
|
|
|
|
"sort_order": self.sort_order,
|
|
|
|
"hide_watched": self.hide_watched,
|
|
|
|
"show_subed_only": self.show_subed_only,
|
|
|
|
"dlnow": self.dlnow,
|
2021-09-28 09:53:45 +00:00
|
|
|
"show_ignored_only": self.show_ignored_only,
|
|
|
|
"forgetIgnore": self.forget_ignore,
|
|
|
|
"addSingle": self.add_single,
|
2021-09-22 04:43:38 +00:00
|
|
|
"manual-import": self.manual_import,
|
2021-11-01 09:42:07 +00:00
|
|
|
"re-embed": self.re_embed,
|
2021-09-22 04:43:38 +00:00
|
|
|
"db-backup": self.db_backup,
|
|
|
|
"db-restore": self.db_restore,
|
2021-10-08 07:56:07 +00:00
|
|
|
"fs-rescan": self.fs_rescan,
|
2021-09-22 04:43:38 +00:00
|
|
|
"channel-search": self.channel_search,
|
2021-10-08 09:18:01 +00:00
|
|
|
"delete-video": self.delete_video,
|
2021-10-09 12:54:36 +00:00
|
|
|
"delete-channel": self.delete_channel,
|
2021-09-22 04:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return exec_map[self.to_exec]
|
|
|
|
|
|
|
|
def watched(self):
|
|
|
|
"""mark as watched"""
|
|
|
|
WatchState(self.exec_val).mark_as_watched()
|
2021-09-21 09:25:22 +00:00
|
|
|
return {"success": True}
|
2021-10-07 16:38:17 +00:00
|
|
|
|
|
|
|
def un_watched(self):
|
|
|
|
"""mark as unwatched"""
|
|
|
|
WatchState(self.exec_val).mark_as_unwatched()
|
|
|
|
return {"success": True}
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-01 07:42:17 +00:00
|
|
|
def change_view(self):
|
|
|
|
"""process view changes in home, channel, and downloads"""
|
|
|
|
origin, new_view = self.exec_val.split(":")
|
2021-10-29 04:45:13 +00:00
|
|
|
key = f"{self.current_user}:view:{origin}"
|
|
|
|
print(f"change view: {key} to {new_view}")
|
|
|
|
RedisArchivist().set_message(key, {"status": new_view}, expire=False)
|
2021-10-01 07:42:17 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def rescan_pending():
|
|
|
|
"""look for new items in subscribed channels"""
|
|
|
|
print("rescan subscribed channels")
|
|
|
|
update_subscribed.delay()
|
|
|
|
return {"success": True}
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
def ignore(self):
|
|
|
|
"""ignore from download queue"""
|
2021-09-24 09:58:05 +00:00
|
|
|
id_to_ignore = self.exec_val
|
|
|
|
print("ignore video " + id_to_ignore)
|
2021-09-22 04:43:38 +00:00
|
|
|
handler = PendingList()
|
2021-09-24 09:58:05 +00:00
|
|
|
handler.ignore_from_pending([id_to_ignore])
|
|
|
|
# also clear from redis queue
|
|
|
|
RedisQueue("dl_queue").clear_item(id_to_ignore)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def dl_pending():
|
|
|
|
"""start the download queue"""
|
|
|
|
print("download pending")
|
2021-09-24 16:37:26 +00:00
|
|
|
running = download_pending.delay()
|
|
|
|
task_id = running.id
|
|
|
|
print("set task id: " + task_id)
|
2021-09-28 03:33:00 +00:00
|
|
|
RedisArchivist().set_message("dl_queue_id", task_id, expire=False)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-24 11:03:22 +00:00
|
|
|
def queue_handler(self):
|
|
|
|
"""queue controls from frontend"""
|
|
|
|
to_execute = self.exec_val
|
|
|
|
if to_execute == "stop":
|
|
|
|
print("stopping download queue")
|
|
|
|
RedisQueue("dl_queue").clear()
|
2021-09-25 08:35:36 +00:00
|
|
|
elif to_execute == "kill":
|
2021-09-28 03:33:00 +00:00
|
|
|
task_id = RedisArchivist().get_message("dl_queue_id")
|
2021-10-11 09:11:30 +00:00
|
|
|
if not isinstance(task_id, str):
|
2021-10-11 08:26:31 +00:00
|
|
|
task_id = False
|
|
|
|
else:
|
|
|
|
print("brutally killing " + task_id)
|
2021-09-25 08:35:36 +00:00
|
|
|
kill_dl(task_id)
|
2021-09-24 11:03:22 +00:00
|
|
|
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
def unsubscribe(self):
|
|
|
|
"""unsubscribe from channel"""
|
|
|
|
channel_id_unsub = self.exec_val
|
|
|
|
print("unsubscribe from " + channel_id_unsub)
|
|
|
|
ChannelSubscription().change_subscribe(
|
|
|
|
channel_id_unsub, channel_subscribed=False
|
|
|
|
)
|
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def sort_order(self):
|
|
|
|
"""change the sort between published to downloaded"""
|
2021-10-29 07:42:12 +00:00
|
|
|
sort_order = {"status": self.exec_val}
|
|
|
|
if self.exec_val in ["asc", "desc"]:
|
2021-10-27 08:29:17 +00:00
|
|
|
RedisArchivist().set_message(
|
2021-10-29 07:42:12 +00:00
|
|
|
f"{self.current_user}:sort_order", sort_order, expire=False
|
2021-10-27 08:29:17 +00:00
|
|
|
)
|
|
|
|
else:
|
2021-10-29 07:42:12 +00:00
|
|
|
RedisArchivist().set_message(
|
|
|
|
f"{self.current_user}:sort_by", sort_order, expire=False
|
|
|
|
)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def hide_watched(self):
|
|
|
|
"""toggle if to show watched vids or not"""
|
2021-10-29 07:02:21 +00:00
|
|
|
key = f"{self.current_user}:hide_watched"
|
|
|
|
message = {"status": bool(int(self.exec_val))}
|
|
|
|
print(f"toggle {key}: {message}")
|
|
|
|
RedisArchivist().set_message(key, message, expire=False)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def show_subed_only(self):
|
|
|
|
"""show or hide subscribed channels only on channels page"""
|
2021-10-29 06:35:37 +00:00
|
|
|
key = f"{self.current_user}:show_subed_only"
|
|
|
|
message = {"status": bool(int(self.exec_val))}
|
2021-10-29 07:02:21 +00:00
|
|
|
print(f"toggle {key}: {message}")
|
2021-10-29 06:35:37 +00:00
|
|
|
RedisArchivist().set_message(key, message, expire=False)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def dlnow(self):
|
|
|
|
"""start downloading single vid now"""
|
|
|
|
youtube_id = self.exec_val
|
|
|
|
print("downloading: " + youtube_id)
|
2021-09-25 10:40:33 +00:00
|
|
|
running = download_single.delay(youtube_id=youtube_id)
|
|
|
|
task_id = running.id
|
|
|
|
print("set task id: " + task_id)
|
2021-09-28 03:33:00 +00:00
|
|
|
RedisArchivist().set_message("dl_queue_id", task_id, expire=False)
|
2021-09-22 04:43:38 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-28 09:53:45 +00:00
|
|
|
def show_ignored_only(self):
|
|
|
|
"""switch view on /downloads/ to show ignored only"""
|
|
|
|
show_value = self.exec_val
|
2021-10-29 05:23:33 +00:00
|
|
|
key = f"{self.current_user}:show_ignored_only"
|
|
|
|
value = {"status": show_value}
|
2021-10-03 11:17:07 +00:00
|
|
|
print(f"Filter download view ignored only: {show_value}")
|
2021-10-29 05:23:33 +00:00
|
|
|
RedisArchivist().set_message(key, value, expire=False)
|
2021-09-28 09:53:45 +00:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def forget_ignore(self):
|
|
|
|
"""delete from ta_download index"""
|
|
|
|
youtube_id = self.exec_val
|
|
|
|
print("forgetting from download index: " + youtube_id)
|
|
|
|
PendingList().delete_from_pending(youtube_id)
|
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
def add_single(self):
|
|
|
|
"""add single youtube_id to download queue"""
|
|
|
|
youtube_id = self.exec_val
|
|
|
|
print("add vid to dl queue: " + youtube_id)
|
|
|
|
PendingList().delete_from_pending(youtube_id)
|
2021-10-31 09:04:28 +00:00
|
|
|
youtube_ids = UrlListParser(youtube_id).process_list()
|
2021-09-28 09:53:45 +00:00
|
|
|
extrac_dl.delay(youtube_ids)
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def manual_import():
|
|
|
|
"""run manual import from settings page"""
|
|
|
|
print("starting manual import")
|
|
|
|
run_manual_import.delay()
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-11-01 09:42:07 +00:00
|
|
|
@staticmethod
|
|
|
|
def re_embed():
|
|
|
|
"""rewrite thumbnails into media files"""
|
|
|
|
print("start video thumbnail embed process")
|
|
|
|
re_sync_thumbs.delay()
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def db_backup():
|
|
|
|
"""backup es to zip from settings page"""
|
|
|
|
print("backing up database")
|
|
|
|
run_backup.delay()
|
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def db_restore():
|
|
|
|
"""restore es zip from settings page"""
|
|
|
|
print("restoring index from backup zip")
|
|
|
|
run_restore_backup.delay()
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-10-08 07:56:07 +00:00
|
|
|
@staticmethod
|
|
|
|
def fs_rescan():
|
|
|
|
"""start file system rescan task"""
|
|
|
|
print("start filesystem scan")
|
|
|
|
rescan_filesystem.delay()
|
|
|
|
return {"success": True}
|
|
|
|
|
2021-09-22 04:43:38 +00:00
|
|
|
def channel_search(self):
|
|
|
|
"""search for channel name as_you_type"""
|
|
|
|
search_query = self.exec_val
|
|
|
|
print("searching for: " + search_query)
|
|
|
|
search_results = SearchForm().search_channels(search_query)
|
|
|
|
return search_results
|
2021-10-08 09:18:01 +00:00
|
|
|
|
|
|
|
def delete_video(self):
|
|
|
|
"""delete media file, metadata and thumb"""
|
|
|
|
youtube_id = self.exec_val
|
|
|
|
YoutubeVideo(youtube_id).delete_media_file()
|
|
|
|
return {"success": True}
|
2021-10-09 12:54:36 +00:00
|
|
|
|
|
|
|
def delete_channel(self):
|
|
|
|
"""delete channel and all matching videos"""
|
|
|
|
channel_id = self.exec_val
|
|
|
|
YoutubeChannel(channel_id).delete_channel()
|
|
|
|
return {"success": True}
|