From 864e9c24202868fc5f3f9392d096eeca48d5d992 Mon Sep 17 00:00:00 2001 From: mediaminister <45148099+mediaminister@users.noreply.github.com> Date: Fri, 3 May 2019 20:22:59 +0200 Subject: [PATCH] Add page-browsing to recent menu --- addon.py | 2 ++ .../resource.language.en_gb/strings.po | 4 ++++ .../resource.language.nl_nl/strings.po | 4 ++++ resources/lib/vrtplayer/actions.py | 4 ++-- resources/lib/vrtplayer/vrtapihelper.py | 15 ++++++++----- resources/lib/vrtplayer/vrtplayer.py | 21 +++++++++++++++++-- test/vrtplayertests.py | 15 +++++++------ 7 files changed, 48 insertions(+), 17 deletions(-) diff --git a/addon.py b/addon.py index 2f2a15e9..ff60ec3d 100644 --- a/addon.py +++ b/addon.py @@ -46,6 +46,8 @@ def router(params_string): 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')) elif action == actions.LISTING_CATEGORY_TVSHOWS: vrt_player.show_tvshow_menu_items(path=params.get('video_url')) elif action == actions.PLAY: diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 6a0fa923..59e19c56 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -155,6 +155,10 @@ msgctxt "#32204" msgid "[B][COLOR green](%s hours left)[/COLOR][/B]\n" msgstr "[B][COLOR green](%s hours left)[/COLOR][/B]\n" +msgctxt "#32300" +msgid "[B][COLOR yellow]More...[/COLOR][/B]" +msgstr "[B][COLOR yellow]More...[/COLOR][/B]" + msgctxt "#32301" msgid "[B]TV guide for channel %s[/B]" msgstr "[B]TV guide for channel %s[/B]" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 78e25f49..189975b4 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -156,6 +156,10 @@ msgctxt "#32204" msgid "[B][COLOR green](%s hours left)[/COLOR][/B]\n" msgstr "[B][COLOR green](nog %s uur)[/COLOR][/B]\n" +msgctxt "#32300" +msgid "[B][COLOR yellow]More...[/COLOR][/B]" +msgstr "[B][COLOR yellow]Meer...[/COLOR][/B]" + msgctxt "#32301" msgid "[B]TV guide for channel %s[/B]" msgstr "[B]TV-gids for kanaal %s[/B]" diff --git a/resources/lib/vrtplayer/actions.py b/resources/lib/vrtplayer/actions.py index 96ec0ee9..33ce9ec1 100644 --- a/resources/lib/vrtplayer/actions.py +++ b/resources/lib/vrtplayer/actions.py @@ -7,10 +7,10 @@ LISTING_AZ_TVSHOWS = 'listingaztvshows' LISTING_CATEGORIES = 'listingcategories' -LISTING_LIVE = 'listinglive' - LISTING_CATEGORY_TVSHOWS = 'listingcategorytvshows' LISTING_EPISODES = 'listingepisodes' +LISTING_LIVE = 'listinglive' +LISTING_RECENT = 'listingrecent' LISTING_TVGUIDE = 'listingtvguide' PLAY = 'play' diff --git a/resources/lib/vrtplayer/vrtapihelper.py b/resources/lib/vrtplayer/vrtapihelper.py index 5504913f..2a19f2b9 100644 --- a/resources/lib/vrtplayer/vrtapihelper.py +++ b/resources/lib/vrtplayer/vrtapihelper.py @@ -76,23 +76,28 @@ def _get_season_items(self, api_url, api_json): season_items, sort, ascending = self._map_to_season_items(api_url, facet.get('buckets', []), episode) return season_items, sort, ascending - def get_episode_items(self, path): + def get_episode_items(self, path=None, page=None): import json episode_items = [] sort = 'episode' ascending = True - if path == 'recent': + + # Recent items + if page: + entries = 50 params = { + 'from': (page - 1) * entries, 'i': 'video', - 'size': '100', + 'size': entries, 'facets[transcodingStatus]': 'AVAILABLE', 'facets[brands]': '[een,canvas,sporza,vrtnws,vrtnxt,radio1,radio2,klara,stubru,mnm]', } api_url = self._VRTNU_SEARCH_URL + '?' + urlencode(params) # api_json = requests.get(api_url, proxies=self._proxies).json() api_json = json.loads(urlopen(api_url).read()) - episode_items, sort, ascending = self._map_to_episode_items(api_json.get('results', []), path) - else: + episode_items, sort, ascending = self._map_to_episode_items(api_json.get('results', []), titletype='recent') + + if path: if '.relevant/' in path: params = { 'i': 'video', diff --git a/resources/lib/vrtplayer/vrtplayer.py b/resources/lib/vrtplayer/vrtplayer.py index aa17ae85..2074199b 100644 --- a/resources/lib/vrtplayer/vrtplayer.py +++ b/resources/lib/vrtplayer/vrtplayer.py @@ -69,7 +69,7 @@ def show_main_menu_items(self): art_dict=dict(thumb='DefaultAddonPVRClient.png', icon='DefaultAddonPVRClient.png', fanart='DefaultAddonPVRClient.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_EPISODES, video_url='recent'), + 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(32087))), @@ -130,7 +130,24 @@ def show_livestream_items(self): self._kodi_wrapper.show_listing(livestream_items, cache=False) def show_episodes(self, path): - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) + self._kodi_wrapper.show_listing(episode_items, sort=sort, ascending=ascending, content_type='episodes') + + def show_recent(self, page): + try: + page = int(page) + except TypeError: + page = 1 + + episode_items, sort, ascending = self._api_helper.get_episode_items(page=page) + + # Add 'More...' entry at the end + episode_items.append(helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32300), + url_dict=dict(action=actions.LISTING_RECENT, page=page + 1), + is_playable=False, + art_dict=dict(thumb='DefaultYear.png', icon='DefaultYear.png', fanart='DefaultYear.png'), + video_dict=dict())) + self._kodi_wrapper.show_listing(episode_items, sort=sort, ascending=ascending, content_type='episodes', cache=False) def play(self, params): diff --git a/test/vrtplayertests.py b/test/vrtplayertests.py index 95f7630e..d4a8247c 100644 --- a/test/vrtplayertests.py +++ b/test/vrtplayertests.py @@ -19,7 +19,7 @@ class TestVRTPlayer(unittest.TestCase): def test_show_videos_single_episode_shows_videos(self): path = '/vrtnu/a-z/marathonradio.relevant/' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) self.assertTrue(episode_items, msg=path) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) @@ -30,7 +30,7 @@ def test_show_videos_single_episode_shows_videos(self): def test_show_videos_single_season_shows_videos(self): path = '/vrtnu/a-z/het-weer.relevant/' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) self.assertTrue(episode_items, msg=path) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) @@ -41,7 +41,7 @@ def test_show_videos_single_season_shows_videos(self): def test_show_videos_multiple_seasons_shows_videos(self): path = '/vrtnu/a-z/pano.relevant/' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) self.assertTrue(episode_items) self.assertEqual(sort, 'label') self.assertFalse(ascending) @@ -52,7 +52,7 @@ def test_show_videos_multiple_seasons_shows_videos(self): def test_show_videos_specific_seasons_shows_videos(self): path = '/vrtnu/a-z/thuis.relevant/' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) self.assertTrue(episode_items, msg=path) self.assertEqual(sort, 'label') self.assertFalse(ascending) @@ -63,16 +63,15 @@ def test_show_videos_specific_seasons_shows_videos(self): def test_get_recent_episodes(self): ''' Test items, sort and order ''' - path = 'recent' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) - self.assertTrue(episode_items) + episode_items, sort, ascending = self._api_helper.get_episode_items(page=1) + self.assertEqual(len(episode_items), 50) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) def test_get_program_episodes(self): ''' Test items, sort and order ''' path = '/vrtnu/a-z/het-journaal.relevant/' - episode_items, sort, ascending = self._api_helper.get_episode_items(path) + episode_items, sort, ascending = self._api_helper.get_episode_items(path=path) self.assertTrue(episode_items) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending)