Prevent double marking as watched

Also removed the mark watched at: % setting. It is controlled by the
server itself.
This commit is contained in:
angelblue05 2015-10-04 06:05:31 -05:00
parent 43494ec053
commit 7d9fe89806
5 changed files with 56 additions and 41 deletions

View file

@ -16,13 +16,18 @@ from DownloadUtils import DownloadUtils
from PlaybackUtils import PlaybackUtils
class Kodi_Monitor(xbmc.Monitor):
class Kodi_Monitor( xbmc.Monitor ):
WINDOW = xbmcgui.Window(10000)
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
def logMsg(self, msg, lvl = 1):
className = self.__class__.__name__
utils.logMsg("%s %s" % ("EMBY", className), msg, int(lvl))
def onDatabaseUpdated(self, database):
pass
@ -97,23 +102,26 @@ class Kodi_Monitor(xbmc.Monitor):
WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex')))
if mediaSources[0].get('DefaultSubtitleStreamIndex') != None:
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))
if method == "VideoLibrary.OnUpdate":
# Triggers 4 times, the following is only for manually marking as watched/unwatched
jsondata = json.loads(data)
if jsondata != None:
playcount = None
playcount = jsondata.get("playcount")
item = jsondata.get("item").get("id")
type = jsondata.get("item").get("type")
prop = WINDOW.getProperty('Played%s%s' % (type,item))
processWatched = WINDOW.getProperty('played_skipWatched')
if (playcount != None) and (prop != "true") and (processWatched != "true"):
WINDOW.setProperty("Played%s%s" % (type,item), "true")
utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2)
try:
playcount = jsondata['playcount']
item = jsondata['item']['id']
type = jsondata['item']['type']
prop = utils.window('Played%s%s' % (type, item))
except:
self.logMsg("Could not process VideoLibrary.OnUpdate data.", 1)
else:
self.logMsg("VideoLibrary.OnUpdate: %s" % data, 2)
if prop != "true":
# Set property to prevent the multi triggering
utils.window('Played%s%s' % (type, item), "true")
WriteKodiVideoDB().updatePlayCountFromKodi(item, type, playcount)
self.clearProperty(type,item)
self.clearProperty(type, item)
if method == "System.OnWake":
xbmc.sleep(10000) #Allow network to wake up
@ -145,13 +153,11 @@ class Kodi_Monitor(xbmc.Monitor):
xbmc.log('Deleting via URL: ' + url)
DownloadUtils().downloadUrl(url, type="DELETE")
def clearProperty(self,type,id):
def clearProperty(self, type, id):
# The sleep is necessary since VideoLibrary.OnUpdate
# triggers 3 times in a row.
# triggers 4 times in a row.
xbmc.sleep(100)
self.WINDOW.clearProperty("Played%s%s" % (type,id))
self.WINDOW.clearProperty('played_skipWatched')
#clear the widget cache
self.WINDOW.setProperty('clearwidgetcache','clear')
utils.window('Played%s%s' % (type,id), clear=True)
# Clear the widget cache
utils.window('clearwidgetcache', value="clear")

View file

@ -378,8 +378,8 @@ class Player( xbmc.Player ):
data = self.played_information.get(item)
if data:
self.logMsg("Item path: %s" % item, 1)
self.logMsg("Item data: %s" % str(data), 1)
self.logMsg("Item path: %s" % item, 2)
self.logMsg("Item data: %s" % str(data), 2)
runtime = data.get('runtime')
currentPosition = data.get('currentPosition')
@ -390,14 +390,12 @@ class Player( xbmc.Player ):
playMethod = data.get('playmethod')
if currentPosition and runtime:
self.logMsg("RuntimeTicks: %s" % runtime, 1)
percentComplete = (currentPosition * 10000000) / int(runtime)
markPlayedAt = float(utils.settings('markPlayed')) / 100
self.logMsg("Percent complete: %s Mark played at: %s" % (percentComplete, markPlayedAt))
if percentComplete < markPlayedAt:
# Do not mark as watched for Kodi Monitor
utils.window('played_skipWatched', value="true")
self.logMsg("Percent complete: %s Mark played at: %s" % (percentComplete, markPlayedAt), 1)
# Prevent manually mark as watched in Kodi monitor > WriteKodiVideoDB().UpdatePlaycountFromKodi()
utils.window('SkipWatched%s' % itemId, "true")
self.stopPlayback(data)
offerDelete = False
@ -430,8 +428,8 @@ class Player( xbmc.Player ):
self.logMsg("stopPlayback called", 2)
itemId = data.get('item_id')
currentPosition = data.get('currentPosition')
itemId = data['item_id']
currentPosition = data['currentPosition']
positionTicks = int(currentPosition * 10000000)
url = "{server}/mediabrowser/Sessions/Playing/Stopped"

View file

@ -184,6 +184,12 @@ class UserClient(threading.Thread):
# Set user image for skin display
self.WINDOW.setProperty("EmbyUserImage",API().getUserArtwork(result,"Primary"))
# Load the resume point from Emby and set as setting
url = "{server}/mediabrowser/System/Configuration?format=json"
result = self.doUtils.downloadUrl(url)
utils.settings('markPlayed', value=str(result['MaxResumePct']))
return True
def getPublicUsers(self):

View file

@ -57,16 +57,21 @@ class WriteKodiVideoDB():
# Could not find the Emby Id
self.logMsg("Emby Id not found.", 2)
else:
# Found the Emby Id, let Emby server know of new playcount
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
if playcount != 0:
doUtils.downloadUrl(watchedurl, type = "POST")
self.logMsg("Mark as watched for Id: %s, playcount: %s." % (emby_id, playcount), 1)
# Stop from manually marking as watched unwatched, with actual playback.
# Window property is set in Player.py
if utils.window('SkipWatched%s' % emby_id) == "true":
utils.window('SkipWatched%s' % emby_id, clear=True)
else:
doUtils.downloadUrl(watchedurl, type = "DELETE")
self.logMsg("Mark as unwatched for Id: %s, playcount: %s." % (emby_id, playcount), 1)
# Erase any resume point associated
self.setKodiResumePoint(id, 0, 0, cursor, playcount)
# Found the Emby Id, let Emby server know of new playcount
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
if playcount != 0:
doUtils.downloadUrl(watchedurl, type = "POST")
self.logMsg("Mark as watched for Id: %s, playcount: %s." % (emby_id, playcount), 1)
else:
doUtils.downloadUrl(watchedurl, type = "DELETE")
self.logMsg("Mark as unwatched for Id: %s, playcount: %s." % (emby_id, playcount), 1)
# Erase any resume point associated
self.setKodiResumePoint(id, 0, 0, cursor, playcount)
finally:
cursor.close

View file

@ -36,13 +36,13 @@
<setting id="smbpassword" type="text" label="30008" default="" option="hidden" visible="true" enable="true" />
<setting type="sep" />
<setting id="disableCinema" type="bool" label="Disable Emby cinema mode" default="false" visible="true" enable="true" />
<setting id="markPlayed" label="Mark watched at" type="slider" default="90" range="60,5,100" option="percent" visible="true" enable="true" />
<setting id="offerDelete" type="bool" label="30114" visible="true" enable="true" default="false" />
<setting id="offerDeleteTV" type="bool" label="30115" visible="eq(-1,true)" enable="true" default="false" />
<setting id="offerDeleteMovies" type="bool" label="30116" visible="eq(-2,true)" enable="true" default="false" />
<setting id="resumeJumpBack" type="slider" label="On Resume Jump Back Seconds" default="10" range="0,1,120" option="int" visible="true" enable="true" />
<setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" />
<setting id="videoBitRate" type="enum" label="30160" values="664 Kbps SD|996 Kbps HD|1.3 Mbps HD|2.0 Mbps HD|3.2 Mbps HD|4.7 Mbps HD|6.2 Mbps HD|7.7 Mbps HD|9.2 Mbps HD|10.7 Mbps HD|12.2 Mbps HD|13.7 Mbps HD|15.2 Mbps HD|16.7 Mbps HD|18.2 Mbps HD|20.0 Mbps HD|40.0 Mbps HD|100.0 Mbps HD [default]|1000.0 Mbps HD" visible="eq(-1,true)" default="17" />
<setting id="markPlayed" type="number" visible="false" default="90" />
<setting id="directSteamFailedCount" type="number" visible="false" default="0" />
</category>
<category label="Extras">