diff --git a/tubearchivist/home/src/frontend/searching.py b/tubearchivist/home/src/frontend/searching.py index 068027f..5bcc01d 100644 --- a/tubearchivist/home/src/frontend/searching.py +++ b/tubearchivist/home/src/frontend/searching.py @@ -6,103 +6,9 @@ Functionality: - calculate pagination values """ -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.helper import get_duration_str - - -class SearchHandler: - """search elastic search""" - - def __init__(self, path, data=False): - self.max_hits = None - self.aggs = None - self.path = path - self.data = data - - def get_data(self): - """get the data""" - response, _ = ElasticWrap(self.path).get(self.data) - - if "hits" in response.keys(): - self.max_hits = response["hits"]["total"]["value"] - return_value = response["hits"]["hits"] - else: - # simulate list for single result to reuse rest of class - return_value = [response] - - if not return_value: - return False - - for idx, hit in enumerate(return_value): - return_value[idx] = self.hit_cleanup(hit) - - if response.get("aggregations"): - self.aggs = response["aggregations"] - if "total_duration" in self.aggs: - duration_sec = int(self.aggs["total_duration"]["value"]) - self.aggs["total_duration"].update( - {"value_str": get_duration_str(duration_sec)} - ) - - return return_value - - @staticmethod - def hit_cleanup(hit): - """clean up and parse data from a single hit""" - hit["source"] = hit.pop("_source") - hit_keys = hit["source"].keys() - if "media_url" in hit_keys: - parsed_url = urllib.parse.quote(hit["source"]["media_url"]) - hit["source"]["media_url"] = parsed_url - - if "published" in hit_keys: - published = hit["source"]["published"] - date_pub = datetime.strptime(published, "%Y-%m-%d") - date_str = datetime.strftime(date_pub, "%d %b, %Y") - hit["source"]["published"] = date_str - - if "vid_last_refresh" in hit_keys: - vid_last_refresh = hit["source"]["vid_last_refresh"] - date_refresh = datetime.fromtimestamp(vid_last_refresh) - date_str = datetime.strftime(date_refresh, "%d %b, %Y") - hit["source"]["vid_last_refresh"] = date_str - - if "playlist_last_refresh" in hit_keys: - playlist_last_refresh = hit["source"]["playlist_last_refresh"] - date_refresh = datetime.fromtimestamp(playlist_last_refresh) - date_str = datetime.strftime(date_refresh, "%d %b, %Y") - hit["source"]["playlist_last_refresh"] = date_str - - if "vid_thumb_url" in hit_keys: - youtube_id = hit["source"]["youtube_id"] - thumb_path = ThumbManager(youtube_id).vid_thumb_path() - hit["source"]["vid_thumb_url"] = f"/cache/{thumb_path}" - - if "channel_last_refresh" in hit_keys: - refreshed = hit["source"]["channel_last_refresh"] - date_refresh = datetime.fromtimestamp(refreshed) - date_str = datetime.strftime(date_refresh, "%d %b, %Y") - hit["source"]["channel_last_refresh"] = date_str - - if "channel" in hit_keys: - channel_keys = hit["source"]["channel"].keys() - if "channel_last_refresh" in channel_keys: - refreshed = hit["source"]["channel"]["channel_last_refresh"] - date_refresh = datetime.fromtimestamp(refreshed) - date_str = datetime.strftime(date_refresh, "%d %b, %Y") - hit["source"]["channel"]["channel_last_refresh"] = date_str - - if "subtitle_fragment_id" in hit_keys: - youtube_id = hit["source"]["youtube_id"] - thumb_path = ThumbManager(youtube_id).vid_thumb_path() - hit["source"]["vid_thumb_url"] = f"/cache/{thumb_path}" - - return hit class SearchForm: diff --git a/tubearchivist/home/templates/home/channel.html b/tubearchivist/home/templates/home/channel.html index 7a7debf..0091345 100644 --- a/tubearchivist/home/templates/home/channel.html +++ b/tubearchivist/home/templates/home/channel.html @@ -42,33 +42,33 @@ {% for channel in results %}
Subscribers: {{ channel.source.channel_subs|intword }}
+Subscribers: {{ channel.channel_subs|intword }}
{% else %} -Subscribers: {{ channel.source.channel_subs|intcomma }}
+Subscribers: {{ channel.channel_subs|intcomma }}
{% endif %}Last refreshed: {{ channel.source.channel_last_refresh }}
- {% if channel.source.channel_subscribed %} - +Last refreshed: {{ channel.channel_last_refresh }}
+ {% if channel.channel_subscribed %} + {% else %} - + {% endif %}Last refreshed: {{ playlist.source.playlist_last_refresh }}
- {% if playlist.source.playlist_subscribed %} - +Last refreshed: {{ playlist.playlist_last_refresh }}
+ {% if playlist.playlist_subscribed %} + {% else %} - + {% endif %}Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}
- {% if video.source.message %} -{{ video.source.message }}
+Published: {{ video.published }} | Duration: {{ video.duration }} | {{ video.youtube_id }}
+ {% if video.message %} +{{ video.message }}
{% endif %}Last refreshed: {{ playlist.source.playlist_last_refresh }}
- {% if playlist.source.playlist_subscribed %} - +Last refreshed: {{ playlist.playlist_last_refresh }}
+ {% if playlist.playlist_subscribed %} + {% else %} - + {% endif %}