diff --git a/resources/lib/favorites.py b/resources/lib/favorites.py index b96de5a70..411a3c560 100644 --- a/resources/lib/favorites.py +++ b/resources/lib/favorites.py @@ -6,6 +6,7 @@ ''' Implementation of Favorites class ''' from __future__ import absolute_import, division, unicode_literals +from resources.lib import statichelper try: # Python 3 from urllib.request import build_opener, install_opener, ProxyHandler, Request, urlopen @@ -54,12 +55,12 @@ def get_favorites(self, ttl=None): self._kodi.update_cache('favorites.json', api_json) self._favorites = api_json - def set_favorite(self, program, path, value=True): + def set_favorite(self, title, program, value=True): ''' Set a program as favorite, and update local copy ''' import json self.get_favorites(ttl=60 * 60) - if value is self.is_favorite(path): + if value is self.is_favorite(program): # Already followed/unfollowed, nothing to do return True @@ -74,63 +75,55 @@ def set_favorite(self, program, path, value=True): 'content-type': 'application/json', 'Referer': 'https://www.vrt.be/vrtnu', } - payload = dict(isFavorite=value, programUrl=path, title=program) + payload = dict(isFavorite=value, programUrl=statichelper.program_to_short_program_url(program), title=title) data = json.dumps(payload).encode('utf-8') - self._kodi.log_notice('URL post: https://video-user-data.vrt.be/favorites/%s' % self.uuid(path), 'Verbose') - req = Request('https://video-user-data.vrt.be/favorites/%s' % self.uuid(path), data=data, headers=headers) + self._kodi.log_notice('URL post: https://video-user-data.vrt.be/favorites/%s' % self.uuid(program), 'Verbose') + req = Request('https://video-user-data.vrt.be/favorites/%s' % self.uuid(program), data=data, headers=headers) result = urlopen(req) if result.getcode() != 200: - self._kodi.show_notification(message="Failed to (un)follow program '%s' at VRT NU" % path) - self._kodi.log_error("Failed to (un)follow program '%s' at VRT NU" % path) + self._kodi.show_notification(message="Failed to (un)follow program '%s' at VRT NU" % program) + self._kodi.log_error("Failed to (un)follow program '%s' at VRT NU" % program) return False # NOTE: Updates to favorites take a longer time to take effect, so we keep our own cache and use it - self._favorites[self.uuid(path)] = dict(value=payload) + self._favorites[self.uuid(program)] = dict(value=payload) self._kodi.update_cache('favorites.json', self._favorites) self.invalidate_caches() return True - def is_favorite(self, path): + def is_favorite(self, program): ''' Is a program a favorite ? ''' value = False - favorite = self._favorites.get(self.uuid(path)) + favorite = self._favorites.get(self.uuid(program)) if favorite is not None: value = favorite.get('value', dict(isFavorite=False)).get('isFavorite', False) return value - def follow(self, program, path): + def follow(self, title, program): ''' Follow your favorite program ''' - ok = self.set_favorite(program, path, True) + ok = self.set_favorite(title, program, True) if ok: - self._kodi.show_notification(message='Follow ' + program) + self._kodi.show_notification(message='Follow ' + title) self._kodi.container_refresh() - def unfollow(self, program, path): + def unfollow(self, title, program): ''' Unfollow your favorite program ''' - ok = self.set_favorite(program, path, False) + ok = self.set_favorite(title, program, False) if ok: - self._kodi.show_notification(message='Unfollow ' + program) + self._kodi.show_notification(message='Unfollow ' + title) self._kodi.container_refresh() - def uuid(self, path): - ''' Return a favorite uuid, used for lookups in favorites dict ''' - return path.replace('/', '').replace('-', '') - - def name(self, path): - ''' Return the favorite name ''' - try: - return path.replace('.relevant/', '/').split('/')[-2] - except IndexError: - # FIXME: Investigate when this fails ! - return path - - def names(self): - ''' Return all favorite names ''' - return [self.name(p.get('value').get('programUrl')) for p in self._favorites.values() if p.get('value').get('isFavorite')] + def uuid(self, program): + ''' Convert a program url component (e.g. de-campus-cup) to a favorite uuid (e.g. vrtnuazdecampuscup), used for lookups in favorites dict ''' + return 'vrtnuaz' + program.replace('-', '') def titles(self): ''' Return all favorite titles ''' return [p.get('value').get('title') for p in self._favorites.values() if p.get('value').get('isFavorite')] + def programs(self): + ''' Return all favorite programs ''' + return [statichelper.short_program_url_to_program(p.get('value').get('programUrl')) for p in self._favorites.values() if p.get('value').get('isFavorite')] + def invalidate_caches(self): ''' Invalidate caches that rely on favorites ''' # NOTE/ Do not invalidate favorites cache as we manage it ourselves diff --git a/resources/lib/router.py b/resources/lib/router.py index bfbd80767..0eee59724 100644 --- a/resources/lib/router.py +++ b/resources/lib/router.py @@ -49,10 +49,10 @@ def router(argv): # Actions requiring _favorites as well if action == actions.FOLLOW: - _favorites.follow(program=params.get('program'), path=params.get('path')) + _favorites.follow(title=params.get('title'), program=params.get('program')) return if action == actions.UNFOLLOW: - _favorites.unfollow(program=params.get('program'), path=params.get('path')) + _favorites.unfollow(title=params.get('title'), program=params.get('program')) return if action == actions.REFRESH_FAVORITES: _favorites.get_favorites(ttl=0) @@ -109,11 +109,11 @@ def router(argv): return if action == actions.LISTING_EPISODES: _favorites.get_favorites(ttl=60 * 60) - _vrtplayer.show_episodes(path=params.get('video_url')) + _vrtplayer.show_episodes(program=params.get('program'), season=params.get('season')) return if action == actions.LISTING_ALL_EPISODES: _favorites.get_favorites(ttl=60 * 60) - _vrtplayer.show_all_episodes(path=params.get('video_url')) + _vrtplayer.show_all_episodes(program=params.get('program')) return if action == actions.SEARCH: _favorites.get_favorites(ttl=60 * 60) diff --git a/resources/lib/statichelper.py b/resources/lib/statichelper.py index a1912a22a..6fcfdb55b 100644 --- a/resources/lib/statichelper.py +++ b/resources/lib/statichelper.py @@ -34,11 +34,44 @@ def convert_html_to_kodilabel(text): return unescape(text).strip() -def unique_path(path): - ''' Create a unique path to be used in VRT favorites ''' - if path.startswith('//www.vrt.be/vrtnu'): - return path.replace('//www.vrt.be/vrtnu/', '/vrtnu/').replace('.relevant/', '/') - return path +def program_to_short_program_url(program): + ''' Convert a program url component (e.g. de-campus-cup) to a short programUrl (e.g. /vrtnu/a-z/de-campus-cup/) ''' + short_program_url = None + if program: + short_program_url = '/vrtnu/a-z/' + program + '/' + return short_program_url + + +def program_to_long_program_url(program): + ''' Convert a program url component (e.g. de-campus-cup) to a long programUrl (e.g. //www.vrt.be/vrtnu/a-z/de-campus-cup/) ''' + long_program_url = None + if program: + long_program_url = '//www.vrt.be/vrtnu/a-z/' + program + '/' + return long_program_url + + +def target_url_to_program(target_url): + ''' Convert a targetUrl (e.g. //www.vrt.be/vrtnu/a-z/de-campus-cup.relevant/) to a program url component (e.g. de-campus-cup) ''' + program = None + if target_url.startswith('//www.vrt.be') and target_url.endswith('.relevant/'): + program = target_url.replace('//www.vrt.be/vrtnu/a-z/', '').replace('.relevant/', '') + return program + + +def short_program_url_to_program(short_program_url): + ''' Convert a short programUrl (e.g. /vrtnu/a-z/de-campus-cup/) to a program url component (e.g. de-campus-cup) ''' + program = None + if short_program_url.startswith('/vrtnu/a-z/'): + program = short_program_url.replace('/vrtnu/a-z/', '').rstrip('/') + return program + + +def long_program_url_to_program(long_program_url): + ''' Convert a long programUrl (e.g. //www.vrt.be/vrtnu/a-z/de-campus-cup/) to a program url component (e.g. de-campus-cup) ''' + program = None + if long_program_url.startswith('//www.vrt.be/vrtnu/a-z/'): + program = long_program_url.replace('//www.vrt.be/vrtnu/a-z/', '').rstrip('/') + return program def shorten_link(url): diff --git a/resources/lib/vrtapihelper.py b/resources/lib/vrtapihelper.py index 86ba41831..c0f7f822a 100644 --- a/resources/lib/vrtapihelper.py +++ b/resources/lib/vrtapihelper.py @@ -65,9 +65,10 @@ def _map_to_tvshow_items(self, tvshows, use_favorites=False): ''' Construct a list of TV show TitleItems based on Suggests API query and filtered by favorites ''' tvshow_items = [] if statichelper.boolean(use_favorites): - favorite_names = self._favorites.names() + programs = self._favorites.programs() for tvshow in tvshows: - if statichelper.boolean(use_favorites) and tvshow.get('programName') not in favorite_names: + program = statichelper.target_url_to_program(tvshow.get('targetUrl')) + if statichelper.boolean(use_favorites) and program not in programs: continue metadata = metadatacreator.MetadataCreator() metadata.tvshowtitle = tvshow.get('title', '???') @@ -82,22 +83,18 @@ def _map_to_tvshow_items(self, tvshows, use_favorites=False): else: thumbnail = 'DefaultAddonVideo.png' if self._favorites.is_activated(): - program_path = statichelper.unique_path(tvshow.get('targetUrl')) - program = tvshow.get('title').encode('utf-8') - if self._favorites.is_favorite(program_path): - params = dict(action='unfollow', program=program, path=program_path) + title = tvshow.get('title').encode('utf-8') + if self._favorites.is_favorite(program): + params = dict(action='unfollow', title=title, program=program) context_menu = [(self._kodi.localize(30412), 'RunPlugin(plugin://plugin.video.vrt.nu?%s)' % urlencode(params))] else: - params = dict(action='follow', program=program, path=program_path) + params = dict(action='follow', title=title, program=program) context_menu = [(self._kodi.localize(30411), 'RunPlugin(plugin://plugin.video.vrt.nu?%s)' % urlencode(params))] else: context_menu = [] - # Cut vrtbase url off since it will be added again when searching for episodes - # (with a-z we dont have the full url) - video_url = statichelper.add_https_method(tvshow.get('targetUrl')).replace(self._VRT_BASE, '') tvshow_items.append(TitleItem( title=label, - url_dict=dict(action=actions.LISTING_EPISODES, video_url=video_url), + url_dict=dict(action=actions.LISTING_EPISODES, program=program), is_playable=False, art_dict=dict(thumb=thumbnail, icon='DefaultAddonVideo.png', fanart=thumbnail), video_dict=metadata.get_video_dict(), @@ -105,12 +102,12 @@ def _map_to_tvshow_items(self, tvshows, use_favorites=False): )) return tvshow_items - def get_latest_episode(self, tvshow): + def get_latest_episode(self, program): ''' Get the latest episode of a program ''' import json video = None params = { - 'facets[programName]': tvshow, + 'facets[programUrl]': statichelper.program_to_long_program_url(program), 'i': 'video', 'size': '1', } @@ -122,10 +119,9 @@ def get_latest_episode(self, tvshow): video = dict(video_id=episode.get('videoId'), publication_id=episode.get('publicationId')) return video - def get_episode_items(self, path=None, page=None, show_seasons=False, use_favorites=False, variety=None): + def get_episode_items(self, program=None, season=None, page=None, show_seasons=False, use_favorites=False, variety=None): ''' Construct a list of TV show episodes TitleItems based on API query and filtered by favorites ''' titletype = None - season_key = None all_items = True episode_items = [] sort = 'episode' @@ -150,7 +146,8 @@ def get_episode_items(self, path=None, page=None, show_seasons=False, use_favori params['facets[assetOffTime]'] = datetime.now(dateutil.tz.gettz('Europe/Brussels')).strftime('%Y-%m-%d') if statichelper.boolean(use_favorites): - params['facets[programName]'] = '[%s]' % (','.join(self._favorites.names())) + program_urls = [statichelper.program_to_long_program_url(p) for p in self._favorites.programs()] + params['facets[programUrl]'] = '[%s]' % (','.join(program_urls)) cache_file = 'my-%s-%s.json' % (variety, page) else: params['facets[programBrands]'] = '[%s]' % (','.join(self._channel_filter)) @@ -165,28 +162,23 @@ def get_episode_items(self, path=None, page=None, show_seasons=False, use_favori api_json = json.load(urlopen(api_url)) self._kodi.update_cache(cache_file, api_json) return self._map_to_episode_items(api_json.get('results', []), titletype=variety, use_favorites=use_favorites) + if program: + params = { + 'facets[programUrl]': statichelper.program_to_long_program_url(program), + 'i': 'video', + 'size': '150', + } + if season: + params.update({'facets[seasonTitle]': season}) - if path: - if '.relevant/' in path: - params = { - 'facets[programUrl]': '//www.vrt.be' + path.replace('.relevant/', '/'), - 'i': 'video', - 'size': '150', - } - api_url = self._VRTNU_SEARCH_URL + '?' + urlencode(params) - else: - api_url = path - - path = unquote(path) - if 'facets[seasonTitle]' in path: - season_key = path.split('facets[seasonTitle]=')[1] + api_url = self._VRTNU_SEARCH_URL + '?' + urlencode(params) results, episodes = self._get_season_episode_data(api_url, show_seasons=show_seasons, all_items=all_items) if results.get('episodes'): - return self._map_to_episode_items(results.get('episodes', []), titletype=titletype, season_key=season_key, use_favorites=use_favorites) + return self._map_to_episode_items(results.get('episodes', []), titletype=titletype, season=season, use_favorites=use_favorites) if results.get('seasons'): - return self._map_to_season_items(api_url, results.get('seasons'), episodes) + return self._map_to_season_items(program, results.get('seasons'), episodes) return episode_items, sort, ascending, content @@ -201,7 +193,7 @@ def _get_season_episode_data(self, api_url, show_seasons, all_items=True): import json self._kodi.log_notice('URL get: ' + unquote(api_url), 'Verbose') api_json = json.load(urlopen(api_url)) - seasons = self._get_season_data(api_json) + seasons = self._get_season_data(api_json) if 'facets[seasonTitle]' not in unquote(api_url) else None episodes = api_json.get('results', [{}]) if show_seasons and seasons: return dict(seasons=seasons), episodes @@ -216,7 +208,7 @@ def _get_season_episode_data(self, api_url, show_seasons, all_items=True): episodes += page_json.get('results', [{}]) return dict(episodes=episodes), None - def _map_to_episode_items(self, episodes, titletype=None, season_key=None, use_favorites=False): + def _map_to_episode_items(self, episodes, titletype=None, season=None, use_favorites=False): ''' Construct a list of TV show episodes TitleItems based on Search API query and filtered by favorites ''' from datetime import datetime import dateutil.parser @@ -225,15 +217,16 @@ def _map_to_episode_items(self, episodes, titletype=None, season_key=None, use_f sort = 'episode' ascending = True if statichelper.boolean(use_favorites): - favorite_names = self._favorites.names() + programs = self._favorites.programs() episode_items = [] for episode in episodes: # VRT API workaround: seasonTitle facet behaves as a partial match regex, # so we have to filter out the episodes from seasons that don't exactly match. - if season_key and episode.get('seasonTitle') != season_key: + if season and episode.get('seasonTitle') != season: continue - if statichelper.boolean(use_favorites) and episode.get('programName') not in favorite_names: + program = statichelper.long_program_url_to_program(episode.get('programUrl')) + if statichelper.boolean(use_favorites) and program not in programs: continue # Support search highlights @@ -297,13 +290,12 @@ def _map_to_episode_items(self, episodes, titletype=None, season_key=None, use_f metadata.plot = '%s\n\n[COLOR yellow]%s[/COLOR]' % (metadata.plot, metadata.permalink) if self._favorites.is_activated(): - program_path = statichelper.unique_path(episode.get('programUrl')) - program = episode.get('program').encode('utf-8') - if self._favorites.is_favorite(program_path): - params = dict(action='unfollow', program=program, path=program_path) + program_title = episode.get('program').encode('utf-8') + if self._favorites.is_favorite(program): + params = dict(action='unfollow', title=program_title, program=program) context_menu = [(self._kodi.localize(30412), 'RunPlugin(plugin://plugin.video.vrt.nu?%s)' % urlencode(params))] else: - params = dict(action='follow', program=program, path=program_path) + params = dict(action='follow', title=program_title, program=program) context_menu = [(self._kodi.localize(30411), 'RunPlugin(plugin://plugin.video.vrt.nu?%s)' % urlencode(params))] else: context_menu = [] @@ -328,7 +320,7 @@ def _map_to_episode_items(self, episodes, titletype=None, season_key=None, use_f return episode_items, sort, ascending, 'episodes' - def _map_to_season_items(self, api_url, seasons, episodes): + def _map_to_season_items(self, program, seasons, episodes): ''' Construct a list of TV show season TitleItems based on Search API query and filtered by favorites ''' import random @@ -366,7 +358,7 @@ def _map_to_season_items(self, api_url, seasons, episodes): if self._kodi.get_global_setting('videolibrary.showallitems') is True: season_items.append(TitleItem( title=self._kodi.localize(30096), - url_dict=dict(action=actions.LISTING_ALL_EPISODES, video_url=api_url), + url_dict=dict(action=actions.LISTING_ALL_EPISODES, program=program), is_playable=False, art_dict=dict(thumb=fanart, icon='DefaultSets.png', fanart=fanart), video_dict=metadata.get_video_dict(), @@ -389,11 +381,9 @@ def _map_to_season_items(self, api_url, seasons, episodes): fanart = 'DefaultSets.png' thumbnail = 'DefaultSets.png' label = '%s %s' % (self._kodi.localize(30094), season_key) - params = {'facets[seasonTitle]': season_key} - path = api_url + '&' + urlencode(params) season_items.append(TitleItem( title=label, - url_dict=dict(action=actions.LISTING_EPISODES, video_url=path), + url_dict=dict(action=actions.LISTING_EPISODES, program=program, season=season_key), is_playable=False, art_dict=dict(thumb=thumbnail, icon='DefaultSets.png', fanart=fanart), video_dict=metadata.get_video_dict(), diff --git a/resources/lib/vrtplayer.py b/resources/lib/vrtplayer.py index 325d64694..b3f528631 100644 --- a/resources/lib/vrtplayer.py +++ b/resources/lib/vrtplayer.py @@ -103,7 +103,7 @@ def show_favorites_menu_items(self): self._kodi.show_listing(favorites_items) # Show dialog when no favorites were found - if not self._favorites.names(): + 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): @@ -131,14 +131,14 @@ def show_livestream_items(self): channel_items = self._apihelper.get_channel_items(action=actions.PLAY, channels=['een', 'canvas', 'sporza', 'ketnet-jr', 'ketnet', 'stubru', 'mnm']) self._kodi.show_listing(channel_items, cache=False) - def show_episodes(self, path): + def show_episodes(self, program, season=None): ''' The VRT NU add-on episodes listing menu ''' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path, show_seasons=True) + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program, season=season, show_seasons=True) self._kodi.show_listing(episode_items, sort=sort, ascending=ascending, content=content) - def show_all_episodes(self, path): + def show_all_episodes(self, program): ''' The VRT NU add-on '* All seasons' listing menu ''' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path) + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program) self._kodi.show_listing(episode_items, sort=sort, ascending=ascending, content=content) def show_recent(self, page=0, use_favorites=False): @@ -207,7 +207,7 @@ def search(self, search_string=None, page=None): def play_latest_episode(self, params): ''' A hidden feature in the VRT NU add-on to play the latest episode of a program ''' - video = self._apihelper.get_latest_episode(params.get('tvshow')) + video = self._apihelper.get_latest_episode(params.get('program')) if not video: self._kodi.log_error('Play latest episode failed, params %s' % params) self._kodi.show_ok_dialog(message=self._kodi.localize(30954)) diff --git a/test/apihelpertests.py b/test/apihelpertests.py index b7e514a26..5dcfecbbc 100644 --- a/test/apihelpertests.py +++ b/test/apihelpertests.py @@ -24,28 +24,28 @@ class ApiHelperTests(unittest.TestCase): _apihelper = vrtapihelper.VRTApiHelper(_kodi, _favorites) def test_get_api_data_single_season(self): - title_items, sort, ascending, content = self._apihelper.get_episode_items(path='/vrtnu/a-z/het-journaal.relevant/', show_seasons=True) + title_items, sort, ascending, content = self._apihelper.get_episode_items(program='het-journaal', show_seasons=True) self.assertTrue(121 < len(title_items) < 140, 'We got %s items instead.' % len(title_items)) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) self.assertEqual(content, 'episodes') def test_get_api_data_multiple_seasons(self): - title_items, sort, ascending, content = self._apihelper.get_episode_items(path='/vrtnu/a-z/thuis.relevant/', show_seasons=True) + title_items, sort, ascending, content = self._apihelper.get_episode_items(program='thuis', show_seasons=True) self.assertTrue(len(title_items) < 5) self.assertEqual(sort, 'label') self.assertFalse(ascending) self.assertEqual(content, 'seasons') def test_get_api_data_specific_season(self): - title_items, sort, ascending, content = self._apihelper.get_episode_items(path='/vrtnu/a-z/pano.relevant/', show_seasons=True) + title_items, sort, ascending, content = self._apihelper.get_episode_items(program='pano', show_seasons=True) self.assertEqual(len(title_items), 4) self.assertEqual(sort, 'label') self.assertFalse(ascending) self.assertEqual(content, 'seasons') def test_get_api_data_specific_season_without_broadcastdate(self): - title_items, sort, ascending, content = self._apihelper.get_episode_items(path='/vrtnu/a-z/postbus-x.relevant/', show_seasons=True) + title_items, sort, ascending, content = self._apihelper.get_episode_items(program='postbus-x', show_seasons=True) self.assertEqual(len(title_items), 3) self.assertEqual(sort, 'label') self.assertTrue(ascending) @@ -85,8 +85,8 @@ def test_get_offline_episodes(self): def test_get_tvshows(self): ''' Test items, sort and order ''' - path = 'nieuws-en-actua' - tvshow_items = self._apihelper.get_tvshow_items(path) + category = 'nieuws-en-actua' + tvshow_items = self._apihelper.get_tvshow_items(category=category) self.assertTrue(tvshow_items) def test_tvshows(self): diff --git a/test/favoritestests.py b/test/favoritestests.py index af36ca59a..788f0b09e 100644 --- a/test/favoritestests.py +++ b/test/favoritestests.py @@ -25,21 +25,21 @@ class TestFavorites(unittest.TestCase): _favorites = favorites.Favorites(_kodi, _tokenresolver) def test_follow_unfollow(self): - program = 'Winteruur' - program_path = '/vrtnu/a-z/winteruur/' - self._favorites.follow(program, program_path) - self.assertTrue(self._favorites.is_favorite(program_path)) + program_title = 'Winteruur' + program = 'winteruur' + self._favorites.follow(title=program_title, program=program) + self.assertTrue(self._favorites.is_favorite(program)) - self._favorites.unfollow(program, program_path) - self.assertFalse(self._favorites.is_favorite(program_path)) + self._favorites.unfollow(program, program) + self.assertFalse(self._favorites.is_favorite(program)) - self._favorites.follow(program, program_path) - self.assertTrue(self._favorites.is_favorite(program_path)) + self._favorites.follow(program, program) + self.assertTrue(self._favorites.is_favorite(program)) - def test_names(self): - names = self._favorites.names() - self.assertTrue(names) - print(names) + def test_programs(self): + programs = self._favorites.programs() + self.assertTrue(programs) + print(programs) def test_titles(self): titles = self._favorites.titles() diff --git a/test/routertests.py b/test/routertests.py index 3d2a403b2..c223debca 100644 --- a/test/routertests.py +++ b/test/routertests.py @@ -35,11 +35,11 @@ def test_az_menu(self): # LISTING_EPISODES = 'listingepisodes' def test_episodes_menu(self): - router.router(['plugin://plugin.video.vrt.nu', '0', '?action=listingepisodes&video_url=/vrtnu/a-z/het-journaal.relevant/']) + router.router(['plugin://plugin.video.vrt.nu', '0', '?action=listingepisodes&program=het-journaal']) # LISTING_ALL_EPISODES = 'listingallepisodes' def test_all_episodes_menu(self): - router.router(['plugin://plugin.video.vrt.nu', '0', '?action=listingallepisodes&video_url=/vrtnu/a-z/thuis.relevant/']) + router.router(['plugin://plugin.video.vrt.nu', '0', '?action=listingallepisodes&program=thuis']) # LISTING_CATEGORIES = 'listingcategories' def test_categories_menu(self): @@ -80,11 +80,11 @@ def test_search_menu(self): # FOLLOW = 'follow' def test_follow_action(self): - router.router(['plugin://plugin.video.vrt.nu', '0', '?action=follow&program=Thuis&path=thuis']) + router.router(['plugin://plugin.video.vrt.nu', '0', '?action=follow&title=Thuis&program=thuis']) # UNFOLLOW = 'unfollow' def test_unfollow_action(self): - router.router(['plugin://plugin.video.vrt.nu', '0', '?action=unfollow&program=Thuis&path=thuis']) + router.router(['plugin://plugin.video.vrt.nu', '0', '?action=unfollow&title=Thuis&program=thuis']) # CLEAR_COOKIES = 'deletetokens' def test_clear_cookies_action(self): diff --git a/test/vrtplayertests.py b/test/vrtplayertests.py index 9a580d1d8..9bd7e29c6 100644 --- a/test/vrtplayertests.py +++ b/test/vrtplayertests.py @@ -27,47 +27,47 @@ class TestVRTPlayer(unittest.TestCase): _vrtplayer = vrtplayer.VRTPlayer(_kodi, _favorites, _apihelper) def test_show_videos_single_episode_shows_videos(self): - path = '/vrtnu/a-z/marathonradio.relevant/' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path) - self.assertTrue(episode_items, msg=path) + program = 'marathonradio' + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program) + self.assertTrue(episode_items, msg=program) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) self.assertEqual(content, 'episodes') - self._vrtplayer.show_episodes(path) + self._vrtplayer.show_episodes(program) # self.assertTrue(self._kodi.show_listing.called) def test_show_videos_single_season_shows_videos(self): - path = '/vrtnu/a-z/het-weer.relevant/' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path) - self.assertTrue(episode_items, msg=path) + program = 'het-weer' + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program) + self.assertTrue(episode_items, msg=program) self.assertEqual(sort, 'dateadded') self.assertFalse(ascending) self.assertEqual(content, 'episodes') - self._vrtplayer.show_episodes(path) + self._vrtplayer.show_episodes(program) # self.assertTrue(self._kodi.show_listing.called) def test_show_videos_multiple_seasons_shows_videos(self): - path = '/vrtnu/a-z/pano.relevant/' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path, show_seasons=True) + program = 'pano' + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program, show_seasons=True) self.assertTrue(episode_items) self.assertEqual(sort, 'label') self.assertFalse(ascending) self.assertEqual(content, 'seasons') - self._vrtplayer.show_episodes(path) + self._vrtplayer.show_episodes(program) # self.assertTrue(self._kodi.show_listing.called) def test_show_videos_specific_seasons_shows_videos(self): - path = '/vrtnu/a-z/thuis.relevant/' - episode_items, sort, ascending, content = self._apihelper.get_episode_items(path=path, show_seasons=True) - self.assertTrue(episode_items, msg=path) + program = 'thuis' + episode_items, sort, ascending, content = self._apihelper.get_episode_items(program=program, show_seasons=True) + self.assertTrue(episode_items, msg=program) self.assertEqual(sort, 'label') self.assertFalse(ascending) self.assertEqual(content, 'seasons') - self._vrtplayer.show_episodes(path) + self._vrtplayer.show_episodes(program) # self.assertTrue(self._kodi.show_listing.called) def test_categories_scraping(self): @@ -86,8 +86,8 @@ def test_random_tvshow_episodes(self): self.assertTrue(tvshow_items, msg=category['id']) tvshow = random.choice(tvshow_items) - episode_items, sort, ascending, content = self._apihelper.get_episode_items(tvshow.url_dict['video_url']) - self.assertTrue(episode_items, msg=tvshow.url_dict['video_url']) + episode_items, sort, ascending, content = self._apihelper.get_episode_items(tvshow.url_dict['program']) + self.assertTrue(episode_items, msg=tvshow.url_dict['program']) self.assertTrue(content in ['episodes', 'seasons'], "Content for '%s' is '%s'" % (tvshow.title, content)) def test_categories(self):