Skip to content

Commit 7beebcc

Browse files
Various fixes (#13)
1 parent 8909aec commit 7beebcc

File tree

16 files changed

+93
-41
lines changed

16 files changed

+93
-41
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ check-addon: clean build
4141
cd ${TMPDIR} && kodi-addon-checker --branch=leia
4242
@rm -rf ${TMPDIR}
4343

44+
codefix:
45+
@isort -l 160 resources/
46+
4447
test: test-unit
4548

4649
test-unit:

resources/language/resource.language.en_gb/strings.po

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ msgctxt "#30020"
6262
msgid "Continue watching where you left off"
6363
msgstr ""
6464

65+
msgctxt "#30021"
66+
msgid "Kids"
67+
msgstr ""
68+
69+
msgctxt "#30022"
70+
msgid "Show the VTM GO recommendations for Kids"
71+
msgstr ""
72+
6573

6674
### SUBMENUS
6775

@@ -138,7 +146,7 @@ msgstr ""
138146
### MESSAGES
139147

140148
msgctxt "#30701"
141-
msgid "You need to configure your credentials before you can access the content of Streamz."
149+
msgid "You need to configure your credentials before you can access the content of Streamz. Do you want to enter them now?"
142150
msgstr ""
143151

144152
msgctxt "#30702"

resources/language/resource.language.nl_nl/strings.po

+10-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ msgctxt "#30020"
6363
msgid "Continue watching where you left off"
6464
msgstr "Kijk verder waar u gebleven was"
6565

66+
msgctxt "#30021"
67+
msgid "Kids"
68+
msgstr "Kids"
69+
70+
msgctxt "#30022"
71+
msgid "Show the VTM GO recommendations for Kids"
72+
msgstr "Bekijk de VTM GO aanbevelingen voor kinderen"
73+
6674

6775
### SUBMENUS
6876

@@ -139,8 +147,8 @@ msgstr "Alle leeftijden"
139147
### MESSAGES
140148

141149
msgctxt "#30701"
142-
msgid "You need to configure your credentials before you can access the content of Streamz."
143-
msgstr "U moet uw inloggegevens configureren voordat u Streamz kan gebruiken."
150+
msgid "You need to configure your credentials before you can access the content of Streamz. Do you want to enter them now?"
151+
msgstr "U moet uw inloggegevens configureren voordat u Streamz kan gebruiken. Wilt u dit nu doen?"
144152

145153
msgctxt "#30702"
146154
msgid "Unknown error while logging in: {code}"

resources/lib/addon.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from requests import HTTPError
1010

1111
from resources.lib import kodilogging, kodiutils
12-
from resources.lib.streamz.exceptions import NoLoginException, InvalidLoginException, LoginErrorException, NoTelenetSubscriptionException, \
13-
NoStreamzSubscriptionException
12+
from resources.lib.streamz.exceptions import InvalidLoginException, LoginErrorException, NoStreamzSubscriptionException, NoTelenetSubscriptionException
1413

1514
kodilogging.config()
1615
routing = routing.Plugin() # pylint: disable=invalid-name
@@ -20,23 +19,26 @@
2019
@routing.route('/')
2120
def index():
2221
""" Show the profile selection, or go to the main menu. """
22+
while True:
23+
if not kodiutils.get_setting('username') or not kodiutils.get_setting('password'):
24+
if not kodiutils.yesno_dialog(message=kodiutils.localize(30701)): # You need to configure your credentials...
25+
# We have no credentials
26+
kodiutils.end_of_directory()
27+
kodiutils.execute_builtin('ActivateWindow(Home)')
28+
return
29+
30+
kodiutils.open_settings()
31+
else:
32+
break
2333
try:
24-
if (kodiutils.get_setting_bool('auto_login')
25-
and kodiutils.get_setting('username')
26-
and kodiutils.get_setting('password')
27-
and kodiutils.get_setting('profile')):
34+
if kodiutils.get_setting_bool('auto_login') and kodiutils.get_setting('profile'):
2835
# We have credentials
2936
show_main_menu()
3037

3138
else:
3239
# Ask the user for the profile to use
3340
select_profile()
3441

35-
except NoLoginException:
36-
kodiutils.ok_dialog(message=kodiutils.localize(30701)) # You need to configure your credentials...
37-
kodiutils.open_settings()
38-
kodiutils.container_refresh()
39-
4042
except InvalidLoginException:
4143
kodiutils.ok_dialog(message=kodiutils.localize(30203)) # Your credentials are not valid!
4244
kodiutils.open_settings()
@@ -111,7 +113,7 @@ def show_catalog_program_season(program, season):
111113

112114
@routing.route('/catalog/recommendations/<storefront>')
113115
def show_recommendations(storefront):
114-
""" Shows the programs of a specific date in the tv guide """
116+
""" Shows the recommendations of a storefront """
115117
from resources.lib.modules.catalog import Catalog
116118
Catalog().show_recommendations(storefront)
117119

resources/lib/kodiplayer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from __future__ import absolute_import, division, unicode_literals
55

66
import logging
7-
import xbmc
87

8+
import xbmc
99

1010
_LOGGER = logging.getLogger(__name__)
1111

resources/lib/kodiutils.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ def addon_path():
111111

112112
def addon_profile():
113113
"""Cache and return add-on profile"""
114-
return to_unicode(xbmc.translatePath(ADDON.getAddonInfo('profile')))
114+
if kodi_version_major() >= 19:
115+
translate_path = xbmcvfs.translatePath
116+
else:
117+
translate_path = xbmc.translatePath
118+
return to_unicode(translate_path(ADDON.getAddonInfo('profile')))
115119

116120

117121
def url_for(name, *args, **kwargs):
@@ -311,7 +315,7 @@ def set_locale():
311315
"""Load the proper locale for date strings, only once"""
312316
if hasattr(set_locale, 'cached'):
313317
return getattr(set_locale, 'cached')
314-
from locale import Error, LC_ALL, setlocale
318+
from locale import LC_ALL, Error, setlocale
315319
locale_lang = get_global_setting('locale.language').split('.')[-1]
316320
locale_lang = locale_lang[:-2] + locale_lang[-2:].upper()
317321
# NOTE: setlocale() only works if the platform supports the Kodi configured locale
@@ -475,6 +479,11 @@ def get_addon_info(key):
475479
return to_unicode(ADDON.getAddonInfo(key))
476480

477481

482+
def execute_builtin(function):
483+
""" Execute a Kodi Builtin """
484+
xbmc.executebuiltin(function)
485+
486+
478487
def container_refresh(url=None):
479488
"""Refresh the current container or (re)load a container by URL"""
480489
if url:
@@ -562,9 +571,10 @@ def get_cache(key, ttl=None):
562571

563572
fdesc = xbmcvfs.File(fullpath, 'r')
564573

574+
import json
565575
try:
566-
import json
567576
value = json.load(fdesc)
577+
fdesc.close()
568578
_LOGGER.debug('Fetching %s from cache', fullpath)
569579
return value
570580
except (ValueError, TypeError):
@@ -587,7 +597,7 @@ def set_cache(key, data):
587597
_LOGGER.debug('Storing to cache as %s', fullpath)
588598
json.dump(data, fdesc)
589599

590-
# fdesc.close()
600+
fdesc.close()
591601

592602

593603
def invalidate_cache(ttl=None):

resources/lib/modules/catalog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from resources.lib import kodiutils
99
from resources.lib.kodiutils import TitleItem
1010
from resources.lib.modules.menu import Menu
11-
from resources.lib.streamz.api import Api, CACHE_PREVENT
11+
from resources.lib.streamz.api import CACHE_PREVENT, Api
1212
from resources.lib.streamz.auth import Auth
1313
from resources.lib.streamz.exceptions import UnavailableException
1414

resources/lib/modules/menu.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from resources.lib import kodiutils
99
from resources.lib.kodiutils import TitleItem
10-
from resources.lib.streamz import Movie, Program, Episode, STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_SERIES, STOREFRONT_KIDS
11-
from resources.lib.streamz.api import Api, CONTENT_TYPE_MOVIE, CONTENT_TYPE_PROGRAM
10+
from resources.lib.streamz import STOREFRONT_KIDS, STOREFRONT_MAIN, STOREFRONT_MAIN_KIDS, STOREFRONT_MOVIES, STOREFRONT_SERIES, Episode, Movie, Program
11+
from resources.lib.streamz.api import CONTENT_TYPE_MOVIE, CONTENT_TYPE_PROGRAM
1212
from resources.lib.streamz.auth import Auth
1313

1414
_LOGGER = logging.getLogger(__name__)
@@ -24,13 +24,14 @@ def __init__(self):
2424
kodiutils.get_setting('loginprovider'),
2525
kodiutils.get_setting('profile'),
2626
kodiutils.get_tokens_path())
27-
self._api = Api(self._auth)
2827

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

33-
if self._auth.login().product == 'STREAMZ':
32+
account = self._auth.login()
33+
34+
if account.product == 'STREAMZ':
3435
listing.append(TitleItem(
3536
title=kodiutils.localize(30015), # Recommendations
3637
path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_MAIN),
@@ -67,14 +68,26 @@ def show_mainmenu(self):
6768
),
6869
))
6970

70-
elif self._auth.login().product == 'STREAMZ_KIDS':
7171
listing.append(TitleItem(
72-
title=kodiutils.localize(30015), # Recommendations
72+
title=kodiutils.localize(30021), # Kids
7373
path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_KIDS),
7474
art_dict=dict(
7575
icon='DefaultFavourites.png',
7676
fanart=kodiutils.get_addon_info('fanart'),
7777
),
78+
info_dict=dict(
79+
plot=kodiutils.localize(30022),
80+
),
81+
))
82+
83+
elif account.product == 'STREAMZ_KIDS':
84+
listing.append(TitleItem(
85+
title=kodiutils.localize(30015), # Recommendations
86+
path=kodiutils.url_for('show_recommendations', storefront=STOREFRONT_MAIN_KIDS),
87+
art_dict=dict(
88+
icon='DefaultFavourites.png',
89+
fanart=kodiutils.get_addon_info('fanart'),
90+
),
7891
info_dict=dict(
7992
plot=kodiutils.localize(30016),
8093
),

resources/lib/modules/metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77

88
from resources.lib import kodiutils
9-
from resources.lib.streamz import Program, Movie
9+
from resources.lib.streamz import Movie, Program
1010
from resources.lib.streamz.api import Api
1111
from resources.lib.streamz.auth import Auth
1212

resources/lib/modules/player.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import logging
77

8-
from resources.lib.kodiplayer import KodiPlayer
98
from resources.lib import kodiutils
9+
from resources.lib.kodiplayer import KodiPlayer
1010
from resources.lib.streamz.api import Api
1111
from resources.lib.streamz.auth import Auth
12-
from resources.lib.streamz.exceptions import UnavailableException, LimitReachedException, StreamGeoblockedException, StreamUnavailableException
12+
from resources.lib.streamz.exceptions import LimitReachedException, StreamGeoblockedException, StreamUnavailableException, UnavailableException
1313
from resources.lib.streamz.stream import Stream
1414

1515
_LOGGER = logging.getLogger(__name__)

resources/lib/service.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from xbmc import Monitor
1010

1111
from resources.lib import kodilogging, kodiutils
12+
from resources.lib.streamz.exceptions import NoLoginException
1213

1314
kodilogging.config()
1415
_LOGGER = logging.getLogger(__name__)
@@ -48,7 +49,11 @@ def update_status(_i, _total):
4849
""" Allow to cancel the background job """
4950
return self.abortRequested() or not kodiutils.get_setting_bool('metadata_update')
5051

51-
success = Metadata().fetch_metadata(callback=update_status)
52+
try:
53+
success = Metadata().fetch_metadata(callback=update_status)
54+
except NoLoginException:
55+
# We have no login yet, but that's okay, we will retry later
56+
success = True
5257

5358
# Update metadata_last_updated
5459
if success:

resources/lib/streamz/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
STOREFRONT_MAIN = 'eba52f64-92da-4fec-804b-278ebafc75fd'
1010
STOREFRONT_MOVIES = '4f163159-15c3-452c-b275-1747b144cfa0'
1111
STOREFRONT_SERIES = 'dba19d15-1ddf-49ef-8eb5-99c59a1fb377'
12-
STOREFRONT_KIDS = 'e0c175c0-a43c-4eed-bdca-e1e95a726bc0'
12+
STOREFRONT_KIDS = 'a53d1ec3-ab43-4942-9d31-4f4754b4f519'
13+
STOREFRONT_MAIN_KIDS = 'e0c175c0-a43c-4eed-bdca-e1e95a726bc0'
1314

1415

1516
class Profile:

resources/lib/streamz/api.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88

99
from resources.lib import kodiutils
10-
from resources.lib.streamz import Category, Movie, Episode, Season, Program, util, API_ENDPOINT
10+
from resources.lib.streamz import API_ENDPOINT, Category, Episode, Movie, Program, Season, util
1111

1212
_LOGGER = logging.getLogger(__name__)
1313

@@ -346,7 +346,8 @@ def do_search(self, search):
346346
:type search: str
347347
:rtype list[Union[Movie, Program]]
348348
"""
349-
response = util.http_get(API_ENDPOINT + '/%s/search/?query=%s' % (self._mode(), quote(search)),
349+
response = util.http_get(API_ENDPOINT + '/%s/search/?query=%s' % (self._mode(),
350+
kodiutils.to_unicode(quote(kodiutils.from_unicode(search)))),
350351
token=self._tokens.jwt_token,
351352
profile=self._tokens.profile)
352353
results = json.loads(response.text)
@@ -430,5 +431,6 @@ def _parse_channel(url):
430431
return None
431432

432433
import os.path
434+
433435
# The channels id's we use in resources.lib.modules.CHANNELS neatly matches this part in the url.
434436
return str(os.path.basename(url).split('-')[0])

resources/lib/streamz/auth.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import re
1010
from hashlib import md5
1111

12-
from resources.lib.streamz import util, API_ENDPOINT, Profile
13-
from resources.lib.streamz.exceptions import LoginErrorException, NoLoginException, NoTelenetSubscriptionException, NoStreamzSubscriptionException, \
14-
InvalidLoginException
12+
from resources.lib.streamz import API_ENDPOINT, Profile, util
13+
from resources.lib.streamz.exceptions import (InvalidLoginException, LoginErrorException, NoLoginException, NoStreamzSubscriptionException,
14+
NoTelenetSubscriptionException)
1515

1616
try: # Python 3
1717
from urllib.parse import parse_qs, urlsplit

resources/lib/streamz/stream.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88

9-
from resources.lib.streamz import ResolvedStream, util, API_ENDPOINT
9+
from resources.lib.streamz import API_ENDPOINT, ResolvedStream, util
1010

1111
_LOGGER = logging.getLogger(__name__)
1212

@@ -190,9 +190,9 @@ def create_license_key(key_url, key_type='R', key_headers=None, key_value=None):
190190
:rtype: str
191191
"""
192192
try: # Python 3
193-
from urllib.parse import urlencode, quote
193+
from urllib.parse import quote, urlencode
194194
except ImportError: # Python 2
195-
from urllib import urlencode, quote
195+
from urllib import quote, urlencode
196196

197197
header = ''
198198
if key_headers:

resources/lib/streamz/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import requests
99
from requests import HTTPError
1010

11-
from resources.lib.streamz.exceptions import InvalidTokenException, InvalidLoginException, UnavailableException, LimitReachedException
11+
from resources.lib.streamz.exceptions import InvalidLoginException, InvalidTokenException, LimitReachedException, UnavailableException
1212

1313
_LOGGER = logging.getLogger(__name__)
1414

0 commit comments

Comments
 (0)