Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugin.video.cinetree/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.cinetree" name="Cinetree" version="2.0.1" provider-name="Dimitri Kroon">
<addon id="plugin.video.cinetree" name="Cinetree" version="2.0.2" provider-name="Dimitri Kroon">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="inputstream.adaptive" version="19.0.7"/>
Expand Down Expand Up @@ -37,6 +37,11 @@
</assets>
<reuselanguageinvoker>true</reuselanguageinvoker>
<news>
[B]Version 2.0.2[/B]
- Fix: Several lists failed to open with 'ParseError' due to some changes at Cinetree.
- Fix: Add-on failed to open when the user was not logged in to Cinetree.

[B]Version 2.0.1[/B]
- New logo image.
- Now possible to directly rent a film with your prepaid credit at Cinetree.
- Now possible to sort listings on the date the film was added to Cinetree.
Expand Down
4 changes: 4 additions & 0 deletions plugin.video.cinetree/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v 2.0.2
- Fix: Several lists failed to open with 'ParseError' due to some changes at Cinetree.
- Fix: Add-on failed to open when the user was not logged in to Cinetree.

v 2.0.1
same as 2.0.0

Expand Down
25 changes: 21 additions & 4 deletions plugin.video.cinetree/resources/lib/ctree/ct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,19 @@ def get_subtitles(url: str, lang: str) -> str:
return subt_file


def get_watched_films():
def get_watched_films(ask_login: bool = True):
"""Get the list of 'Mijn Films'.

:param ask_login: Whether to show a dialog asking the user to login when
the currently not logged in. If False, an AuthenticationError is raised
without asking the user to sign in.

"""
history = fetch.fetch_authenticated(fetch.get_json, 'https://api.cinetree.nl/watch-history', max_age=10)
history = fetch.fetch_authenticated(
fetch.get_json,
url='https://api.cinetree.nl/watch-history',
ask_login=ask_login,
max_age=10)
sb_films, _ = storyblok.stories_by_uuids(film['assetId'] for film in history)
sb_films = {film['uuid']: film for film in sb_films}

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


def get_favourites(refresh=False):
"""Films saved to the personal watch list at Cinetreee."""
def get_favourites(refresh=False, ask_login=True):
"""Films saved to the personal watch list at Cinetreee.

:param refresh: Whether to force requesting data from Cinetree, or just
return already stored data when available.
:param ask_login: Whether to show a dialog asking the user to login when
the currently not logged in. If False, an AuthenticationError is raised
without asking the user to sign in.

"""
global favourites
if refresh or favourites is None:
resp = fetch.fetch_authenticated(
fetch.get_json,
url='https://api.cinetree.nl/favorites/',
ask_login=ask_login,
max_age=0)

favourites = {item['uuid']: item['createdAt'] for item in resp}
Expand Down
4 changes: 2 additions & 2 deletions plugin.video.cinetree/resources/lib/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_document(url, headers=None, **kwargs):
return resp.text


def fetch_authenticated(funct, url, **kwargs):
def fetch_authenticated(funct, url, ask_login=True, **kwargs):
"""Call one of the fetch function, but with user authentication

Call the specified function with authentication header and return the result.
Expand All @@ -129,7 +129,7 @@ def fetch_authenticated(funct, url, **kwargs):
# This is quite common, as tokens seem to expire rather quickly on Cinetree
if tries == 0:
if account.refresh() is False:
if not (kodi_utils.show_msg_not_logged_in() and account.login()):
if not (ask_login and kodi_utils.show_msg_not_logged_in() and account.login()):
raise
else:
# A NotAuthenticatedError even after a refresh or login succeeded:
Expand Down
5 changes: 3 additions & 2 deletions plugin.video.cinetree/resources/lib/jsonp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def parse(document: str) -> dict:
document = document.replace('{}', 'null')

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

# Find the closing parentheses of the function definition and split the string
# in the parameter list and function body
Expand Down
10 changes: 8 additions & 2 deletions plugin.video.cinetree/resources/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def _create_playables(addon, films: Iterable[ct_data.FilmItem]):
if addon:
addon.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED,
xbmcplugin.SORT_METHOD_DATEADDED)
favourites = ct_api.get_favourites()
try:
favourites = ct_api.get_favourites(ask_login=False)
except errors.AuthenticationError:
favourites = {}

for film_item in films:
if film_item:
Expand Down Expand Up @@ -303,7 +306,10 @@ def sync_watched_state():
since the last time it was checked.

"""
history = list(ct_api.get_watched_films())
try:
history = list(ct_api.get_watched_films(ask_login=False))
except errors.AuthenticationError:
return
logger.debug("[sync_watched] History has %s items", len(history))
with PersistentDict(constants.HISTORY_CACHE) as prev_watched:
changed = {film for film in history if prev_watched.get(film.uuid) != film.playtime}
Expand Down