Skip to content

Commit

Permalink
Add "Featured content" menu (#322)
Browse files Browse the repository at this point in the history
This PR includes:
- Add the "Featured" content menu based on a static list
- A typo in docstring
- Improve categories interface
  • Loading branch information
dagwieers authored Jun 18, 2019
1 parent 5ea2755 commit 17a4441
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 44 deletions.
19 changes: 12 additions & 7 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def programs(program=None, season=None):
''' The programs A-Z / seasons / episode listing '''
from resources.lib import vrtplayer
if program:
vrtplayer.VRTPlayer(kodi).show_episodes(program, season)
vrtplayer.VRTPlayer(kodi).show_episodes(program=program, season=season)
else:
vrtplayer.VRTPlayer(kodi).show_tvshow_menu_items()

Expand All @@ -111,10 +111,7 @@ def programs(program=None, season=None):
def categories(category=None):
''' The categories menu and listing '''
from resources.lib import vrtplayer
if category:
vrtplayer.VRTPlayer(kodi).show_tvshow_menu_items(category=category)
else:
vrtplayer.VRTPlayer(kodi).show_category_menu_items()
vrtplayer.VRTPlayer(kodi).show_category_menu_items(category=category)


@plugin.route('/channels')
Expand Down Expand Up @@ -143,11 +140,19 @@ def recent(page=1):
@plugin.route('/offline')
@plugin.route('/offline/<page>')
def offline(page=1):
''' The soon ogline listing '''
''' The soon offline listing '''
from resources.lib import vrtplayer
vrtplayer.VRTPlayer(kodi).show_offline(page=page)


@plugin.route('/featured')
@plugin.route('/featured/<feature>')
def featured(feature=None):
''' The featured menu and listing '''
from resources.lib import vrtplayer
vrtplayer.VRTPlayer(kodi).show_featured_menu_items(feature=feature)


@plugin.route('/tvguide')
@plugin.route('/tvguide/<date>')
@plugin.route('/tvguide/<date>/<channel>')
Expand Down Expand Up @@ -188,7 +193,7 @@ def play_url(video_url):
def play_last(program):
''' The API interface to play the latest episode of a program '''
from resources.lib import vrtplayer
vrtplayer.VRTPlayer(kodi).play_latest_episode(program)
vrtplayer.VRTPlayer(kodi).play_latest_episode(program=program)


if __name__ == '__main__':
Expand Down
14 changes: 11 additions & 3 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,26 @@ msgid "Video content that will soon be offline"
msgstr ""

msgctxt "#30024"
msgid "TV guide"
msgid "Featured content"
msgstr ""

msgctxt "#30025"
msgid "Browse channel TV guides"
msgid "Highlighted movies and programs"
msgstr ""

msgctxt "#30026"
msgid "Search VRT NU"
msgid "TV guide"
msgstr ""

msgctxt "#30027"
msgid "Browse channel TV guides"
msgstr ""

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

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

Expand Down
14 changes: 11 additions & 3 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,26 @@ msgid "Video content that will soon be offline"
msgstr "Tv-afleveringen die binnenkort verdwijnen"

msgctxt "#30024"
msgid "Featured content"
msgstr "Uitgelicht aanbod"

msgctxt "#30025"
msgid "Highlighted movies and programs"
msgstr "Aanbevolen films en tvprogramma's"

msgctxt "#30026"
msgid "TV guide"
msgstr "Tv-gids"

msgctxt "#30025"
msgctxt "#30027"
msgid "Browse channel TV guides"
msgstr "Doorzoek de tv-gids per kanaal"

msgctxt "#30026"
msgctxt "#30028"
msgid "Search VRT NU"
msgstr "Doorzoek VRT NU"

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

Expand Down
46 changes: 29 additions & 17 deletions resources/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

# Fallback list of categories so we don't depend on web scraping only
CATEGORIES = [
dict(name='Audiodescriptie', id='met-audiodescriptie'),
dict(name='Cultuur', id='cultuur'),
dict(name='Docu', id='docu'),
dict(name='Entertainment', id='entertainment'),
dict(name='Films', id='films'),
dict(name='Human interest', id='human-interest'),
dict(name='Humor', id='humor'),
dict(name='Kinderen', id='voor-kinderen'),
dict(name='Koken', id='koken'),
dict(name='Lifestyle', id='lifestyle'),
dict(name='Muziek', id='muziek'),
dict(name='Nieuws en actua', id='nieuws-en-actua'),
dict(name='Series', id='series'),
dict(name='Sport', id='sport'),
dict(name='Talkshows', id='talkshows'),
dict(name='Vlaamse Gebarentaal', id='met-gebarentaal'),
dict(name='Wetenschap en natuur', id='wetenschap-en-natuur'),
dict(name='Audiodescriptie', id='met-audiodescriptie', msgctxt=''),
dict(name='Cultuur', id='cultuur', msgctxt=''),
dict(name='Docu', id='docu', msgctxt=''),
dict(name='Entertainment', id='entertainment', msgctxt=''),
dict(name='Films', id='films', msgctxt=''),
dict(name='Human interest', id='human-interest', msgctxt=''),
dict(name='Humor', id='humor', msgctxt=''),
dict(name='Kinderen', id='voor-kinderen', msgctxt=''),
dict(name='Koken', id='koken', msgctxt=''),
dict(name='Lifestyle', id='lifestyle', msgctxt=''),
dict(name='Muziek', id='muziek', msgctxt=''),
dict(name='Nieuws en actua', id='nieuws-en-actua', msgctxt=''),
dict(name='Series', id='series', msgctxt=''),
dict(name='Sport', id='sport', msgctxt=''),
dict(name='Talkshows', id='talkshows', msgctxt=''),
dict(name='Vlaamse Gebarentaal', id='met-gebarentaal', msgctxt=''),
dict(name='Wetenschap en natuur', id='wetenschap-en-natuur', msgctxt=''),
]

CHANNELS = [
Expand Down Expand Up @@ -115,3 +115,15 @@
studio='VRT NXT',
),
]

FEATURED = [
# Tijdsgerelateerd
dict(name='Exclusief online', id='exclusief-online', msgctxt=''),
dict(name='Laatste aflevering', id='laatste-aflevering', msgctxt=''),
dict(name='Laatste kans', id='laatste-kans', msgctxt=''),
dict(name='Nieuw', id='Nieuw', msgctxt=''),
dict(name='Volledige reeks', id='volledige-reeks', msgctxt=''),
dict(name='Volledige seizoen', id='volledig-seizoen', msgctxt=''),
# Inhoudsgerelateerd
dict(name='Kortfilm', id='kortfilm', msgctxt=''),
]
25 changes: 22 additions & 3 deletions resources/lib/vrtapihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self, _kodi, _favorites):
self._favorites = _favorites
self._channel_filter = [channel.get('name') for channel in CHANNELS if _kodi.get_setting(channel.get('name'), 'true') == 'true']

def get_tvshow_items(self, category=None, channel=None, use_favorites=False):
''' Get all TV shows for a given category or channel, optionally filtered by favorites '''
def get_tvshow_items(self, category=None, channel=None, feature=None, use_favorites=False):
''' Get all TV shows for a given category, channel or feature, optionally filtered by favorites '''
params = dict()

if category:
Expand All @@ -46,8 +46,12 @@ def get_tvshow_items(self, category=None, channel=None, use_favorites=False):
params['facets[programBrands]'] = channel
cache_file = 'channel.%s.json' % channel

if feature:
params['facets[programTags.title]'] = feature
cache_file = 'featured.%s.json' % feature

# If no facet-selection is done, we return the A-Z listing
if not category and not channel:
if not category and not channel and not feature:
params['facets[transcodingStatus]'] = 'AVAILABLE'
cache_file = 'programs.json'

Expand Down Expand Up @@ -551,6 +555,21 @@ def get_channel_items(self, channels=None, live=True):

return channel_items

def get_featured_items(self):
''' Construct a list of featured Listitems '''
from resources.lib import FEATURED

featured_items = []
for feature in FEATURED:
featured_items.append(TitleItem(
title=feature.get('name'),
path=self._kodi.url_for('featured', feature=feature.get('id')),
is_playable=False,
art_dict=dict(thumb='DefaultCountry.png', icon='DefaultCountry.png', fanart='DefaultCountry.png'),
video_dict=dict(plot='[B]%s[/B]' % feature.get('name'), studio='VRT'),
))
return featured_items

def get_category_items(self):
''' Construct a list of category ListItems '''
categories = []
Expand Down
38 changes: 29 additions & 9 deletions resources/lib/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ def show_main_menu_items(self):
is_playable=False,
art_dict=dict(thumb='DefaultYear.png', icon='DefaultYear.png', fanart='DefaultYear.png'),
video_dict=dict(plot=self._kodi.localize(30023))),
TitleItem(title=self._kodi.localize(30024), # TV guide
TitleItem(title=self._kodi.localize(30024), # Featured content
path=self._kodi.url_for('featured'),
is_playable=False,
art_dict=dict(thumb='DefaultCountry.png', icon='DefaultCountry.png', fanart='DefaultCountry.png'),
video_dict=dict(plot=self._kodi.localize(30025))),
TitleItem(title=self._kodi.localize(30026), # TV guide
path=self._kodi.url_for('tv_guide'),
is_playable=False,
art_dict=dict(thumb='DefaultAddonTvInfo.png', icon='DefaultAddonTvInfo.png', fanart='DefaultAddonTvInfo.png'),
video_dict=dict(plot=self._kodi.localize(30025))),
TitleItem(title=self._kodi.localize(30026), # Search
video_dict=dict(plot=self._kodi.localize(30027))),
TitleItem(title=self._kodi.localize(30028), # Search
path=self._kodi.url_for('search'),
is_playable=False,
art_dict=dict(thumb='DefaultAddonsSearch.png', icon='DefaultAddonsSearch.png', fanart='DefaultAddonsSearch.png'),
video_dict=dict(plot=self._kodi.localize(30027))),
video_dict=dict(plot=self._kodi.localize(30029))),
])
self._kodi.show_listing(main_items)

Expand Down Expand Up @@ -109,17 +114,22 @@ def show_favorites_menu_items(self):
if not self._favorites.titles():
self._kodi.show_ok_dialog(heading=self._kodi.localize(30415), message=self._kodi.localize(30416))

def show_tvshow_menu_items(self, category=None, use_favorites=False):
def show_tvshow_menu_items(self, use_favorites=False):
''' The VRT NU add-on 'A-Z' listing menu '''
# My programs menus may need more up-to-date favorites
self._favorites.get_favorites(ttl=5 * 60 if use_favorites else 60 * 60)
tvshow_items = self._apihelper.get_tvshow_items(category=category, use_favorites=use_favorites)
tvshow_items = self._apihelper.get_tvshow_items(use_favorites=use_favorites)
self._kodi.show_listing(tvshow_items, sort='label', content='tvshows')

def show_category_menu_items(self):
def show_category_menu_items(self, category=None):
''' The VRT NU add-on 'Categories' listing menu '''
category_items = self._apihelper.get_category_items()
self._kodi.show_listing(category_items, sort='label', content='files')
if category:
self._favorites.get_favorites(ttl=60 * 60)
tvshow_items = self._apihelper.get_tvshow_items(category=category)
self._kodi.show_listing(tvshow_items, sort='label', content='tvshows')
else:
category_items = self._apihelper.get_category_items()
self._kodi.show_listing(category_items, sort='label', content='files')

def show_channels_menu_items(self, channel=None):
''' The VRT NU add-on 'Channels' listing menu '''
Expand All @@ -133,6 +143,16 @@ def show_channels_menu_items(self, channel=None):
channel_items = self._apihelper.get_channel_items(live=False)
self._kodi.show_listing(channel_items, cache=False)

def show_featured_menu_items(self, feature=None):
''' The VRT NU add-on 'Featured content' listing menu '''
if feature:
self._favorites.get_favorites(ttl=60 * 60)
tvshow_items = self._apihelper.get_tvshow_items(feature=feature)
self._kodi.show_listing(tvshow_items, sort='label', content='tvshows')
else:
featured_items = self._apihelper.get_featured_items()
self._kodi.show_listing(featured_items, sort='label', content='files')

def show_livestream_items(self):
''' The VRT NU add-on 'Live TV' listing menu '''
channel_items = self._apihelper.get_channel_items()
Expand Down
10 changes: 10 additions & 0 deletions test/routingtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def test_categories_tvshow_menu(self):
addon.plugin.run(['plugin://plugin.video.vrt.nu/categories/kinderen', '0', ''])
self.assertEqual(addon.plugin.url_for(addon.categories, category='kinderen'), 'plugin://plugin.video.vrt.nu/categories/kinderen')

# Featured menu: '/featured'
def test_featured_menu(self):
addon.plugin.run(['plugin://plugin.video.vrt.nu/featured', '0', ''])
self.assertEqual(addon.plugin.url_for(addon.featured), 'plugin://plugin.video.vrt.nu/featured')

# Featured programs menu: '/featured/<cfeatured>'
def test_featured_tvshow_menu(self):
addon.plugin.run(['plugin://plugin.video.vrt.nu/featured/kortfilm', '0', ''])
self.assertEqual(addon.plugin.url_for(addon.featured, feature='kortfilm'), 'plugin://plugin.video.vrt.nu/featured/kortfilm')

# Channels menu = '/channels/<channel>'
def test_channels_menu(self):
addon.plugin.run(['plugin://plugin.video.vrt.nu/channels', '0', ''])
Expand Down
10 changes: 8 additions & 2 deletions test/vrtplayertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def test_show_videos_specific_seasons_shows_videos(self):
def test_categories_scraping(self):
''' Test to ensure our hardcoded categories conforms to scraped categories '''
# Remove thumbnails from scraped categories first
categories = [dict(id=c['id'], name=c['name']) for c in self._apihelper.get_categories()]
self.assertEqual(categories, CATEGORIES)
categories_scraped = [dict(id=c['id'], name=c['name']) for c in self._apihelper.get_categories()]
categories_stored = [dict(id=c['id'], name=c['name']) for c in CATEGORIES]
self.assertEqual(categories_scraped, categories_stored)

def test_random_tvshow_episodes(self):
''' Rest episode from a random tvshow in a random category '''
Expand All @@ -95,6 +96,11 @@ def test_categories(self):
category_items = self._apihelper.get_category_items()
self.assertEqual(len(category_items), 17)

def test_featured(self):
''' Test to ensure our hardcoded categories conforms to scraped categories '''
featured_items = self._apihelper.get_featured_items()
self.assertEqual(len(featured_items), 7)


if __name__ == '__main__':
unittest.main()

0 comments on commit 17a4441

Please sign in to comment.