Skip to content

Commit

Permalink
Add search functionality (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers authored May 11, 2019
1 parent f0b541b commit 56b75ad
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 65 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ unit:
#PYTHONPATH=$(pwd) python test/streamservicetests.py
PYTHONPATH=$(pwd) python test/apihelpertests.py
PYTHONPATH=$(pwd) python test/tvguidetests.py
PYTHONPATH=$(pwd) python test/searchtests.py
@echo -e "$(white)=$(blue) Unit tests finished successfully.$(reset)"

zip: test
Expand Down
12 changes: 7 additions & 5 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ def router(params_string):
api_helper = vrtapihelper.VRTApiHelper(kodi_wrapper)
vrt_player = vrtplayer.VRTPlayer(kodi_wrapper, api_helper)

if action == actions.LISTING_AZ_TVSHOWS:
if action == actions.PLAY:
vrt_player.play(params)
elif action == actions.LISTING_AZ_TVSHOWS:
vrt_player.show_tvshow_menu_items()
elif action == actions.LISTING_CATEGORIES:
vrt_player.show_category_menu_items()
elif action == actions.LISTING_CATEGORY_TVSHOWS:
vrt_player.show_tvshow_menu_items(category=params.get('category'))
elif action == actions.LISTING_CHANNELS:
vrt_player.show_channels_menu_items(channel=params.get('channel'))
elif action == actions.LISTING_LIVE:
Expand All @@ -58,10 +62,8 @@ def router(params_string):
vrt_player.show_all_episodes(path=params.get('video_url'))
elif action == actions.LISTING_RECENT:
vrt_player.show_recent(page=params.get('page', 1))
elif action == actions.LISTING_CATEGORY_TVSHOWS:
vrt_player.show_tvshow_menu_items(category=params.get('category'))
elif action == actions.PLAY:
vrt_player.play(params)
elif action == actions.SEARCH:
vrt_player.search(search_string=params.get('query'), page=params.get('page', 1))
else:
vrt_player.show_main_menu_items()

Expand Down
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
disable=
broad-except,
deprecated-lambda,
duplicate-code,
fixme,
import-error,
invalid-name,
Expand Down
20 changes: 20 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ msgctxt "#30091"
msgid "Browse channel TV guides"
msgstr "Browse channel TV guides"

msgctxt "#30092"
msgid "Search VRT NU"
msgstr "Search VRT NU"

msgctxt "#30093"
msgid "Search the complete VRT NU library"
msgstr "Search the complete VRT NU library"

msgctxt "#30094"
msgid "Season"
msgstr "Season"
Expand All @@ -175,6 +183,18 @@ msgctxt "#30096"
msgid "* All seasons"
msgstr "* All seasons"

msgctxt "#30097"
msgid "Enter search string"
msgstr "Enter search string"

msgctxt "#30098"
msgid "Nothing found"
msgstr "Nothing found"

msgctxt "#30099"
msgid "Nothing was found when searching for: %s"
msgstr "Nothing was found when searching for: %s"

msgctxt "#30101"
msgid "%s live"
msgstr "%s live"
Expand Down
20 changes: 20 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ msgctxt "#30091"
msgid "Browse channel TV guides"
msgstr "Doorzoek de TV-gids per kanaal"

msgctxt "#30092"
msgid "Doorzoek VRT NU"
msgstr "Doorzoek VRT NU"

msgctxt "#30093"
msgid "Search the complete VRT NU library"
msgstr "Doorzoek de hele VRT NU bibliotheek"

msgctxt "#30094"
msgid "Season"
msgstr "Seizoen"
Expand All @@ -184,6 +192,18 @@ msgctxt "#30096"
msgid "* All seasons"
msgstr "* Alle seizoenen"

msgctxt "#30097"
msgid "Enter search string"
msgstr "Geef zoektermen op"

msgctxt "#30098"
msgid "Nothing found"
msgstr "Niets gevonden"

msgctxt "#30099"
msgid "Nothing was found when searching for: %s"
msgstr "Er werd niets gevonden bij het zoeken naar: %s"

msgctxt "#30101"
msgid "%s live"
msgstr "%s live"
Expand Down
8 changes: 8 additions & 0 deletions resources/lib/kodiwrappers/kodiwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ def play(self, video):
xbmc.sleep(100)
xbmc.Player().showSubtitles(subtitles_visible)

def get_search_string(self):
search_string = None
keyboard = xbmc.Keyboard('', self.get_localized_string(30097))
keyboard.doModal()
if keyboard.isConfirmed():
search_string = keyboard.getText()
return search_string

def show_ok_dialog(self, title, message):
import xbmcgui
xbmcgui.Dialog().ok(self._addon.getAddonInfo('name'), title, message)
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/vrtplayer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from __future__ import absolute_import, division, unicode_literals


CLEAR_COOKIES = 'clearcookies'
LISTING_ALL_EPISODES = 'listingallepisodes'
LISTING_AZ_TVSHOWS = 'listingaztvshows'
Expand All @@ -16,3 +15,4 @@
LISTING_RECENT = 'listingrecent'
LISTING_TVGUIDE = 'listingtvguide'
PLAY = 'play'
SEARCH = 'search'
47 changes: 34 additions & 13 deletions resources/lib/vrtplayer/vrtapihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, unicode_literals
from resources.lib.helperobjects import helperobjects
from resources.lib.helperobjects.helperobjects import TitleItem
from resources.lib.vrtplayer import actions, metadatacreator, statichelper

try:
Expand Down Expand Up @@ -42,7 +42,10 @@ def get_tvshow_items(self, category=None, channel=None):

api_url = self._VRTNU_SUGGEST_URL + '?' + urlencode(params)
self._kodi_wrapper.log_notice('URL get: ' + api_url, 'Verbose')
tvshows = json.loads(urlopen(api_url).read())
api_json = json.loads(urlopen(api_url).read())
return self._map_to_tvshow_items(api_json)

def _map_to_tvshow_items(self, tvshows):
tvshow_items = []
for tvshow in tvshows:
metadata = metadatacreator.MetadataCreator()
Expand All @@ -58,11 +61,13 @@ def get_tvshow_items(self, category=None, channel=None):
# Cut vrtbase url off since it will be added again when searching for episodes
# (with a-z we dont have the full url)
video_url = statichelper.add_https_method(tvshow.get('targetUrl')).replace(self._VRT_BASE, '')
tvshow_items.append(helperobjects.TitleItem(title=label,
url_dict=dict(action=actions.LISTING_EPISODES, video_url=video_url),
is_playable=False,
art_dict=dict(thumb=thumbnail, icon='DefaultAddonVideo.png', fanart=thumbnail),
video_dict=metadata.get_video_dict()))
tvshow_items.append(TitleItem(
title=label,
url_dict=dict(action=actions.LISTING_EPISODES, video_url=video_url),
is_playable=False,
art_dict=dict(thumb=thumbnail, icon='DefaultAddonVideo.png', fanart=thumbnail),
video_dict=metadata.get_video_dict(),
))
return tvshow_items

def _get_season_items(self, api_url, api_json):
Expand All @@ -89,11 +94,10 @@ def get_episode_items(self, path=None, page=None, all_seasons=False):

# Recent items
if page:
entries = 50
params = {
'from': (page - 1) * entries,
'from': (page - 1) * 50,
'i': 'video',
'size': entries,
'size': 50,
'facets[transcodingStatus]': 'AVAILABLE',
'facets[programBrands]': '[een,canvas,sporza,vrtnws,vrtnxt,radio1,radio2,klara,stubru,mnm]',
}
Expand Down Expand Up @@ -215,7 +219,7 @@ def _map_to_episode_items(self, episodes, titletype=None, season_key=None):
video_url = statichelper.add_https_method(episode.get('url'))
label, sort, ascending = self._make_label(episode, titletype, options=display_options)
metadata.title = label
episode_items.append(helperobjects.TitleItem(
episode_items.append(TitleItem(
title=label,
url_dict=dict(action=actions.PLAY, video_url=video_url, video_id=episode.get('videoId'), publication_id=episode.get('publicationId')),
is_playable=True,
Expand All @@ -241,7 +245,7 @@ def _map_to_season_items(self, api_url, seasons, episode):

# Add an "* All seasons" list item
if self._kodi_wrapper.get_global_setting('videolibrary.showallitems') is True:
season_items.append(helperobjects.TitleItem(
season_items.append(TitleItem(
title=self._kodi_wrapper.get_localized_string(30096),
url_dict=dict(action=actions.LISTING_ALL_EPISODES, video_url=api_url),
is_playable=False,
Expand All @@ -257,7 +261,7 @@ def _map_to_season_items(self, api_url, seasons, episode):
label = '%s %s' % (self._kodi_wrapper.get_localized_string(30094), season_key)
params = {'facets[seasonTitle]': season_key}
path = api_url + '&' + urlencode(params)
season_items.append(helperobjects.TitleItem(
season_items.append(TitleItem(
title=label,
url_dict=dict(action=actions.LISTING_EPISODES, video_url=path),
is_playable=False,
Expand All @@ -266,6 +270,23 @@ def _map_to_season_items(self, api_url, seasons, episode):
))
return season_items, sort, ascending

def search(self, search_string, page=1):
import json

params = {
'from': (page - 1) * 50,
'i': 'video',
'size': 50,
'q': search_string,
}
api_url = 'https://search.vrt.be/search?' + urlencode(params)
self._kodi_wrapper.log_notice('URL get: ' + api_url, 'Verbose')
api_json = json.loads(urlopen(api_url).read())

episodes = api_json.get('results', [{}])
episode_items, sort, ascending = self._map_to_episode_items(episodes, titletype='recent')
return episode_items, sort, ascending

def get_live_screenshot(self, channel):
url = '%s/%s.jpg' % (self._VRTNU_SCREENSHOT_URL, channel)
self.__delete_cached_thumbnail(url)
Expand Down
Loading

0 comments on commit 56b75ad

Please sign in to comment.