Merge branch 'testing' of https://github.com/bbilly1/tubearchivist into feat/react-frontend

This commit is contained in:
Sean Norwood 2022-04-17 00:45:58 +00:00
commit 526c98ca8a
3 changed files with 29 additions and 26 deletions

View File

@ -7,12 +7,16 @@ Functionality:
import urllib.parse import urllib.parse
from home.src.download.thumbnails import ThumbManager from home.src.download.thumbnails import ThumbManager
from home.src.ta.config import AppConfig
from home.src.ta.helper import date_praser from home.src.ta.helper import date_praser
class SearchProcess: class SearchProcess:
"""process search results""" """process search results"""
CONFIG = AppConfig().config
CACHE_DIR = CONFIG["application"]["cache_dir"]
def __init__(self, response): def __init__(self, response):
self.response = response self.response = response
self.processed = False self.processed = False
@ -42,6 +46,8 @@ class SearchProcess:
processed = self._process_channel(result["_source"]) processed = self._process_channel(result["_source"])
if index == "ta_playlist": if index == "ta_playlist":
processed = self._process_playlist(result["_source"]) processed = self._process_playlist(result["_source"])
if index == "ta_download":
processed = self._process_download(result["_source"])
return processed return processed
@ -71,13 +77,18 @@ class SearchProcess:
vid_thumb_url = ThumbManager().vid_thumb_path(video_id) vid_thumb_url = ThumbManager().vid_thumb_path(video_id)
channel = self._process_channel(video_dict["channel"]) channel = self._process_channel(video_dict["channel"])
if "subtitles" in video_dict:
for idx, _ in enumerate(video_dict["subtitles"]):
url = video_dict["subtitles"][idx]["media_url"]
video_dict["subtitles"][idx]["media_url"] = f"/media/{url}"
video_dict.update( video_dict.update(
{ {
"channel": channel, "channel": channel,
"media_url": media_url, "media_url": f"/media/{media_url}",
"vid_last_refresh": vid_last_refresh, "vid_last_refresh": vid_last_refresh,
"published": published, "published": published,
"vid_thumb_url": vid_thumb_url, "vid_thumb_url": f"{self.CACHE_DIR}/{vid_thumb_url}",
} }
) )
@ -98,3 +109,17 @@ class SearchProcess:
) )
return dict(sorted(playlist_dict.items())) return dict(sorted(playlist_dict.items()))
def _process_download(self, download_dict):
"""run on single download item"""
video_id = download_dict["youtube_id"]
vid_thumb_url = ThumbManager().vid_thumb_path(video_id)
published = date_praser(download_dict["published"])
download_dict.update(
{
"vid_thumb_url": f"{self.CACHE_DIR}/{vid_thumb_url}",
"published": published,
}
)
return dict(sorted(download_dict.items()))

View File

@ -1,7 +1,6 @@
"""all API views""" """all API views"""
from api.src.search_processor import SearchProcess from api.src.search_processor import SearchProcess
from home.src.download.thumbnails import ThumbManager
from home.src.es.connect import ElasticWrap from home.src.es.connect import ElasticWrap
from home.src.index.video import SponsorBlock from home.src.index.video import SponsorBlock
from home.src.ta.config import AppConfig from home.src.ta.config import AppConfig
@ -44,25 +43,6 @@ class ApiBaseView(APIView):
self.response["data"] = False self.response["data"] = False
self.status_code = status_code self.status_code = status_code
def process_keys(self):
"""process keys for frontend"""
all_keys = self.response["data"].keys()
if "media_url" in all_keys:
media_url = self.response["data"]["media_url"]
self.response["data"]["media_url"] = f"/media/{media_url}"
if "vid_thumb_url" in all_keys:
youtube_id = self.response["data"]["youtube_id"]
vid_thumb_url = ThumbManager().vid_thumb_path(youtube_id)
cache_dir = self.response["config"]["application"]["cache_dir"]
new_thumb = f"{cache_dir}/{vid_thumb_url}"
self.response["data"]["vid_thumb_url"] = new_thumb
if "subtitles" in all_keys:
all_subtitles = self.response["data"]["subtitles"]
for idx, _ in enumerate(all_subtitles):
url = self.response["data"]["subtitles"][idx]["media_url"]
new_url = f"/media/{url}"
self.response["data"]["subtitles"][idx]["media_url"] = new_url
def get_paginate(self): def get_paginate(self):
"""add pagination detail to response""" """add pagination detail to response"""
self.response["paginate"] = False self.response["paginate"] = False
@ -86,8 +66,6 @@ class VideoApiView(ApiBaseView):
# pylint: disable=unused-argument # pylint: disable=unused-argument
"""get request""" """get request"""
self.get_document(video_id) self.get_document(video_id)
if self.response.get("data"):
self.process_keys()
return Response(self.response, status=self.status_code) return Response(self.response, status=self.status_code)

View File

@ -10,7 +10,6 @@ from datetime import datetime
import requests import requests
from django.conf import settings from django.conf import settings
from home.src.download.thumbnails import ThumbManager
from home.src.es.connect import ElasticWrap from home.src.es.connect import ElasticWrap
from home.src.index import channel as ta_channel from home.src.index import channel as ta_channel
from home.src.index.generic import YouTubeItem from home.src.index.generic import YouTubeItem
@ -437,7 +436,8 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
upload_date_time = datetime.strptime(upload_date, "%Y%m%d") upload_date_time = datetime.strptime(upload_date, "%Y%m%d")
published = upload_date_time.strftime("%Y-%m-%d") published = upload_date_time.strftime("%Y-%m-%d")
last_refresh = int(datetime.now().strftime("%s")) last_refresh = int(datetime.now().strftime("%s"))
base64_blur = ThumbManager().get_base64_blur(self.youtube_id) # base64_blur = ThumbManager().get_base64_blur(self.youtube_id)
base64_blur = False
# build json_data basics # build json_data basics
self.json_data = { self.json_data = {
"title": self.youtube_meta["title"], "title": self.youtube_meta["title"],