Skip to content

Commit

Permalink
Rework Kids zone (#67)
Browse files Browse the repository at this point in the history
This makes the Kids zone part of the routing.
  • Loading branch information
dagwieers authored and michaelarnauts committed Sep 13, 2019
1 parent ea21cdd commit c26890e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 41 deletions.
6 changes: 5 additions & 1 deletion resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ msgid "Features"
msgstr ""

msgctxt "#30823"
msgid "Force Kids Zone"
msgid "Use Kids zone"
msgstr ""

msgctxt "#30825"
msgid "Force Kids zone"
msgstr ""

msgctxt "#30860"
Expand Down
99 changes: 67 additions & 32 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
plugin = routing.Plugin()


@plugin.route('/kids')
def show_kids_index():
show_index()


@plugin.route('/')
def show_index():
kids = _get_kids_mode()
Expand All @@ -27,57 +32,62 @@ def show_index():
listitem = ListItem(localize(30001), offscreen=True) # A-Z
listitem.setArt({'icon': 'DefaultMovieTitle.png'})
listitem.setInfo('video', {
'plot': localize(30002) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30002),
})
listing.append((plugin.url_for(show_catalog, category='all', kids=kids), listitem, True))
route_catalog = show_kids_catalog if kids else show_catalog
listing.append((plugin.url_for(route_catalog, category='all'), listitem, True))

listitem = ListItem(localize(30003), offscreen=True) # Catalogue
listitem.setArt({'icon': 'DefaultGenre.png'})
listitem.setInfo('video', {
'plot': localize(30004) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30004),
})
listing.append((plugin.url_for(show_catalog, kids=kids), listitem, True))
listing.append((plugin.url_for(route_catalog), listitem, True))

listitem = ListItem(localize(30005), offscreen=True) # Live TV
listitem.setArt({'icon': 'DefaultAddonPVRClient.png'})
listitem.setInfo('video', {
'plot': localize(30006) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30006),
})
listing.append((plugin.url_for(show_livetv, kids=kids), listitem, True))
route_livetv = show_kids_livetv if kids else show_livetv
listing.append((plugin.url_for(route_livetv), listitem, True))

listitem = ListItem(localize(30013), offscreen=True) # TV Guide
listitem.setArt({'icon': 'DefaultAddonTvInfo.png'})
listitem.setInfo('video', {
'plot': localize(30014) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30014),
})
listing.append((plugin.url_for(show_tvguide, kids=kids), listitem, True))
route_tvguide = show_kids_tvguide if kids else show_tvguide
listing.append((plugin.url_for(route_tvguide), 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
listitem.setArt({'icon': 'DefaultTags.png'})
listitem.setInfo('video', {
'plot': localize(30008) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30008),
})
listing.append((plugin.url_for(show_youtube, kids=kids), listitem, True))
route_youtube = show_kids_youtube if kids else show_youtube
listing.append((plugin.url_for(route_youtube), listitem, True))

listitem = ListItem(localize(30009), offscreen=True) # Search
listitem.setArt({'icon': 'DefaultAddonsSearch.png'})
listitem.setInfo('video', {
'plot': localize(30010) + ('\n\n' + localize(30201) if kids else ''),
'plot': localize(30010),
})
listing.append((plugin.url_for(show_search, kids=kids), listitem, True))
route_search = show_kids_search if kids else show_search
listing.append((plugin.url_for(route_search), listitem, True))

if get_setting_as_bool('kids_mode_switching') and not kids:
if get_setting_as_bool('use_kids_zone') and not kids:
listitem = ListItem(localize(30011), offscreen=True) # Kids Zone
listitem.setArt({'icon': 'DefaultUser.png'})
listitem.setInfo('video', {
'plot': localize(30012),
})
listing.append((plugin.url_for(show_index, kids=True), listitem, True))
listing.append((plugin.url_for(show_kids_index), listitem, True))

xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.setPluginCategory(plugin.handle, category='VTM GO')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS' if kids else 'VTM GO')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)

Expand All @@ -97,6 +107,11 @@ def check_credentials():
show_settings()


@plugin.route('/kids/livetv')
def show_kids_livetv():
show_livetv()


@plugin.route('/livetv')
def show_livetv():
kids = _get_kids_mode()
Expand Down Expand Up @@ -143,17 +158,22 @@ def show_livetv():
# Sort live channels 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='VTM GO / Live TV')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / Live TV' if kids else 'VTM GO / Live TV')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/kids/tvguide')
def show_kids_tvguide():
show_tvguide()


@plugin.route('/tvguide')
@plugin.route('/tvguide/<channel>')
def show_tvguide(channel=None):
listing = []
kids = _get_kids_mode()
if channel is None:
kids = _get_kids_mode()
# Show a list of all channels
from . import CHANNELS
for entry in CHANNELS:
Expand All @@ -177,7 +197,7 @@ def show_tvguide(channel=None):

listitem = ListItem(entry.get('label'), offscreen=True)
listitem.setInfo('video', {
'plot': localize(2330206, label=entry),
'plot': localize(30206, label=entry),
'studio': entry.get('studio'),
'mediatype': 'video',
})
Expand Down Expand Up @@ -206,7 +226,7 @@ def show_tvguide(channel=None):

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

xbmcplugin.setPluginCategory(plugin.handle, category='VTM GO / TV Guide')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / TV Guide' if kids else 'VTM GO / TV Guide')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)

Expand Down Expand Up @@ -254,10 +274,17 @@ def show_tvguide_detail(channel=None, date=None):
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=False)


@plugin.route('/kids/catalog')
@plugin.route('/kids/catalog/<category>')
def show_kids_catalog(category=None):
show_catalog(category)


@plugin.route('/catalog')
@plugin.route('/catalog/<category>')
def show_catalog(category=None):
kids = _get_kids_mode()
route_catalog = show_kids_catalog if kids else show_catalog

listing = []
if category is None:
Expand All @@ -274,12 +301,12 @@ def show_catalog(category=None):
listitem.setInfo('video', {
'plot': '[B]{category}[/B]'.format(category=cat.title),
})
listing.append((plugin.url_for(show_catalog, category=cat.id, kids=kids), listitem, True))
listing.append((plugin.url_for(route_catalog, category=cat.id), listitem, True))

# 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='VTM GO / Catalogue')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / Catalogue' if kids else 'VTM GO / Catalogue')

else:
# Show the items of a category
Expand Down Expand Up @@ -307,7 +334,7 @@ def show_catalog(category=None):
listing.append((plugin.url_for(play_movie, movie=item.id), listitem, False))

elif item.type == Content.CONTENT_TYPE_PROGRAM:
listing.append((plugin.url_for(show_program, program=item.id, kids=kids), listitem, True))
listing.append((plugin.url_for(show_program, program=item.id), listitem, True))

if category == 'films':
xbmcplugin.setContent(plugin.handle, 'movies')
Expand Down Expand Up @@ -388,7 +415,7 @@ def show_program(program, season=None):
'plot': _format_plot(program_obj),
'set': program_obj.name,
})
listing.append((plugin.url_for(show_program, program=program, season='all', kids=kids), listitem, True))
listing.append((plugin.url_for(show_program, program=program, season='all'), listitem, True))

for s in program_obj.seasons.values():
listitem = ListItem(localize(30205, season=s.number), offscreen=True) # Season X
Expand Down Expand Up @@ -457,6 +484,11 @@ def show_program(program, season=None):
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/kids/youtube')
def show_kids_youtube():
show_youtube()


@plugin.route('/youtube')
def show_youtube():
kids = _get_kids_mode()
Expand Down Expand Up @@ -485,7 +517,7 @@ def show_youtube():

listitem = ListItem(entry.get('label'), offscreen=True)
listitem.setInfo('video', {
'plot': localize(2330206, label=entry),
'plot': localize(30206, label=entry),
'studio': entry.get('studio'),
'mediatype': 'video',
})
Expand All @@ -499,11 +531,16 @@ def show_youtube():
# Sort by default like in our dict.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.setPluginCategory(plugin.handle, category='VTM GO / YouTube')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / YouTube' if kids else 'VTM GO / YouTube')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/kids/search')
def show_kids_search():
show_search()


@plugin.route('/search')
def show_search():
kids = _get_kids_mode()
Expand Down Expand Up @@ -538,14 +575,14 @@ def show_search():
listitem.setInfo('video', {
'mediatype': None, # This shows a folder icon
})
listing.append((plugin.url_for(show_program, program=item.id, kids=kids), listitem, True))
listing.append((plugin.url_for(show_program, program=item.id), listitem, True))

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

# Sort like we get our results back.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_FOLDERS)
xbmcplugin.setPluginCategory(plugin.handle, category='VTM GO / Search')
xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / Search' if kids else 'VTM GO / Search')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)

Expand Down Expand Up @@ -685,13 +722,11 @@ def _stream(strtype, strid):


def _get_kids_mode():
if get_setting_as_bool('kids_zone_forced'):
if get_setting_as_bool('use_kids_zone') and get_setting_as_bool('force_kids_zone'):
return True

# kids will contain a string of 'True' or 'False'
kids = plugin.args.get('kids')
if kids:
return kids[0] == 'True'
if plugin.path.startswith('/kids'):
return True
return False


Expand Down
3 changes: 2 additions & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</category>
<category label="30820"> <!-- Interface -->
<setting label="30821" type="lsep"/> <!-- Features -->
<setting label="30823" help="30824" type="bool" id="kids_zone_forced" default="false"/>
<setting label="30823" help="30824" type="bool" id="use_kids_zone" default="false"/>
<setting label="30825" help="30826" type="bool" id="force_kids_zone" default="false" enable="eq(-1,true)" subsetting="true"/>
</category>
<category label="30860"> <!-- Playback -->
<setting label="30861" type="lsep"/> <!-- Subtitles -->
Expand Down
18 changes: 14 additions & 4 deletions test/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_main_menu(self):
self.assertEqual(addon.url_for(plugin.show_index), 'plugin://plugin.video.vtm.go/')

def test_kids_zone(self):
plugin.run(['plugin://plugin.video.vtm.go/', '0', 'kids=True'])
self.assertEqual(addon.url_for(plugin.show_index, kids=True), 'plugin://plugin.video.vtm.go/?kids=True')
plugin.run(['plugin://plugin.video.vtm.go/kids', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_index), 'plugin://plugin.video.vtm.go/kids')

# Check credentials: '/check-credentials'
# def test_check_credentials(self):
Expand All @@ -36,6 +36,8 @@ def test_kids_zone(self):
def test_livetv_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/livetv', '0', ''])
self.assertEqual(addon.url_for(plugin.show_livetv), 'plugin://plugin.video.vtm.go/livetv')
plugin.run(['plugin://plugin.video.vtm.go/kids/livetv', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_livetv), 'plugin://plugin.video.vtm.go/kids/livetv')

# Episodes menu: '/program/<program>'
def test_program_menu(self):
Expand All @@ -55,11 +57,15 @@ def test_program_season_menu(self):
def test_catalog_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/catalog', '0', ''])
self.assertEqual(addon.url_for(plugin.show_catalog), 'plugin://plugin.video.vtm.go/catalog')
plugin.run(['plugin://plugin.video.vtm.go/kids/catalog', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_catalog), 'plugin://plugin.video.vtm.go/kids/catalog')

# Catalogue menu: '/catalog/<category>'
def test_catalog_category_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/catalog/films', '0', ''])
self.assertEqual(addon.url_for(plugin.show_catalog, category='films'), 'plugin://plugin.video.vtm.go/catalog/films')
plugin.run(['plugin://plugin.video.vtm.go/kids/catalog/films', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_catalog, category='films'), 'plugin://plugin.video.vtm.go/kids/catalog/films')
plugin.run(['plugin://plugin.video.vtm.go/catalog/kids', '0', ''])
self.assertEqual(addon.url_for(plugin.show_catalog, category='kids'), 'plugin://plugin.video.vtm.go/catalog/kids')
plugin.run(['plugin://plugin.video.vtm.go/catalog/nieuws-actua', '0', ''])
Expand All @@ -76,20 +82,24 @@ def test_movies(self):
def test_youtube_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/youtube', '0', ''])
self.assertEqual(addon.url_for(plugin.show_youtube), 'plugin://plugin.video.vtm.go/youtube')
plugin.run(['plugin://plugin.video.vtm.go/kids/youtube', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_youtube), 'plugin://plugin.video.vtm.go/kids/youtube')

# Search menu: '/search'
def test_search_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/search', '0', ''])
self.assertEqual(addon.url_for(plugin.show_search), 'plugin://plugin.video.vtm.go/search')
plugin.run(['plugin://plugin.video.vtm.go/kids/search', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_search), 'plugin://plugin.video.vtm.go/kids/search')

# TV Guide menu: '/tvguide'
def test_tvguide_menu(self):
plugin.run(['plugin://plugin.video.vtm.go/tvguide', '0', ''])
self.assertEqual(addon.url_for(plugin.show_tvguide), 'plugin://plugin.video.vtm.go/tvguide')

plugin.run(['plugin://plugin.video.vtm.go/kids/tvguide', '0', ''])
self.assertEqual(addon.url_for(plugin.show_kids_tvguide), 'plugin://plugin.video.vtm.go/kids/tvguide')
plugin.run(['plugin://plugin.video.vtm.go/tvguide/vtm', '0', ''])
self.assertEqual(addon.url_for(plugin.show_tvguide, channel='vtm'), 'plugin://plugin.video.vtm.go/tvguide/vtm')

# plugin.run(['plugin://plugin.video.vtm.go/tvguide/vtm/2019-01-01', '0', ''])
self.assertEqual(addon.url_for(plugin.show_tvguide_detail, channel='vtm', date='2019-01-01'), 'plugin://plugin.video.vtm.go/tvguide/vtm/2019-01-01')

Expand Down
5 changes: 3 additions & 2 deletions test/userdata/addon_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"plugin.video.vtm.go": {
"_comment": "do-not-add-email-and-password-here",
"email": "",
"kids_mode_switching": "true",
"force_kids_zone": "false",
"log_level": "Info",
"max_bandwidth": 4096,
"password": "",
"show_subtitles": "true"
"show_subtitles": "true",
"use_kids_zone": "true"
}
}
2 changes: 1 addition & 1 deletion test/xbmcaddon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def getLocalizedString(msgctxt):
for entry in PO:
if entry.msgctxt == '#%s' % msgctxt:
return entry.msgstr or entry.msgid
print('ERROR: Unable to translate #{msgctxt}')
print('ERROR: Unable to translate #{msgctxt}'.format(msgctxt=msgctxt))
return '<Untranslated>'

def getSetting(self, key):
Expand Down

0 comments on commit c26890e

Please sign in to comment.