Skip to content

Commit

Permalink
Add channels menu
Browse files Browse the repository at this point in the history
This PR includes the long-expected channels menu item
  • Loading branch information
dagwieers committed May 4, 2019
1 parent ac6ca9b commit 5a19695
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 47 deletions.
8 changes: 5 additions & 3 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ def router(params_string):
vrt_player = vrtplayer.VRTPlayer(kodi_wrapper, api_helper)

if action == actions.LISTING_AZ_TVSHOWS:
vrt_player.show_tvshow_menu_items(path=None)
vrt_player.show_tvshow_menu_items()
elif action == actions.LISTING_CATEGORIES:
vrt_player.show_category_menu_items()
elif action == actions.LISTING_CHANNELS:
vrt_player.show_channels_menu_items(channel=params.get('channel'))
elif action == actions.LISTING_LIVE:
vrt_player.show_livestream_items()
elif action == actions.LISTING_EPISODES:
vrt_player.show_episodes(path=params.get('video_url'))
elif action == actions.LISTING_RECENT:
vrt_player.show_recent(page=params.get('page'))
vrt_player.show_recent(page=params.get('page', 1))
elif action == actions.LISTING_CATEGORY_TVSHOWS:
vrt_player.show_tvshow_menu_items(path=params.get('video_url'))
vrt_player.show_tvshow_menu_items(category=params.get('category'))
elif action == actions.PLAY:
vrt_player.play(params)
else:
Expand Down
18 changes: 13 additions & 5 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,34 @@ msgid "TV programs listed by category"
msgstr "TV programs listed by category"

msgctxt "#32084"
msgid "Channels"
msgstr "Channels"

msgctxt "#32085"
msgid "TV programs listed by channel"
msgstr "TV programs listed by channel"

msgctxt "#32086"
msgid "Live TV"
msgstr "Live TV"

msgctxt "#32085"
msgctxt "#32087"
msgid "Watch TV channels live (using Internet streaming)"
msgstr "Watch TV channels live (using Internet streaming)"

msgctxt "#32086"
msgctxt "#32088"
msgid "Most recent"
msgstr "Most recent"

msgctxt "#32087"
msgctxt "#32089"
msgid "Recently published episodes of TV programs"
msgstr "Recently published episodes of TV programs"

msgctxt "#32088"
msgctxt "#32090"
msgid "TV guide"
msgstr "TV guide"

msgctxt "#32089"
msgctxt "#32091"
msgid "Browse channel TV guides"
msgstr "Browse channel TV guides"

Expand Down
22 changes: 15 additions & 7 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,37 @@ msgstr "Categorieën"

msgctxt "#32083"
msgid "TV programs listed by category"
msgstr "Lijst van tv-programma's per categorie"
msgstr "Lijst van TV-programma's per categorie"

msgctxt "#32084"
msgid "Channels"
msgstr "Kanalen"

msgctxt "#32085"
msgid "TV programs listed by channel"
msgstr "Lijst van TV-programma's per kanaal"

msgctxt "#32086"
msgid "Live TV"
msgstr "Live kijken"

msgctxt "#32085"
msgctxt "#32087"
msgid "Watch TV channels live (using Internet streaming)"
msgstr "Bekijk tv-kanalen live (via Internet)"
msgstr "Bekijk TV-kanalen live (via Internet)"

msgctxt "#32086"
msgctxt "#32088"
msgid "Most recent"
msgstr "Meest recent"

msgctxt "#32087"
msgctxt "#32089"
msgid "Recently published episodes of TV programs"
msgstr "Recent gepubliceerde afleveringen van tv-programma's"

msgctxt "#32088"
msgctxt "#32090"
msgid "TV guide"
msgstr "TV-gids"

msgctxt "#32089"
msgctxt "#32091"
msgid "Browse channel TV guides"
msgstr "Doorzoek de TV-gids per kanaal"

Expand Down
1 change: 1 addition & 0 deletions resources/lib/vrtplayer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
LISTING_AZ_TVSHOWS = 'listingaztvshows'
LISTING_CATEGORIES = 'listingcategories'
LISTING_CATEGORY_TVSHOWS = 'listingcategorytvshows'
LISTING_CHANNELS = 'listingchannels'
LISTING_EPISODES = 'listingepisodes'
LISTING_LIVE = 'listinglive'
LISTING_RECENT = 'listingrecent'
Expand Down
17 changes: 11 additions & 6 deletions resources/lib/vrtplayer/vrtapihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ def __init__(self, kodi_wrapper):
install_opener(build_opener(ProxyHandler(self._proxies)))
self._showpermalink = kodi_wrapper.get_setting('showpermalink') == 'true'

def get_tvshow_items(self, path=None):
def get_tvshow_items(self, category=None, channel=None):
import json
if path:
params = {'facets[categories]': path}
api_url = self._VRTNU_SUGGEST_URL + '?' + urlencode(params)
params = dict()

if category:
params['facets[categories]'] = category
else:
# If no path is provided, we return the A-Z listing
params = {'facets[transcodingStatus]': 'AVAILABLE'}
api_url = self._VRTNU_SUGGEST_URL + '?' + urlencode(params)
params['facets[transcodingStatus]'] = 'AVAILABLE'

if channel:
params['facets[brands]'] = channel

api_url = self._VRTNU_SUGGEST_URL + '?' + urlencode(params)
# tvshows = requests.get(api_url, proxies=self._proxies).json()
tvshows = json.loads(urlopen(api_url).read())
tvshow_items = []
Expand Down
78 changes: 52 additions & 26 deletions resources/lib/vrtplayer/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,70 +64,96 @@ def show_main_menu_items(self):
art_dict=dict(thumb='DefaultGenre.png', icon='DefaultGenre.png', fanart='DefaultGenre.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32083))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32084),
url_dict=dict(action=actions.LISTING_LIVE),
url_dict=dict(action=actions.LISTING_CHANNELS),
is_playable=False,
art_dict=dict(thumb='DefaultAddonPVRClient.png', icon='DefaultAddonPVRClient.png', fanart='DefaultAddonPVRClient.png'),
art_dict=dict(thumb='DefaultTags.png', icon='DefaultTags.png', fanart='DefaultTags.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32085))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32086),
url_dict=dict(action=actions.LISTING_RECENT, page='1'),
url_dict=dict(action=actions.LISTING_LIVE),
is_playable=False,
art_dict=dict(thumb='DefaultYear.png', icon='DefaultYear.png', fanart='DefaultYear.png'),
art_dict=dict(thumb='DefaultAddonPVRClient.png', icon='DefaultAddonPVRClient.png', fanart='DefaultAddonPVRClient.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32087))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32088),
url_dict=dict(action=actions.LISTING_RECENT, page='1'),
is_playable=False,
art_dict=dict(thumb='DefaultYear.png', icon='DefaultYear.png', fanart='DefaultYear.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32089))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32090),
url_dict=dict(action=actions.LISTING_TVGUIDE),
is_playable=False,
art_dict=dict(thumb='DefaultAddonTvInfo.png', icon='DefaultAddonTvInfo.png', fanart='DefaultAddonTvInfo.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32089))),
]
self._kodi_wrapper.show_listing(main_items)

def show_tvshow_menu_items(self, path):
tvshow_items = self._api_helper.get_tvshow_items(path)
def show_tvshow_menu_items(self, category=None):
tvshow_items = self._api_helper.get_tvshow_items(category=category)
self._kodi_wrapper.show_listing(tvshow_items, sort='label', content_type='tvshows')

def show_category_menu_items(self):
category_items = self.__get_category_menu_items()
self._kodi_wrapper.show_listing(category_items, sort='label', content_type='files')

def show_channels_menu_items(self, channel=None):
if channel:
tvshow_items = self._api_helper.get_tvshow_items(channel=channel)
self._kodi_wrapper.show_listing(tvshow_items, sort='label', content_type='tvshows')
else:
self.show_channels(action=actions.LISTING_CHANNELS,
channels=['een', 'canvas', 'sporza', 'ketnet-jr', 'ketnet', 'stubru', 'mnm', 'vrtnws', 'vrtnxt'])

def show_livestream_items(self):
self.show_channels(action=actions.PLAY,
channels=['een', 'canvas', 'sporza', 'ketnet', 'stubru', 'mnm'])

def show_channels(self, action=actions.PLAY, channels=None):
from resources.lib.vrtplayer import CHANNELS

fanart_path = 'resource://resource.images.studios.white/%(studio)s.png'
icon_path = 'resource://resource.images.studios.white/%(studio)s.png'
# NOTE: Wait for resource.images.studios.coloured v0.16 to be released
# icon_path = 'resource://resource.images.studios.coloured/%(studio)s.png'

livestream_items = []
for channel in ['een', 'canvas', 'ketnet', 'sporza', 'stubru', 'mnm']:
channel_items = []
for channel in channels:

icon = icon_path % CHANNELS[channel]
if channel in ['een', 'canvas', 'ketnet']:
fanart = self._api_helper.get_live_screenshot(channel)
plot = self._kodi_wrapper.get_localized_string(32201) + '\n' + self._kodi_wrapper.get_localized_string(32102) % CHANNELS[channel].get('name')
else:
fanart = fanart_path % CHANNELS[channel]
plot = self._kodi_wrapper.get_localized_string(32102) % CHANNELS[channel].get('name')

url_dict = dict(action=actions.PLAY)
if CHANNELS[channel].get('live_stream'):
url_dict['video_url'] = CHANNELS[channel].get('live_stream')
if CHANNELS[channel].get('live_stream_id'):
url_dict['video_id'] = CHANNELS[channel].get('live_stream_id')
fanart = fanart_path % CHANNELS[channel]

livestream_items.append(helperobjects.TitleItem(
title=self._kodi_wrapper.get_localized_string(32101) % CHANNELS[channel].get('name'),
if action == actions.LISTING_CHANNELS:
url_dict = dict(action=action, channel=channel)
label = CHANNELS[channel].get('name')
plot = '[B]%s[/B]' % CHANNELS[channel].get('name')
is_playable = False
else:
url_dict = dict(action=action)
label = self._kodi_wrapper.get_localized_string(32101) % CHANNELS[channel].get('name')
is_playable = True
if channel in ['een', 'canvas', 'ketnet']:
fanart = self._api_helper.get_live_screenshot(channel)
plot = '%s\n%s' % (self._kodi_wrapper.get_localized_string(32201),
self._kodi_wrapper.get_localized_string(32102) % CHANNELS[channel].get('name'))
else:
plot = self._kodi_wrapper.get_localized_string(32102) % CHANNELS[channel].get('name')
if CHANNELS[channel].get('live_stream'):
url_dict['video_url'] = CHANNELS[channel].get('live_stream')
if CHANNELS[channel].get('live_stream_id'):
url_dict['video_id'] = CHANNELS[channel].get('live_stream_id')

channel_items.append(helperobjects.TitleItem(
title=label,
url_dict=url_dict,
is_playable=True,
is_playable=is_playable,
art_dict=dict(thumb=icon, icon=icon, fanart=fanart),
video_dict=dict(
title=self._kodi_wrapper.get_localized_string(32101) % CHANNELS[channel].get('name'),
title=label,
plot=plot,
studio=CHANNELS[channel].get('studio'),
mediatype='video',
),
))

self._kodi_wrapper.show_listing(livestream_items, cache=False)
self._kodi_wrapper.show_listing(channel_items, cache=False)

def show_episodes(self, path):
episode_items, sort, ascending = self._api_helper.get_episode_items(path=path)
Expand Down Expand Up @@ -173,7 +199,7 @@ def __get_category_menu_items(self):
for category in categories:
thumbnail = category.get('thumbnail', 'DefaultGenre.png')
category_items.append(helperobjects.TitleItem(title=category.get('name'),
url_dict=dict(action=actions.LISTING_CATEGORY_TVSHOWS, video_url=category.get('id')),
url_dict=dict(action=actions.LISTING_CATEGORY_TVSHOWS, category=category.get('id')),
is_playable=False,
art_dict=dict(thumb=thumbnail, icon='DefaultGenre.png', fanart=thumbnail),
video_dict=dict(plot='[B]%s[/B]' % category.get('name'), studio='VRT')))
Expand Down

0 comments on commit 5a19695

Please sign in to comment.