refactor single video page to use SearchProcess

This commit is contained in:
Simon 2023-09-04 21:43:09 +07:00
parent 879f5ab52f
commit a7fc7902f0
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 11 additions and 9 deletions

View File

@ -39,7 +39,7 @@ class SearchProcess:
def _process_result(self, result):
"""detect which type of data to process"""
index = result["_index"]
processed = {}
processed = False
if index == "ta_video":
processed = self._process_video(result["_source"])
if index == "ta_channel":
@ -53,12 +53,13 @@ class SearchProcess:
if index == "ta_subtitle":
processed = self._process_subtitle(result)
processed.update(
{
"_index": index,
"_score": round(result.get("_score") or 0, 2),
}
)
if isinstance(processed, dict):
processed.update(
{
"_index": index,
"_score": round(result.get("_score") or 0, 2),
}
)
return processed

View File

@ -892,8 +892,9 @@ class VideoView(MinView):
def get(self, request, video_id):
"""get single video"""
config_handler = AppConfig(request.user.id)
look_up = SearchHandler(f"ta_video/_doc/{video_id}", config=False)
video_data = look_up.get_data()[0]["source"]
response, _ = ElasticWrap(f"ta_video/_doc/{video_id}").get()
video_data = SearchProcess(response).process()
try:
rating = video_data["stats"]["average_rating"]
video_data["stats"]["average_rating"] = self.star_creator(rating)