process ta_download search results

This commit is contained in:
simon 2022-04-17 05:21:35 +07:00
parent 9224696e33
commit 7d45d23767
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

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
@ -64,8 +70,6 @@ class SearchProcess:
def _process_video(self, video_dict): def _process_video(self, video_dict):
"""run on single video dict""" """run on single video dict"""
# fix cache_dir build dynamic
cache_dir = "/cache"
video_id = video_dict["youtube_id"] video_id = video_dict["youtube_id"]
media_url = urllib.parse.quote(video_dict["media_url"]) media_url = urllib.parse.quote(video_dict["media_url"])
vid_last_refresh = date_praser(video_dict["vid_last_refresh"]) vid_last_refresh = date_praser(video_dict["vid_last_refresh"])
@ -84,7 +88,7 @@ class SearchProcess:
"media_url": f"/media/{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": f"{cache_dir}/{vid_thumb_url}", "vid_thumb_url": f"{self.CACHE_DIR}/{vid_thumb_url}",
} }
) )
@ -105,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()))