Skip to content

Commit

Permalink
Improve error handling and code cleanup (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts authored Oct 6, 2020
1 parent 9495b2b commit 6b0b47e
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 277 deletions.
14 changes: 5 additions & 9 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,25 @@ msgid "Unknown error while logging in: {code}"
msgstr ""

msgctxt "#30703"
msgid "Your account has no profiles defined. Please login on www.streamz.be/streamz and create a profile."
msgid "Your account has no profiles defined. Please login on www.streamz.be and create a profile."
msgstr ""

msgctxt "#30708"
msgid "Please restart Kodi."
msgstr ""

msgctxt "#30709"
msgid "Geo-blocked video"
msgstr ""

msgctxt "#30710"
msgid "This video is geo-blocked and can't be played from your location."
msgstr ""

msgctxt "#30711"
msgid "Unavailable video"
msgstr ""

msgctxt "#30712"
msgid "The video is unavailable and can't be played right now."
msgstr ""

msgctxt "#30713"
msgid "You have reached the maximum amount of concurrent streams. Please stop streaming on another device to start watching here."
msgstr ""

msgctxt "#30714"
msgid "Local metadata is cleared."
msgstr ""
Expand Down
16 changes: 6 additions & 10 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,25 @@ msgid "Unknown error while logging in: {code}"
msgstr "Onbekende fout bij het inloggen: {code}"

msgctxt "#30703"
msgid "Your account has no profiles defined. Please login on www.streamz.be/streamz and create a profile."
msgstr "Uw account heeft geen profielen. Gelieve in te loggen op www.streamz.be/streamz en een profiel aan te maken."
msgid "Your account has no profiles defined. Please login on www.streamz.be and create a profile."
msgstr "Uw account heeft geen profielen. Gelieve in te loggen op www.streamz.be en een profiel aan te maken."

msgctxt "#30708"
msgid "Please restart Kodi."
msgstr "Gelieve Kodi te herstarten."

msgctxt "#30709"
msgid "Geo-blocked video"
msgstr "Video is geografisch geblokkeerd"

msgctxt "#30710"
msgid "This video is geo-blocked and can't be played from your location."
msgstr "Deze video is geografisch geblokkeerd en kan niet worden afgespeeld vanaf uw locatie."

msgctxt "#30711"
msgid "Unavailable video"
msgstr "Onbeschikbare video"

msgctxt "#30712"
msgid "The video is unavailable and can't be played right now."
msgstr "Deze video is niet beschikbaar en kan nu niet worden afgespeeld."

msgctxt "#30713"
msgid "You have reached the maximum amount of concurrent streams. Please stop streaming on another device to start watching here."
msgstr "U heeft het maximum aantal gelijktijdige streams bereikt. Gelieve te stoppen met streamen op een ander apparaat om hier te beginnen kijken."

msgctxt "#30714"
msgid "Local metadata is cleared."
msgstr "De lokale metadata is verwijderd."
Expand Down
6 changes: 5 additions & 1 deletion resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging

import routing
from requests import HTTPError

from resources.lib import kodilogging, kodiutils
from resources.lib.streamz.exceptions import NoLoginException, InvalidLoginException, LoginErrorException, NoTelenetSubscriptionException, \
Expand Down Expand Up @@ -51,7 +52,10 @@ def index():

except LoginErrorException as exc:
kodiutils.ok_dialog(message=kodiutils.localize(30702, code=exc.code)) # Unknown error while logging in: {code}
kodiutils.open_settings()
kodiutils.end_of_directory()

except HTTPError as exc:
kodiutils.ok_dialog(message=kodiutils.localize(30702, code='HTTP %d' % exc.response.status_code)) # Unknown error while logging in: {code}
kodiutils.end_of_directory()


Expand Down
6 changes: 4 additions & 2 deletions resources/lib/modules/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self):
self._api = Api(self._auth)

def select_profile(self, key=None):
""" Show your profiles
""" Show your profiles.
:type key: str
"""
profiles = self._auth.get_profiles()
Expand Down Expand Up @@ -71,7 +72,8 @@ def select_profile(self, key=None):

@staticmethod
def _get_profile_name(profile):
""" Get a descriptive string of the profile
""" Get a descriptive string of the profile.
:type profile: resources.lib.streamz.Profile
"""
title = profile.name
Expand Down
27 changes: 17 additions & 10 deletions resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
self._api = Api(self._auth)

def show_catalog(self):
""" Show the catalog """
""" Show the catalog. """
categories = self._api.get_categories()

listing = []
Expand All @@ -45,7 +45,8 @@ def show_catalog(self):
kodiutils.show_listing(listing, 30003, content='files')

def show_catalog_category(self, category=None):
""" Show a category in the catalog
""" Show a category in the catalog.
:type category: str
"""
items = self._api.get_items(category)
Expand All @@ -59,7 +60,8 @@ def show_catalog_category(self, category=None):
kodiutils.show_listing(listing, 30003, content='movies' if category == 'films' else 'tvshows', sort=['label', 'year', 'duration'])

def show_program(self, program):
""" Show a program from the catalog
""" Show a program from the catalog.
:type program: str
"""
try:
Expand Down Expand Up @@ -120,7 +122,8 @@ def show_program(self, program):
kodiutils.show_listing(listing, 30003, content='tvshows', sort=['label'])

def show_program_season(self, program, season):
""" Show the episodes of a program from the catalog
""" Show the episodes of a program from the catalog.
:type program: str
:type season: int
"""
Expand All @@ -144,7 +147,8 @@ def show_program_season(self, program, season):
kodiutils.show_listing(listing, 30003, content='episodes', sort=['episode', 'duration'])

def show_recommendations(self, storefront):
""" Show the recommendations
""" Show the recommendations.
:type storefront: str
"""
recommendations = self._api.get_recommendations(storefront)
Expand All @@ -163,7 +167,8 @@ def show_recommendations(self, storefront):
kodiutils.show_listing(listing, 30015, content='files')

def show_recommendations_category(self, storefront, category):
""" Show the items in a recommendations category
""" Show the items in a recommendations category.
:type storefront: str
:type category: str
"""
Expand All @@ -182,7 +187,7 @@ def show_recommendations_category(self, storefront, category):
kodiutils.show_listing(listing, 30015, content='tvshows')

def show_mylist(self):
""" Show the items in "My List" """
""" Show the items in "My List". """
mylist = self._api.get_swimlane('my-list')

listing = []
Expand All @@ -194,15 +199,17 @@ def show_mylist(self):
kodiutils.show_listing(listing, 30017, content='tvshows')

def mylist_add(self, video_type, content_id):
""" Add an item to "My List"
""" Add an item to "My List".
:type video_type: str
:type content_id: str
"""
self._api.add_mylist(video_type, content_id)
kodiutils.end_of_directory()

def mylist_del(self, video_type, content_id):
""" Remove an item from "My List"
""" Remove an item from "My List".
:type video_type: str
:type content_id: str
"""
Expand All @@ -211,7 +218,7 @@ def mylist_del(self, video_type, content_id):
kodiutils.container_refresh()

def show_continuewatching(self):
""" Show the items in "Continue Watching" """
""" Show the items in "Continue Watching". """
mylist = self._api.get_swimlane('continue-watching')

listing = []
Expand Down
6 changes: 4 additions & 2 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
self._api = Api(self._auth)

def show_mainmenu(self):
""" Show the main menu """
""" Show the main menu. """
listing = []

if self._auth.login().product == 'STREAMZ':
Expand Down Expand Up @@ -147,7 +147,8 @@ def show_mainmenu(self):

@staticmethod
def format_plot(obj):
""" Format the plot for a item
""" Format the plot for a item.
:type obj: object
:rtype str
"""
Expand Down Expand Up @@ -183,6 +184,7 @@ def format_plot(obj):
@classmethod
def generate_titleitem(cls, item, progress=False):
""" Generate a TitleItem based on a Movie, Program or Episode.
:type item: Union[Movie, Program, Episode]
:type progress: bool
:rtype TitleItem
Expand Down
9 changes: 5 additions & 4 deletions resources/lib/modules/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def __init__(self):
self._api = Api(self._auth)

def update(self):
""" Update the metadata with a foreground progress indicator """
""" Update the metadata with a foreground progress indicator. """
# Create progress indicator
progress = kodiutils.progress(message=kodiutils.localize(30715)) # Updating metadata

def update_status(i, total):
""" Update the progress indicator """
""" Update the progress indicator. """
progress.update(int(((i + 1) / total) * 100), kodiutils.localize(30716, index=i + 1, total=total)) # Updating metadata ({index}/{total})
return progress.iscanceled()

Expand All @@ -41,7 +41,8 @@ def update_status(i, total):
progress.close()

def fetch_metadata(self, callback=None):
""" Fetch the metadata for all the items in the catalog
""" Fetch the metadata for all the items in the catalog.
:type callback: callable
"""
# Fetch all items from the catalog
Expand All @@ -64,7 +65,7 @@ def fetch_metadata(self, callback=None):

@staticmethod
def clean():
""" Clear metadata (called from settings) """
""" Clear metadata (called from settings). """
kodiutils.invalidate_cache()
kodiutils.set_setting('metadata_last_updated', '0')
kodiutils.ok_dialog(message=kodiutils.localize(30714)) # Local metadata is cleared
27 changes: 13 additions & 14 deletions resources/lib/modules/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from resources.lib import kodiutils
from resources.lib.streamz.api import Api
from resources.lib.streamz.auth import Auth
from resources.lib.streamz.exceptions import UnavailableException
from resources.lib.streamz.stream import StreamGeoblockedException, StreamUnavailableException, Stream
from resources.lib.streamz.exceptions import UnavailableException, LimitReachedException, StreamGeoblockedException, StreamUnavailableException
from resources.lib.streamz.stream import Stream

_LOGGER = logging.getLogger(__name__)

Expand All @@ -30,6 +30,7 @@ def __init__(self):

def play(self, category, item):
""" Play the requested item.
:type category: string
:type item: string
"""
Expand All @@ -43,12 +44,17 @@ def play(self, category, item):
resolved_stream = self._stream.get_stream(category, item)

except StreamGeoblockedException:
kodiutils.ok_dialog(heading=kodiutils.localize(30709), message=kodiutils.localize(30710)) # This video is geo-blocked...
kodiutils.ok_dialog(message=kodiutils.localize(30710)) # This video is geo-blocked...
kodiutils.end_of_directory()
return

except StreamUnavailableException:
kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize(30712)) # The video is unavailable...
kodiutils.ok_dialog(message=kodiutils.localize(30712)) # The video is unavailable...
kodiutils.end_of_directory()
return

except LimitReachedException:
kodiutils.ok_dialog(message=kodiutils.localize(30713)) # You have reached the maximum amount of concurrent streams...
kodiutils.end_of_directory()
return

Expand Down Expand Up @@ -101,16 +107,6 @@ def play(self, category, item):
if next_episode_details:
upnext_data = self.generate_upnext(episode_details, next_episode_details)

elif category == 'channels':
info_dict.update({'mediatype': 'episode'})

# For live channels, we need to keep on updating the manifest
# This might not be needed, and could be done with the Location-tag updates if inputstream.adaptive supports it
# See https://github.com/peak3d/inputstream.adaptive/pull/298#issuecomment-524206935
prop_dict.update({
'inputstream.adaptive.manifest_update_parameter': 'full',
})

else:
_LOGGER.warning('Unknown category %s', category)

Expand Down Expand Up @@ -138,6 +134,7 @@ def play(self, category, item):
@staticmethod
def _check_inputstream():
""" Check if inputstreamhelper and inputstream.adaptive are fine.
:rtype boolean
"""
try:
Expand All @@ -156,6 +153,7 @@ def _check_inputstream():
@staticmethod
def generate_upnext(current_episode, next_episode):
""" Construct the data for Up Next.
:type current_episode: resources.lib.streamz.api.Episode
:type next_episode: resources.lib.streamz.api.Episode
"""
Expand Down Expand Up @@ -200,6 +198,7 @@ def generate_upnext(current_episode, next_episode):
@staticmethod
def send_upnext(upnext_info):
""" Send a message to Up Next with information about the next Episode.
:type upnext_info: object
"""
from base64 import b64encode
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self,):
self._api = Api(self._auth)

def show_search(self, query=None):
""" Shows the search dialog
""" Shows the search dialog.
:type query: str
"""
if not query:
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/streamz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ class ResolvedStream:

def __init__(self, program=None, program_id=None, title=None, duration=None, url=None, license_url=None, subtitles=None, cookies=None):
"""
:type program: str|None
:type program_id: int|None
:type program: str
:type program_id: str
:type title: str
:type duration: str|None
:type duration: str
:type url: str
:type license_url: str
:type subtitles: list[str]
Expand Down
Loading

0 comments on commit 6b0b47e

Please sign in to comment.