diff --git a/resources/lib/addon.py b/resources/lib/addon.py index 9e3e1b1..b51cfb2 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -98,18 +98,18 @@ def show_mylist(): Catalog().show_mylist() -@routing.route('/catalog/mylist/add//') -def mylist_add(video_type, content_id): +@routing.route('/catalog/mylist/add/') +def mylist_add(content_id): """ Add an item to "My List" """ from resources.lib.modules.catalog import Catalog - Catalog().mylist_add(video_type, content_id) + Catalog().mylist_add(content_id) -@routing.route('/catalog/mylist/del//') -def mylist_del(video_type, content_id): +@routing.route('/catalog/mylist/del/') +def mylist_del(content_id): """ Remove an item from "My List" """ from resources.lib.modules.catalog import Catalog - Catalog().mylist_del(video_type, content_id) + Catalog().mylist_del(content_id) @routing.route('/catalog/continuewatching') diff --git a/resources/lib/modules/catalog.py b/resources/lib/modules/catalog.py index 2efd8e6..8e3eeac 100644 --- a/resources/lib/modules/catalog.py +++ b/resources/lib/modules/catalog.py @@ -183,22 +183,20 @@ def show_mylist(self): # Sort categories by default like in Streamz. kodiutils.show_listing(listing, 30017, content='files', sort=['unsorted', 'label', 'year', 'duration']) - def mylist_add(self, video_type, content_id): + def mylist_add(self, content_id): """ Add an item to "My List". - :type video_type: str :type content_id: str """ - self._api.add_mylist(video_type, content_id) + self._api.add_mylist(content_id) kodiutils.end_of_directory() - def mylist_del(self, video_type, content_id): + def mylist_del(self, content_id): """ Remove an item from "My List". - :type video_type: str :type content_id: str """ - self._api.del_mylist(video_type, content_id) + self._api.del_mylist(content_id) kodiutils.end_of_directory() def show_continuewatching(self): diff --git a/resources/lib/modules/menu.py b/resources/lib/modules/menu.py index a04cba2..c526fbd 100644 --- a/resources/lib/modules/menu.py +++ b/resources/lib/modules/menu.py @@ -9,7 +9,6 @@ from resources.lib.kodiutils import TitleItem from resources.lib.streamz import (PRODUCT_STREAMZ, PRODUCT_STREAMZ_KIDS, STOREFRONT_KIDS, STOREFRONT_MAIN, STOREFRONT_MAIN_KIDS, STOREFRONT_MOVIES, STOREFRONT_SERIES, Episode, Movie, Program) -from resources.lib.streamz.api import CONTENT_TYPE_MOVIE, CONTENT_TYPE_PROGRAM from resources.lib.streamz.auth import Auth _LOGGER = logging.getLogger(__name__) @@ -200,13 +199,13 @@ def generate_titleitem(cls, item, progress=False): context_menu = [( kodiutils.localize(30101), # Remove from My List 'Container.Update(%s)' % - kodiutils.url_for('mylist_del', video_type=CONTENT_TYPE_MOVIE, content_id=item.movie_id) + kodiutils.url_for('mylist_del', content_id=item.movie_id) )] else: context_menu = [( kodiutils.localize(30100), # Add to My List 'Container.Update(%s)' % - kodiutils.url_for('mylist_add', video_type=CONTENT_TYPE_MOVIE, content_id=item.movie_id) + kodiutils.url_for('mylist_add', content_id=item.movie_id) )] info_dict.update({ @@ -249,13 +248,13 @@ def generate_titleitem(cls, item, progress=False): context_menu = [( kodiutils.localize(30101), # Remove from My List 'Container.Update(%s)' % - kodiutils.url_for('mylist_del', video_type=CONTENT_TYPE_PROGRAM, content_id=item.program_id) + kodiutils.url_for('mylist_del', content_id=item.program_id) )] else: context_menu = [( kodiutils.localize(30100), # Add to My List 'Container.Update(%s)' % - kodiutils.url_for('mylist_add', video_type=CONTENT_TYPE_PROGRAM, content_id=item.program_id) + kodiutils.url_for('mylist_add', content_id=item.program_id) )] info_dict.update({ diff --git a/resources/lib/streamz/api.py b/resources/lib/streamz/api.py index c160f18..7ad6502 100644 --- a/resources/lib/streamz/api.py +++ b/resources/lib/streamz/api.py @@ -139,16 +139,16 @@ def get_mylist(self, content_filter=None, cache=CACHE_ONLY): return items - def add_mylist(self, video_type, content_id): + def add_mylist(self, content_id): """ Add an item to My List. """ - util.http_put(API_ENDPOINT + '/%s/userData/myList/%s/%s' % (self._mode(), video_type, content_id), + util.http_put(API_ENDPOINT + '/%s/userData/myList/%s' % (self._mode(), content_id), token=self._tokens.access_token, profile=self._tokens.profile) kodiutils.set_cache(['swimlane', 'my-list'], None) - def del_mylist(self, video_type, content_id): + def del_mylist(self, content_id): """ Delete an item from My List. """ - util.http_delete(API_ENDPOINT + '/%s/userData/myList/%s/%s' % (self._mode(), video_type, content_id), + util.http_delete(API_ENDPOINT + '/%s/userData/myList/%s' % (self._mode(), content_id), token=self._tokens.access_token, profile=self._tokens.profile) kodiutils.set_cache(['swimlane', 'my-list'], None) @@ -170,7 +170,7 @@ def get_movie(self, movie_id, cache=CACHE_AUTO): if not movie: # Fetch from API - response = util.http_get(API_ENDPOINT + '/%s/movies/%s' % (self._mode(), movie_id), + response = util.http_get(API_ENDPOINT + '/%s/detail/%s' % (self._mode(), movie_id), token=self._tokens.access_token, profile=self._tokens.profile) movie = json.loads(response.text) @@ -211,7 +211,7 @@ def get_program(self, program_id, cache=CACHE_AUTO): if not program: # Fetch from API - response = util.http_get(API_ENDPOINT + '/%s/programs/%s' % (self._mode(), program_id), + response = util.http_get(API_ENDPOINT + '/%s/detail/%s' % (self._mode(), program_id), token=self._tokens.access_token, profile=self._tokens.profile) program = json.loads(response.text) @@ -224,10 +224,10 @@ def get_program(self, program_id, cache=CACHE_AUTO): episodes = {} # Fetch season - season_response = util.http_get(API_ENDPOINT + '/%s/programs/%s/seasons/%s' % (self._mode(), program_id, item_season), + season_response = util.http_get(API_ENDPOINT + '/%s/detail/%s?selectedSeasonIndex=%s' % (self._mode(), program_id, item_season), token=self._tokens.access_token, profile=self._tokens.profile) - season = json.loads(season_response.text) + season = json.loads(season_response.text).get('selectedSeason') for item_episode in season.get('episodes', []): episodes[item_episode.get('index')] = Episode( @@ -315,7 +315,7 @@ def get_episode(self, episode_id): :type episode_id: str :rtype Episode """ - response = util.http_get(API_ENDPOINT + '/%s/play/episodes/%s' % (self._mode(), episode_id), + response = util.http_get(API_ENDPOINT + '/%s/play/%s' % (self._mode(), episode_id), token=self._tokens.access_token, profile=self._tokens.profile) episode = json.loads(response.text) diff --git a/tests/test_api.py b/tests/test_api.py index 2c897f6..ba13ff4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -9,11 +9,15 @@ import unittest from resources.lib import kodiutils -from resources.lib.streamz import STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_PAGE_CONTINUE_WATCHING, STOREFRONT_SERIES +from resources.lib.streamz import STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_PAGE_CONTINUE_WATCHING, STOREFRONT_SERIES, Episode, Movie, Program from resources.lib.streamz.api import Api from resources.lib.streamz.auth import Auth from resources.lib.streamz.exceptions import UnavailableException +EXAMPLE_MOVIE = 'f384c9f1-e2dc-4f82-9954-a3f91589385a' # Niet schieten +EXAMPLE_PROGRAM = '6382e070-c284-4538-b60a-44f337ba6157' # FC De Kampioenen +EXAMPLE_EPISODE = '7c1c2b5c-de72-45d6-ab88-8dd63edddf43' # FC De Kampioenen S01E01 + @unittest.skipUnless(os.environ.get('ADDON_TOKEN') and os.environ.get('ADDON_PROFILE'), 'Skipping since we have no credentials.') class TestApi(unittest.TestCase): @@ -50,6 +54,18 @@ def test_search(self): results = self.api.do_search('huis') self.assertIsInstance(results, list) + def test_get_program(self): + results = self.api.get_program(EXAMPLE_PROGRAM) + self.assertIsInstance(results, Program) + + def test_get_movie(self): + results = self.api.get_movie(EXAMPLE_MOVIE) + self.assertIsInstance(results, Movie) + + def test_get_episode(self): + results = self.api.get_episode(EXAMPLE_EPISODE) + self.assertIsInstance(results, Episode) + def test_errors(self): with self.assertRaises(UnavailableException): self.api.get_movie('0') diff --git a/tests/test_routing.py b/tests/test_routing.py index a108b44..64dbff6 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -18,7 +18,7 @@ _LOGGER = logging.getLogger(__name__) -EXAMPLE_MOVIE = '9f33cbca-0321-4a2f-9ac4-374ff69e2c4e' # Gooische Vrouwen 2 +EXAMPLE_MOVIE = 'f384c9f1-e2dc-4f82-9954-a3f91589385a' # Niet schieten EXAMPLE_PROGRAM = '6382e070-c284-4538-b60a-44f337ba6157' # FC De Kampioenen EXAMPLE_EPISODE = '7c1c2b5c-de72-45d6-ab88-8dd63edddf43' # FC De Kampioenen S01E01