Simplify loop

This commit is contained in:
tomkat83 2017-05-25 13:58:15 +02:00
parent 5be7a5be8b
commit 0c0cf342df

View file

@ -326,42 +326,43 @@ class Player(xbmc.Player):
# Process each items
for item in self.played_info:
data = self.played_info.get(item)
if data:
log.debug("Item path: %s" % item)
log.debug("Item data: %s" % data)
if not data:
continue
log.debug("Item path: %s" % item)
log.debug("Item data: %s" % data)
runtime = data['runtime']
currentPosition = data['currentPosition']
itemid = data['item_id']
refresh_id = data['refresh_id']
currentFile = data['currentfile']
media_type = data['Type']
playMethod = data['playmethod']
runtime = data['runtime']
currentPosition = data['currentPosition']
itemid = data['item_id']
refresh_id = data['refresh_id']
currentFile = data['currentfile']
media_type = data['Type']
playMethod = data['playmethod']
# Prevent manually mark as watched in Kodi monitor
window('plex_skipWatched%s' % itemid, value="true")
# Prevent manually mark as watched in Kodi monitor
window('plex_skipWatched%s' % itemid, value="true")
if currentPosition and runtime:
try:
percentComplete = float(currentPosition) / float(runtime)
except ZeroDivisionError:
# Runtime is 0.
percentComplete = 0
if currentPosition and runtime:
try:
percentComplete = float(currentPosition) / float(runtime)
except ZeroDivisionError:
# Runtime is 0.
percentComplete = 0
markPlayed = 0.90
log.info("Percent complete: %s Mark played at: %s"
% (percentComplete, markPlayed))
if percentComplete >= markPlayed:
# Tell Kodi that we've finished watching (Plex knows)
if (data['fileid'] is not None and
data['itemType'] in (v.KODI_TYPE_MOVIE, v.KODI_TYPE_EPISODE)):
with kodidb.GetKodiDB('video') as kodi_db:
kodi_db.addPlaystate(
data['fileid'],
None,
None,
data['playcount'] + 1,
DateToKodi(getUnixTimestamp()))
markPlayed = 0.90
log.info("Percent complete: %s Mark played at: %s"
% (percentComplete, markPlayed))
if percentComplete >= markPlayed:
# Tell Kodi that we've finished watching (Plex knows)
if (data['fileid'] is not None and
data['itemType'] in (v.KODI_TYPE_MOVIE, v.KODI_TYPE_EPISODE)):
with kodidb.GetKodiDB('video') as kodi_db:
kodi_db.addPlaystate(
data['fileid'],
None,
None,
data['playcount'] + 1,
DateToKodi(getUnixTimestamp()))
# Clean the WINDOW properties
for filename in self.played_info: