Skip to content

Commit e5a397b

Browse files
authored
[plugin.video.cinetree] v2.0.2 (#4671)
1 parent 08efbec commit e5a397b

6 files changed

Lines changed: 44 additions & 11 deletions

File tree

plugin.video.cinetree/addon.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.video.cinetree" name="Cinetree" version="2.0.1" provider-name="Dimitri Kroon">
2+
<addon id="plugin.video.cinetree" name="Cinetree" version="2.0.2" provider-name="Dimitri Kroon">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="inputstream.adaptive" version="19.0.7"/>
@@ -37,6 +37,11 @@
3737
</assets>
3838
<reuselanguageinvoker>true</reuselanguageinvoker>
3939
<news>
40+
[B]Version 2.0.2[/B]
41+
- Fix: Several lists failed to open with 'ParseError' due to some changes at Cinetree.
42+
- Fix: Add-on failed to open when the user was not logged in to Cinetree.
43+
44+
[B]Version 2.0.1[/B]
4045
- New logo image.
4146
- Now possible to directly rent a film with your prepaid credit at Cinetree.
4247
- Now possible to sort listings on the date the film was added to Cinetree.

plugin.video.cinetree/changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v 2.0.2
2+
- Fix: Several lists failed to open with 'ParseError' due to some changes at Cinetree.
3+
- Fix: Add-on failed to open when the user was not logged in to Cinetree.
4+
15
v 2.0.1
26
same as 2.0.0
37

plugin.video.cinetree/resources/lib/ctree/ct_api.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,19 @@ def get_subtitles(url: str, lang: str) -> str:
149149
return subt_file
150150

151151

152-
def get_watched_films():
152+
def get_watched_films(ask_login: bool = True):
153153
"""Get the list of 'Mijn Films'.
154154
155+
:param ask_login: Whether to show a dialog asking the user to login when
156+
the currently not logged in. If False, an AuthenticationError is raised
157+
without asking the user to sign in.
158+
155159
"""
156-
history = fetch.fetch_authenticated(fetch.get_json, 'https://api.cinetree.nl/watch-history', max_age=10)
160+
history = fetch.fetch_authenticated(
161+
fetch.get_json,
162+
url='https://api.cinetree.nl/watch-history',
163+
ask_login=ask_login,
164+
max_age=10)
157165
sb_films, _ = storyblok.stories_by_uuids(film['assetId'] for film in history)
158166
sb_films = {film['uuid']: film for film in sb_films}
159167

@@ -186,13 +194,22 @@ def remove_watched_film(film_uuid):
186194
return resp.status_code == 200
187195

188196

189-
def get_favourites(refresh=False):
190-
"""Films saved to the personal watch list at Cinetreee."""
197+
def get_favourites(refresh=False, ask_login=True):
198+
"""Films saved to the personal watch list at Cinetreee.
199+
200+
:param refresh: Whether to force requesting data from Cinetree, or just
201+
return already stored data when available.
202+
:param ask_login: Whether to show a dialog asking the user to login when
203+
the currently not logged in. If False, an AuthenticationError is raised
204+
without asking the user to sign in.
205+
206+
"""
191207
global favourites
192208
if refresh or favourites is None:
193209
resp = fetch.fetch_authenticated(
194210
fetch.get_json,
195211
url='https://api.cinetree.nl/favorites/',
212+
ask_login=ask_login,
196213
max_age=0)
197214

198215
favourites = {item['uuid']: item['createdAt'] for item in resp}

plugin.video.cinetree/resources/lib/fetch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_document(url, headers=None, **kwargs):
102102
return resp.text
103103

104104

105-
def fetch_authenticated(funct, url, **kwargs):
105+
def fetch_authenticated(funct, url, ask_login=True, **kwargs):
106106
"""Call one of the fetch function, but with user authentication
107107
108108
Call the specified function with authentication header and return the result.
@@ -129,7 +129,7 @@ def fetch_authenticated(funct, url, **kwargs):
129129
# This is quite common, as tokens seem to expire rather quickly on Cinetree
130130
if tries == 0:
131131
if account.refresh() is False:
132-
if not (kodi_utils.show_msg_not_logged_in() and account.login()):
132+
if not (ask_login and kodi_utils.show_msg_not_logged_in() and account.login()):
133133
raise
134134
else:
135135
# A NotAuthenticatedError even after a refresh or login succeeded:

plugin.video.cinetree/resources/lib/jsonp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ def parse(document: str) -> dict:
4545
document = document.replace('{}', 'null')
4646

4747
# Split the document in the function body, parameter and arguments list
48-
funct, args = document.rsplit('}', 1)
49-
_, funct = funct.split('function(', 1)
48+
pos = document.rfind('}(')
49+
args = document[pos + 1:]
50+
_, funct = document[:pos].split('function(', 1)
5051

5152
# Find the closing parentheses of the function definition and split the string
5253
# in the parameter list and function body

plugin.video.cinetree/resources/lib/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ def _create_playables(addon, films: Iterable[ct_data.FilmItem]):
125125
if addon:
126126
addon.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED,
127127
xbmcplugin.SORT_METHOD_DATEADDED)
128-
favourites = ct_api.get_favourites()
128+
try:
129+
favourites = ct_api.get_favourites(ask_login=False)
130+
except errors.AuthenticationError:
131+
favourites = {}
129132

130133
for film_item in films:
131134
if film_item:
@@ -303,7 +306,10 @@ def sync_watched_state():
303306
since the last time it was checked.
304307
305308
"""
306-
history = list(ct_api.get_watched_films())
309+
try:
310+
history = list(ct_api.get_watched_films(ask_login=False))
311+
except errors.AuthenticationError:
312+
return
307313
logger.debug("[sync_watched] History has %s items", len(history))
308314
with PersistentDict(constants.HISTORY_CACHE) as prev_watched:
309315
changed = {film for film in history if prev_watched.get(film.uuid) != film.playtime}

0 commit comments

Comments
 (0)