Fix userdata
This commit is contained in:
parent
4b2e069bff
commit
bf45cd5e13
5 changed files with 44 additions and 66 deletions
|
@ -194,8 +194,7 @@ def GetPlexSectionResults(viewId, headerOptions={}):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None):
|
||||||
headerOptions={}):
|
|
||||||
"""
|
"""
|
||||||
Returns a list (raw XML API dump) of all Plex subitems for the key.
|
Returns a list (raw XML API dump) of all Plex subitems for the key.
|
||||||
(e.g. /library/sections/2/allLeaves pointing to all TV shows)
|
(e.g. /library/sections/2/allLeaves pointing to all TV shows)
|
||||||
|
@ -206,7 +205,6 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
||||||
since that point of time until now.
|
since that point of time until now.
|
||||||
updatedAt Unix timestamp; only retrieves PMS items updated
|
updatedAt Unix timestamp; only retrieves PMS items updated
|
||||||
by the PMS since that point of time until now.
|
by the PMS since that point of time until now.
|
||||||
headerOptions to override any download headers
|
|
||||||
|
|
||||||
If lastViewedAt and updatedAt=None, ALL PMS items are returned.
|
If lastViewedAt and updatedAt=None, ALL PMS items are returned.
|
||||||
|
|
||||||
|
@ -216,14 +214,16 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
||||||
e.g. when server and client are in different time zones.
|
e.g. when server and client are in different time zones.
|
||||||
"""
|
"""
|
||||||
args = []
|
args = []
|
||||||
url = "{server}/library/sections/%s/allLeaves?" % viewId
|
url = "{server}/library/sections/%s/allLeaves" % viewId
|
||||||
|
|
||||||
if lastViewedAt:
|
if lastViewedAt:
|
||||||
args.append('lastViewedAt>=%s' % lastViewedAt)
|
args.append('lastViewedAt>=%s' % lastViewedAt)
|
||||||
if updatedAt:
|
if updatedAt:
|
||||||
args.append('updatedAt>=%s' % updatedAt)
|
args.append('updatedAt>=%s' % updatedAt)
|
||||||
args = '&'.join(args)
|
if args:
|
||||||
xml = downloadutils.DownloadUtils().downloadUrl(
|
url += '?' + '&'.join(args)
|
||||||
url+args, headerOptions=headerOptions)
|
|
||||||
|
xml = downloadutils.DownloadUtils().downloadUrl(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml.attrib
|
xml.attrib
|
||||||
|
|
|
@ -32,7 +32,7 @@ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
class DownloadUtils():
|
class DownloadUtils():
|
||||||
|
|
||||||
# Borg - multiple instances, shared state
|
# Borg - multiple instances, shared state
|
||||||
_shared_state = {}
|
# _shared_state = {}
|
||||||
clientInfo = clientinfo.ClientInfo()
|
clientInfo = clientinfo.ClientInfo()
|
||||||
|
|
||||||
# Requests session
|
# Requests session
|
||||||
|
@ -41,7 +41,8 @@ class DownloadUtils():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.__dict__ = self._shared_state
|
# self.__dict__ = self._shared_state
|
||||||
|
pass
|
||||||
|
|
||||||
def setUsername(self, username):
|
def setUsername(self, username):
|
||||||
# Reserved for userclient only
|
# Reserved for userclient only
|
||||||
|
|
|
@ -224,6 +224,26 @@ class Items(object):
|
||||||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
||||||
sound=False)
|
sound=False)
|
||||||
|
|
||||||
|
def updateUserdata(self, xml):
|
||||||
|
"""
|
||||||
|
Updates the Kodi watched state of the item from PMS. Also retrieves
|
||||||
|
Plex resume points for movies in progress.
|
||||||
|
"""
|
||||||
|
self.logMsg("Entering updateUserdata", 1)
|
||||||
|
for mediaitem in xml:
|
||||||
|
API = PlexAPI.API(mediaitem)
|
||||||
|
itemid = API.getRatingKey()
|
||||||
|
# Get key and db entry on the Kodi db side
|
||||||
|
fileid = self.emby_db.getItem_byId(itemid)[1]
|
||||||
|
# Grab the user's viewcount, resume points etc. from PMS' answer
|
||||||
|
userdata = API.getUserData()
|
||||||
|
# Write to Kodi DB
|
||||||
|
self.kodi_db.addPlaystate(fileid,
|
||||||
|
userdata['Resume'],
|
||||||
|
userdata['Runtime'],
|
||||||
|
userdata['PlayCount'],
|
||||||
|
userdata['LastPlayedDate'])
|
||||||
|
|
||||||
|
|
||||||
class Movies(Items):
|
class Movies(Items):
|
||||||
|
|
||||||
|
@ -255,26 +275,6 @@ class Movies(Items):
|
||||||
count += 1
|
count += 1
|
||||||
self.add_updateBoxset(boxset)
|
self.add_updateBoxset(boxset)
|
||||||
|
|
||||||
def updateUserdata(self, itemList):
|
|
||||||
"""
|
|
||||||
Updates the Kodi watched state of the item from PMS. Also retrieves
|
|
||||||
Plex resume points for movies in progress.
|
|
||||||
"""
|
|
||||||
API = PlexAPI.API(itemList)
|
|
||||||
for itemNumber in range(len(itemList)):
|
|
||||||
API.setChildNumber(itemNumber)
|
|
||||||
itemid = API.getRatingKey()
|
|
||||||
# Get key and db entry on the Kodi db side
|
|
||||||
fileid = self.emby_db.getItem_byId(itemid)[1]
|
|
||||||
# Grab the user's viewcount, resume points etc. from PMS' answer
|
|
||||||
userdata = API.getUserData()
|
|
||||||
# Write to Kodi DB
|
|
||||||
self.kodi_db.addPlaystate(fileid,
|
|
||||||
userdata['Resume'],
|
|
||||||
userdata['Runtime'],
|
|
||||||
userdata['PlayCount'],
|
|
||||||
userdata['LastPlayedDate'])
|
|
||||||
|
|
||||||
def add_update(self, item, viewtag=None, viewid=None):
|
def add_update(self, item, viewtag=None, viewid=None):
|
||||||
self.logMsg("Entering add_update", 1)
|
self.logMsg("Entering add_update", 1)
|
||||||
# Process single movie
|
# Process single movie
|
||||||
|
@ -886,26 +886,6 @@ class TVShows(Items):
|
||||||
if not pdialog and self.contentmsg:
|
if not pdialog and self.contentmsg:
|
||||||
self.contentPop(title)
|
self.contentPop(title)
|
||||||
|
|
||||||
def updateUserdata(self, itemList):
|
|
||||||
"""
|
|
||||||
Updates the Kodi watched state of the item from PMS. Also retrieves
|
|
||||||
Plex resume points for movies in progress.
|
|
||||||
"""
|
|
||||||
API = PlexAPI.API(itemList)
|
|
||||||
for itemNumber in range(len(itemList)):
|
|
||||||
API.setChildNumber(itemNumber)
|
|
||||||
itemid = API.getRatingKey()
|
|
||||||
# Get key and db entry on the Kodi db side
|
|
||||||
fileid = self.emby_db.getItem_byId(itemid)[1]
|
|
||||||
# Grab the user's viewcount, resume points etc. from PMS' answer
|
|
||||||
userdata = API.getUserData()
|
|
||||||
# Write to Kodi DB
|
|
||||||
self.kodi_db.addPlaystate(fileid,
|
|
||||||
userdata['Resume'],
|
|
||||||
userdata['Runtime'],
|
|
||||||
userdata['PlayCount'],
|
|
||||||
userdata['LastPlayedDate'])
|
|
||||||
|
|
||||||
def add_update(self, item, viewtag=None, viewid=None):
|
def add_update(self, item, viewtag=None, viewid=None):
|
||||||
# Process single tvshow
|
# Process single tvshow
|
||||||
kodicursor = self.kodicursor
|
kodicursor = self.kodicursor
|
||||||
|
|
|
@ -314,7 +314,8 @@ class LibrarySync(threading.Thread):
|
||||||
if self.updatelist:
|
if self.updatelist:
|
||||||
if self.updatelist[0]['itemType'] in ['Movies', 'TVShows']:
|
if self.updatelist[0]['itemType'] in ['Movies', 'TVShows']:
|
||||||
updateKodiVideoLib = True
|
updateKodiVideoLib = True
|
||||||
self.GetAndProcessXMLs(plexType)
|
self.GetAndProcessXMLs(
|
||||||
|
PlexFunctions.GetItemClassFromType(plexType))
|
||||||
self.updatelist = []
|
self.updatelist = []
|
||||||
# Let Kodi grab the artwork now
|
# Let Kodi grab the artwork now
|
||||||
if updateKodiVideoLib:
|
if updateKodiVideoLib:
|
||||||
|
@ -791,17 +792,13 @@ class LibrarySync(threading.Thread):
|
||||||
also updates resume times.
|
also updates resume times.
|
||||||
This is done by downloading one XML for ALL elements with viewId
|
This is done by downloading one XML for ALL elements with viewId
|
||||||
"""
|
"""
|
||||||
# Download XML, not JSON, because PMS JSON seems to be damaged
|
xml = PlexFunctions.GetAllPlexLeaves(viewId,
|
||||||
headerOptions = {'Accept': 'application/xml'}
|
lastViewedAt=lastViewedAt,
|
||||||
plexItems = PlexFunctions.GetAllPlexLeaves(
|
updatedAt=updatedAt)
|
||||||
viewId,
|
if xml:
|
||||||
lastViewedAt=lastViewedAt,
|
|
||||||
updatedAt=updatedAt,
|
|
||||||
headerOptions=headerOptions)
|
|
||||||
if plexItems:
|
|
||||||
itemMth = getattr(itemtypes, itemType)
|
itemMth = getattr(itemtypes, itemType)
|
||||||
with itemMth() as method:
|
with itemMth() as method:
|
||||||
method.updateUserdata(plexItems)
|
method.updateUserdata(xml)
|
||||||
|
|
||||||
def musicvideos(self, embycursor, kodicursor, pdialog):
|
def musicvideos(self, embycursor, kodicursor, pdialog):
|
||||||
# Get musicvideos from emby
|
# Get musicvideos from emby
|
||||||
|
@ -1147,19 +1144,19 @@ class LibrarySync(threading.Thread):
|
||||||
else:
|
else:
|
||||||
# Run full lib scan approx every 10min
|
# Run full lib scan approx every 10min
|
||||||
if count % 600 == 0:
|
if count % 600 == 0:
|
||||||
self.logMsg('Running maintainViews() scan', 1)
|
|
||||||
utils.window('emby_dbScan', value="true")
|
utils.window('emby_dbScan', value="true")
|
||||||
|
self.logMsg('Running maintainViews() scan', 1)
|
||||||
self.fullSync(manualrun=True)
|
self.fullSync(manualrun=True)
|
||||||
utils.window('emby_dbScan', value="false")
|
|
||||||
count = 0
|
count = 0
|
||||||
# Update views / PMS libraries approx. every 2 minutes
|
utils.window('emby_dbScan', value="false")
|
||||||
|
# Update views / PMS libraries approx. every 5
|
||||||
elif count % 120 == 0:
|
elif count % 120 == 0:
|
||||||
self.logMsg('Running maintainViews() scan', 1)
|
self.logMsg('Running maintainViews() scan', 1)
|
||||||
utils.window('emby_dbScan', value="true")
|
utils.window('emby_dbScan', value="true")
|
||||||
self.maintainViews()
|
self.maintainViews()
|
||||||
self.startSync()
|
self.startSync()
|
||||||
# Run fast sync approx every 10s
|
# Run fast sync otherwise (ever second or so)
|
||||||
elif count % 10 == 0:
|
else:
|
||||||
self.startSync()
|
self.startSync()
|
||||||
|
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Playlist():
|
||||||
mediatype = embydb_item[4]
|
mediatype = embydb_item[4]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Item is not found in our database, add item manually
|
# Item is not found in our database, add item manually
|
||||||
self.logMsg("Item was not found in the database, manually adding item.", 1)
|
self.logMsg("Item was not found in the database, manually adding item.", 1)
|
||||||
item = self.emby.getItem(itemid)
|
item = self.emby.getItem(itemid)
|
||||||
self.addtoPlaylist_xbmc(playlist, item)
|
self.addtoPlaylist_xbmc(playlist, item)
|
||||||
else:
|
else:
|
||||||
|
@ -67,7 +67,7 @@ class Playlist():
|
||||||
# Seek to the starting position
|
# Seek to the starting position
|
||||||
seektime = startat / 10000000.0
|
seektime = startat / 10000000.0
|
||||||
player.seekTime(seektime)
|
player.seekTime(seektime)
|
||||||
self.logMsg("Seeking to: %s" % seektime, 1)
|
self.logMsg("Seeking to: %s" % seektime, 1)
|
||||||
|
|
||||||
self.verifyPlaylist()
|
self.verifyPlaylist()
|
||||||
embycursor.close()
|
embycursor.close()
|
||||||
|
|
Loading…
Reference in a new issue