Skip to content

Commit

Permalink
Update to version 13 API (part 2) (#54)
Browse files Browse the repository at this point in the history
* More API 13 fixes

* Codefix

* codefix
  • Loading branch information
michaelarnauts authored Jan 13, 2023
1 parent 4180c95 commit 077eb21
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
12 changes: 6 additions & 6 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ def show_mylist():
Catalog().show_mylist()


@routing.route('/catalog/mylist/add/<video_type>/<content_id>')
def mylist_add(video_type, content_id):
@routing.route('/catalog/mylist/add/<content_id>')
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/<video_type>/<content_id>')
def mylist_del(video_type, content_id):
@routing.route('/catalog/mylist/del/<content_id>')
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')
Expand Down
10 changes: 4 additions & 6 deletions resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
18 changes: 9 additions & 9 deletions resources/lib/streamz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 077eb21

Please sign in to comment.