Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement recommendations #94

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ msgctxt "#30014"
msgid "Browse the TV Guide"
msgstr ""

msgctxt "#30015"
msgid "Recommendations"
msgstr ""

msgctxt "#30016"
msgid "Show the VTM GO recommendations"
msgstr ""


### CODE
msgctxt "#30200"
Expand Down
8 changes: 8 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ msgctxt "#30014"
msgid "Browse the TV Guide"
msgstr "Doorblader de tv-gids"

msgctxt "#30015"
msgid "Recommendations"
msgstr "Aanbevelingen"

msgctxt "#30016"
msgid "Show the VTM GO recommendations"
msgstr "Bekijk de VTM GO aanbevelingen"


### CODE
msgctxt "#30200"
Expand Down
102 changes: 102 additions & 0 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def show_index():
route_tvguide = show_kids_tvguide if kids else show_tvguide
listing.append((plugin.url_for(route_tvguide), listitem, True))

listitem = ListItem(localize(30015), offscreen=True) # Recommendations
listitem.setArt({'icon': 'DefaultFavourites.png'})
listitem.setInfo('video', {
'plot': localize(30016),
})
route_recommendations = show_kids_recommendations if kids else show_recommendations
listing.append((plugin.url_for(route_recommendations), listitem, True))

# Only provide YouTube option when plugin.video.youtube is available
if get_cond_visibility('System.HasAddon(plugin.video.youtube)') != 0:
listitem = ListItem(localize(30007), offscreen=True) # YouTube
Expand Down Expand Up @@ -277,6 +285,99 @@ def show_tvguide_detail(channel=None, date=None):
xbmcplugin.endOfDirectory(plugin.handle, ok)


@plugin.route('/kids/recommendations')
def show_kids_recommendations():
show_recommendations()


@plugin.route('/recommendations')
def show_recommendations():
""" Show the recommendations. """
kids = _get_kids_mode()

listing = []
try:
_vtmGo = VtmGo(kids=kids)
recommendations = _vtmGo.get_recommendations()
except Exception as ex:
notification(message=str(ex))
raise

for cat in recommendations:
listitem = ListItem(cat.title, offscreen=True)
listitem.setInfo('video', {
'plot': '[B]{category}[/B]'.format(category=cat.title),
})
listing.append((plugin.url_for(show_kids_recommendations_category if kids else show_recommendations_category, category=cat.category_id), listitem, True))

xbmcplugin.setContent(plugin.handle, 'files')

# Sort categories by default like in VTM GO.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.setPluginCategory(plugin.handle, category=_breadcrumb(localize(30015)))

ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok)


@plugin.route('/kids/recommendations/<category>')
def show_kids_recommendations_category(category):
show_recommendations_category(category)


@plugin.route('/recommendations/<category>')
def show_recommendations_category(category):
""" Show the items in a recommendations category. """
kids = _get_kids_mode()

listing = []
try:
_vtmGo = VtmGo(kids=kids)
recommendations = _vtmGo.get_recommendations()
except Exception as ex:
notification(message=str(ex))
raise

title = None

for cat in recommendations:
if cat.category_id == category:

title = cat.title

for item in cat.content:
listitem = ListItem(item.title, offscreen=True)
listitem.setArt({
'thumb': item.cover,
})

if item.video_type == Content.CONTENT_TYPE_MOVIE:
listitem.setInfo('video', {
'mediatype': 'movie',
})
listitem.setProperty('IsPlayable', 'true')
listing.append((plugin.url_for(play, category='movies', item=item.content_id), listitem, False))

elif item.video_type == Content.CONTENT_TYPE_PROGRAM:
listitem.setInfo('video', {
'mediatype': None, # This shows a folder icon
})
listing.append((plugin.url_for(show_program, program=item.content_id), listitem, True))

xbmcplugin.setContent(plugin.handle, 'tvshows')

xbmcplugin.setContent(plugin.handle, 'files')

# Sort categories by default like in VTM GO.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.setPluginCategory(plugin.handle, category=_breadcrumb(localize(30015), title))

ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok)


@plugin.route('/kids/catalog')
def show_kids_catalog():
show_catalog()
Expand Down Expand Up @@ -554,6 +655,7 @@ def show_search():
listitem.setInfo('video', {
'mediatype': 'movie',
})
listitem.setProperty('IsPlayable', 'true')
listing.append((plugin.url_for(play, category='movies', item=item.content_id), listitem, False))

elif item.video_type == Content.CONTENT_TYPE_PROGRAM:
Expand Down
34 changes: 28 additions & 6 deletions resources/lib/vtmgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def __repr__(self):


class Category:
def __init__(self, category_id=None, title=None):
def __init__(self, category_id=None, title=None, content=None):
""" Defines a category from the catalogue.
:type category_id: str
:type title: str
:type content: list[Content]
"""
self.category_id = category_id
self.title = title
self.content = content

def __repr__(self):
return "%r" % self.__dict__
Expand Down Expand Up @@ -213,12 +215,32 @@ def get_config(self):
info = json.loads(response)
return info

def get_main(self):
def get_recommendations(self):
""" Returns the config for the dashboard. """
# This is currently not used
response = self._get_url('/%s/main' % self._mode)
info = json.loads(response)
return info
results = json.loads(response)

categories = []
for cat in results.get('rows', []):
if cat.get('rowType') in ['SWIMLANE_DEFAULT']:
items = []

for item in cat.get('teasers'):
items.append(Content(
content_id=item.get('target', {}).get('id'),
video_type=item.get('target', {}).get('type'),
title=item.get('title'),
geoblocked=item.get('geoBlocked'),
cover=item.get('imageUrl'),
))

categories.append(Category(
category_id=cat.get('id'),
title=cat.get('title'),
content=items,
))

return categories

def get_live(self):
""" Get a list of all the live tv channels.
Expand Down Expand Up @@ -392,7 +414,7 @@ def do_search(self, search):
:type search: str
:rtype list[Content]
"""
response = self._get_url('/%s/autocomplete/?maxItems=50&keywords=%s' % (self._mode, quote(search)))
response = self._get_url('/%s/autocomplete/?maxItems=%d&keywords=%s' % (self._mode, 50, quote(search)))
results = json.loads(response)

items = []
Expand Down
9 changes: 9 additions & 0 deletions test/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def test_tvguide_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/tvguide/vtm/today', '0', ''])
self.assertEqual(addon.url_for(plugin.show_tvguide_detail, channel='vtm', date='today'), 'plugin://plugin.video.vtm.go/tvguide/vtm/today')

# Recommendations menu: '/recommendations'
def test_recommendations_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/recommendations', '0', ''])
self.assertEqual(addon.url_for(plugin.show_recommendations), 'plugin://plugin.video.vtm.go/recommendations')
plugin.run(['plugin://plugin.video.vtm.go/kids/recommendations', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_recommendations), 'plugin://plugin.video.vtm.go/kids/recommendations')
plugin.run(['plugin://plugin.video.vtm.go/recommendations/1', '0', ''])
self.assertEqual(addon.url_for(plugin.show_recommendations_category, category='1'), 'plugin://plugin.video.vtm.go/recommendations/1')

# Play Live TV: '/play/livetv/<channel>'
def test_play_livetv(self):
plugin.run(['plugin://plugin.video.vtm.go/play/channels/ea826456-6b19-4612-8969-864d1c818347?.pvr', '0', ''])
Expand Down
6 changes: 3 additions & 3 deletions test/test_vtmgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def test_get_config(self):
self.assertTrue(config)
# print(config)

def test_get_main(self):
main = self._vtmgo.get_main()
self.assertTrue(main)
def test_get_recommendations(self):
recommendations = self._vtmgo.get_recommendations()
self.assertTrue(recommendations)
# print(main)

def test_get_categories(self):
Expand Down