diff --git a/tubearchivist/api/src/search_processor.py b/tubearchivist/api/src/search_processor.py index e9b4d24..b180486 100644 --- a/tubearchivist/api/src/search_processor.py +++ b/tubearchivist/api/src/search_processor.py @@ -39,7 +39,7 @@ class SearchProcess: def _process_result(self, result): """detect which type of data to process""" index = result["_index"] - processed = False + processed = {} if index == "ta_video": processed = self._process_video(result["_source"]) if index == "ta_channel": @@ -50,6 +50,10 @@ class SearchProcess: processed = self._process_download(result["_source"]) if index == "ta_comment": processed = self._process_comment(result["_source"]) + if index == "ta_subtitle": + processed = self._process_subtitle(result) + + processed.update({"_index": index}) return processed @@ -139,3 +143,17 @@ class SearchProcess: processed_comments[-1]["comment_replies"].append(comment) return processed_comments + + def _process_subtitle(self, result): + """take complete result dict to extract highlight""" + subtitle_dict = result["_source"] + highlight = result.get("highlight") + if highlight: + # replace lines with the highlighted markdown + subtitle_line = highlight.get("subtitle_line")[0] + subtitle_dict.update({"subtitle_line": subtitle_line}) + + thumb_path = ThumbManager(subtitle_dict["youtube_id"]).vid_thumb_path() + subtitle_dict.update({"vid_thumb_url": f"/cache/{thumb_path}"}) + + return subtitle_dict diff --git a/tubearchivist/home/src/frontend/searching.py b/tubearchivist/home/src/frontend/searching.py index b9f2624..167b90b 100644 --- a/tubearchivist/home/src/frontend/searching.py +++ b/tubearchivist/home/src/frontend/searching.py @@ -9,6 +9,7 @@ Functionality: import urllib.parse from datetime import datetime +from api.src.search_processor import SearchProcess from home.src.download.thumbnails import ThumbManager from home.src.es.connect import ElasticWrap from home.src.ta.config import AppConfig @@ -114,8 +115,8 @@ class SearchForm: def multi_search(self, search_query): """searching through index""" path, query, query_type = SearchParser(search_query).run() - look_up = SearchHandler(path, config=self.CONFIG, data=query) - search_results = look_up.get_data() + response, _ = ElasticWrap(path).get(data=query) + search_results = SearchProcess(response).process() all_results = self.build_results(search_results) return {"results": all_results, "queryType": query_type} @@ -465,7 +466,6 @@ class QueryBuilder: query = { "size": 30, - "_source": {"excludes": "subtitle_line"}, "query": {"bool": {"must": must_list}}, "highlight": { "fields": { diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 990e76c..03984b2 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -938,7 +938,7 @@ function populateMultiSearchResults(allResults, queryType) { videoBox.parentElement.style.display = 'block'; if (allVideos.length > 0) { for (let index = 0; index < allVideos.length; index++) { - const video = allVideos[index].source; + const video = allVideos[index]; const videoDiv = createVideo(video, defaultVideo); videoBox.appendChild(videoDiv); } @@ -957,7 +957,7 @@ function populateMultiSearchResults(allResults, queryType) { channelBox.parentElement.style.display = 'block'; if (allChannels.length > 0) { for (let index = 0; index < allChannels.length; index++) { - const channel = allChannels[index].source; + const channel = allChannels[index]; const channelDiv = createChannel(channel, defaultChannel); channelBox.appendChild(channelDiv); } @@ -976,7 +976,7 @@ function populateMultiSearchResults(allResults, queryType) { playlistBox.parentElement.style.display = 'block'; if (allPlaylists.length > 0) { for (let index = 0; index < allPlaylists.length; index++) { - const playlist = allPlaylists[index].source; + const playlist = allPlaylists[index]; const playlistDiv = createPlaylist(playlist, defaultPlaylist); playlistBox.appendChild(playlistDiv); } @@ -995,7 +995,7 @@ function populateMultiSearchResults(allResults, queryType) { if (allFullText.length > 0) { for (let i = 0; i < allFullText.length; i++) { const fullText = allFullText[i]; - if ('highlight' in fullText) { + if ('subtitle_line' in fullText) { const fullTextDiv = createFulltext(fullText); fullTextBox.appendChild(fullTextDiv); } @@ -1132,19 +1132,14 @@ function createPlaylist(playlist, viewStyle) { } function createFulltext(fullText) { - const videoId = fullText.source.youtube_id; - const videoTitle = fullText.source.title; - const thumbUrl = fullText.source.vid_thumb_url; - const channelId = fullText.source.subtitle_channel_id; - const channelName = fullText.source.subtitle_channel; - const subtitleLine = fullText.highlight.subtitle_line[0]; - const subtitle_start = fullText.source.subtitle_start.split('.')[0]; - const subtitle_end = fullText.source.subtitle_end.split('.')[0]; + const videoId = fullText.youtube_id; + const subtitle_start = fullText.subtitle_start.split('.')[0]; + const subtitle_end = fullText.subtitle_end.split('.')[0]; const markup = `
- video-thumb + video-thumb
play-icon @@ -1153,10 +1148,10 @@ function createFulltext(fullText) {

${subtitle_start} - ${subtitle_end}

-

${subtitleLine}

+

${fullText.subtitle_line}

-

${channelName}

-

${videoTitle}

+

${fullText.subtitle_channel}

+

${fullText.title}

`;