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

46 lines
1.2 KiB
Python
Raw Permalink 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(__name__)
2020-03-19 16:45:31 +01:00
class Search:
""" Menu code related to search """
def __init__(self):
""" Initialise object """
self._search = SearchApi()
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
2020-04-20 08:59:10 +02:00
listing = [Menu.generate_titleitem(item) for item in items]
2020-03-19 16:45:31 +01:00
# Sort like we get our results back.
kodiutils.show_listing(listing, 30009, content='tvshows')