Skip to content

Commit

Permalink
Send a "stop" action if the session couldn't be found during an update
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Feb 22, 2015
1 parent d6c5188 commit 68ca533
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Trakttv.bundle/Contents/Code/pts/scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ def update_progress(ws, view_offset):
ws.progress = int(round(total_progress * 100, 0))
return True

def finish(self, ws):
if ws.progress is None or ws.progress < 80:
return False

log.debug('Session finished, sending a "stop" action')
self.handle_action(ws, 'stop')
return True

def valid(self, ws):
filtered = None

Expand Down
6 changes: 1 addition & 5 deletions Trakttv.bundle/Contents/Code/pts/scrobbler_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def create_session(self, info):
def session_valid(self, ws, info):
if ws.metadata.rating_key != info['ratingKey']:
log.debug('Invalid Session: Media changed')

if ws.progress >= 80:
log.debug('Media changed, sending a "stop" action')
self.handle_action(ws, 'stop')

self.finish(ws)
return False

if ws.skip and info.get('state') == 'stopped':
Expand Down
16 changes: 10 additions & 6 deletions Trakttv.bundle/Contents/Code/pts/scrobbler_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,24 @@ def create_session(self, session_key, state):
def update_session(self, ws, view_offset):
log.debug('Trying to update the current WatchSession (session key: %s)' % ws.key)

session = Plex['status'].sessions().get(ws.key)
sessions = Plex['status'].sessions()

if sessions is None:
log.warn('Unable to retrieve sessions')
return False

session = sessions.get(ws.key)

if not session:
log.warn('Session was not found on media server')
self.finish(ws)
return False

log.debug('last item key: %s, current item key: %s' % (ws.metadata.rating_key, session.rating_key))

if ws.metadata.rating_key != session.rating_key:
log.debug('Invalid Session: Media changed')

if ws.progress >= 80:
log.debug('Media changed, sending a "stop" action')
self.handle_action(ws, 'stop')

self.finish(ws)
return False

ws.last_view_offset = view_offset
Expand Down

0 comments on commit 68ca533

Please sign in to comment.