plugin.video.viervijfzes/resources/lib/modules/search.py

47 lines
1.3 KiB
Python
Raw Normal View History

2020-03-19 16:45:31 +01:00
# -*- coding: utf-8 -*-
""" Search module """
from __future__ import absolute_import, division, unicode_literals
import logging
from resources.lib import kodiutils
from resources.lib.modules.menu import Menu
from resources.lib.viervijfzes.search import SearchApi
_LOGGER = logging.getLogger('search')
class Search:
""" Menu code related to search """
def __init__(self):
""" Initialise object """
self._search = SearchApi()
self._menu = Menu()
def show_search(self, query=None):
""" Shows the search dialog
:type query: str
"""
if not query:
# Ask for query
2020-03-21 20:34:07 +01:00
query = kodiutils.get_search_string(heading=kodiutils.localize(30009)) # Search
2020-03-19 16:45:31 +01:00
if not query:
kodiutils.end_of_directory()
return
# Do search
try:
items = self._search.search(query)
except Exception as ex: # pylint: disable=broad-except
kodiutils.notification(message=str(ex))
kodiutils.end_of_directory()
return
# Display results
listing = [self._menu.generate_titleitem(item) for item in items]
# Sort like we get our results back.
kodiutils.show_listing(listing, 30009, content='tvshows')