Skip to content

Commit

Permalink
Wait for the resumepoints to be updated before loading the menus
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed Dec 22, 2019
1 parent ede4623 commit 0785c6b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
18 changes: 18 additions & 0 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,24 @@ def end_of_directory():
xbmcplugin.endOfDirectory(handle=plugin.handle, succeeded=False, updateListing=False, cacheToDisc=False)


def wait_for_resumepoints():
"""Wait for resumepoints to be updated"""
update = get_property('vrtnu_resumepoints')
if update == 'busy':
import time
timeout = time.time() + 5 # 5 seconds timeout
log(3, 'Resumepoint update is busy, wait')
while update != 'ready':
if time.time() > timeout: # Exit loop in case something goes wrong
break
xbmc.sleep(50)
update = get_property('vrtnu_resumepoints')
set_property('vrtnu_resumepoints', None)
log(3, 'Resumepoint update is ready, continue')
return True
return False


def log(level=1, message='', **kwargs):
"""Log info messages to Kodi"""
debug_logging = get_global_setting('debug.showloginfo') # Returns a boolean
Expand Down
18 changes: 13 additions & 5 deletions resources/lib/playerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from apihelper import ApiHelper
from data import CHANNELS
from favorites import Favorites
from kodiutils import addon_id, container_reload, get_setting, has_addon, log, notify
from kodiutils import addon_id, get_setting, has_addon, log, notify, set_property
from resumepoints import ResumePoints
from utils import assetpath_to_id, play_url_to_id, to_unicode, url_to_episode

Expand Down Expand Up @@ -64,7 +64,7 @@ def onPlayBackStarted(self): # pylint: disable=invalid-name

# Avoid setting resumepoints for livestreams
for channel in CHANNELS:
if ep_id.get('video_id') == channel.get('live_stream_id'):
if ep_id.get('video_id') and ep_id.get('video_id') == channel.get('live_stream_id'):
log(3, '[PlayerInfo %d] Avoid setting resumepoints for livestream %s' % (self.thread_id, ep_id.get('video_id')))
self.listen = False
return
Expand Down Expand Up @@ -107,11 +107,16 @@ def onPlayBackSeek(self, time, seekOffset): # pylint: disable=invalid-name
log(3, '[PlayerInfo %d] Event onPlayBackSeek time=%d offset=%d' % (self.thread_id, time, seekOffset))
self.last_pos = time // 1000

# If we seek beyond the end, quit Player
# If we seek beyond the start or end, set property to let wait_for_resumepoints function know that update resume is busy
if self.last_pos >= self.total:
set_property('vrtnu_resumepoints', 'busy')
# Exit Player faster
self.quit.set()
self.stop()

if self.last_pos < 0:
set_property('vrtnu_resumepoints', 'busy')

def onPlayBackPaused(self): # pylint: disable=invalid-name
"""Called when user pauses a playing file"""
if not self.listen:
Expand Down Expand Up @@ -218,6 +223,9 @@ def push_position(self, position, total):
if not self.asset_id:
return

# Set property to let wait_for_resumepoints function know that update resume is busy
set_property('vrtnu_resumepoints', 'busy')

# Push resumepoint to VRT NU
self.resumepoints.update(
asset_id=self.asset_id,
Expand All @@ -228,5 +236,5 @@ def push_position(self, position, total):
whatson_id=self.whatson_id
)

# Always reload container
container_reload()
# Set property to let wait_for_resumepoints function know that update resume is done
set_property('vrtnu_resumepoints', 'ready')
2 changes: 2 additions & 0 deletions resources/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def init_watching_activity(self):
self._favorites = Favorites()
if not self._apihelper:
self._apihelper = ApiHelper(self._favorites, self._resumepoints)
else:
self._playerinfo = None

def onNotification(self, sender, method, data): # pylint: disable=invalid-name
"""Handler for notifications"""
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from helperobjects import TitleItem
from kodiutils import (delete_cached_thumbnail, end_of_directory, get_addon_info, get_setting,
has_credentials, localize, log_error, ok_dialog, play, set_setting,
show_listing, ttl, url_for)
show_listing, ttl, url_for, wait_for_resumepoints)
from resumepoints import ResumePoints
from utils import find_entry, realpage

Expand All @@ -21,6 +21,7 @@ def __init__(self):
self._favorites = Favorites()
self._resumepoints = ResumePoints()
self._apihelper = ApiHelper(self._favorites, self._resumepoints)
wait_for_resumepoints()

def show_main_menu(self):
"""The VRT NU add-on main menu"""
Expand Down

0 comments on commit 0785c6b

Please sign in to comment.