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

View File

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

View File

@ -184,6 +184,12 @@ class UserClient(threading.Thread):
# Set user image for skin display # Set user image for skin display
self.WINDOW.setProperty("EmbyUserImage",API().getUserArtwork(result,"Primary")) 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 return True
def getPublicUsers(self): def getPublicUsers(self):

View File

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

View File

@ -36,13 +36,13 @@
<setting id="smbpassword" type="text" label="30008" default="" option="hidden" visible="true" enable="true" /> <setting id="smbpassword" type="text" label="30008" default="" option="hidden" visible="true" enable="true" />
<setting type="sep" /> <setting type="sep" />
<setting id="disableCinema" type="bool" label="Disable Emby cinema mode" default="false" visible="true" enable="true" /> <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="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="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="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="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="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="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" /> <setting id="directSteamFailedCount" type="number" visible="false" default="0" />
</category> </category>
<category label="Extras"> <category label="Extras">