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
|
||||
|
||||
|
||||
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
||||
headerOptions={}):
|
||||
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None):
|
||||
"""
|
||||
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)
|
||||
|
@ -206,7 +205,6 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
|||
since that point of time until now.
|
||||
updatedAt Unix timestamp; only retrieves PMS items updated
|
||||
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.
|
||||
|
||||
|
@ -216,14 +214,16 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
|
|||
e.g. when server and client are in different time zones.
|
||||
"""
|
||||
args = []
|
||||
url = "{server}/library/sections/%s/allLeaves?" % viewId
|
||||
url = "{server}/library/sections/%s/allLeaves" % viewId
|
||||
|
||||
if lastViewedAt:
|
||||
args.append('lastViewedAt>=%s' % lastViewedAt)
|
||||
if updatedAt:
|
||||
args.append('updatedAt>=%s' % updatedAt)
|
||||
args = '&'.join(args)
|
||||
xml = downloadutils.DownloadUtils().downloadUrl(
|
||||
url+args, headerOptions=headerOptions)
|
||||
if args:
|
||||
url += '?' + '&'.join(args)
|
||||
|
||||
xml = downloadutils.DownloadUtils().downloadUrl(url)
|
||||
|
||||
try:
|
||||
xml.attrib
|
||||
|
|
|
@ -32,7 +32,7 @@ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
|||
class DownloadUtils():
|
||||
|
||||
# Borg - multiple instances, shared state
|
||||
_shared_state = {}
|
||||
# _shared_state = {}
|
||||
clientInfo = clientinfo.ClientInfo()
|
||||
|
||||
# Requests session
|
||||
|
@ -41,7 +41,8 @@ class DownloadUtils():
|
|||
|
||||
def __init__(self):
|
||||
|
||||
self.__dict__ = self._shared_state
|
||||
# self.__dict__ = self._shared_state
|
||||
pass
|
||||
|
||||
def setUsername(self, username):
|
||||
# Reserved for userclient only
|
||||
|
|
|
@ -224,6 +224,26 @@ class Items(object):
|
|||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
||||
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):
|
||||
|
||||
|
@ -255,26 +275,6 @@ class Movies(Items):
|
|||
count += 1
|
||||
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):
|
||||
self.logMsg("Entering add_update", 1)
|
||||
# Process single movie
|
||||
|
@ -886,26 +886,6 @@ class TVShows(Items):
|
|||
if not pdialog and self.contentmsg:
|
||||
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):
|
||||
# Process single tvshow
|
||||
kodicursor = self.kodicursor
|
||||
|
|
|
@ -314,7 +314,8 @@ class LibrarySync(threading.Thread):
|
|||
if self.updatelist:
|
||||
if self.updatelist[0]['itemType'] in ['Movies', 'TVShows']:
|
||||
updateKodiVideoLib = True
|
||||
self.GetAndProcessXMLs(plexType)
|
||||
self.GetAndProcessXMLs(
|
||||
PlexFunctions.GetItemClassFromType(plexType))
|
||||
self.updatelist = []
|
||||
# Let Kodi grab the artwork now
|
||||
if updateKodiVideoLib:
|
||||
|
@ -791,17 +792,13 @@ class LibrarySync(threading.Thread):
|
|||
also updates resume times.
|
||||
This is done by downloading one XML for ALL elements with viewId
|
||||
"""
|
||||
# Download XML, not JSON, because PMS JSON seems to be damaged
|
||||
headerOptions = {'Accept': 'application/xml'}
|
||||
plexItems = PlexFunctions.GetAllPlexLeaves(
|
||||
viewId,
|
||||
xml = PlexFunctions.GetAllPlexLeaves(viewId,
|
||||
lastViewedAt=lastViewedAt,
|
||||
updatedAt=updatedAt,
|
||||
headerOptions=headerOptions)
|
||||
if plexItems:
|
||||
updatedAt=updatedAt)
|
||||
if xml:
|
||||
itemMth = getattr(itemtypes, itemType)
|
||||
with itemMth() as method:
|
||||
method.updateUserdata(plexItems)
|
||||
method.updateUserdata(xml)
|
||||
|
||||
def musicvideos(self, embycursor, kodicursor, pdialog):
|
||||
# Get musicvideos from emby
|
||||
|
@ -1147,19 +1144,19 @@ class LibrarySync(threading.Thread):
|
|||
else:
|
||||
# Run full lib scan approx every 10min
|
||||
if count % 600 == 0:
|
||||
self.logMsg('Running maintainViews() scan', 1)
|
||||
utils.window('emby_dbScan', value="true")
|
||||
self.logMsg('Running maintainViews() scan', 1)
|
||||
self.fullSync(manualrun=True)
|
||||
utils.window('emby_dbScan', value="false")
|
||||
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:
|
||||
self.logMsg('Running maintainViews() scan', 1)
|
||||
utils.window('emby_dbScan', value="true")
|
||||
self.maintainViews()
|
||||
self.startSync()
|
||||
# Run fast sync approx every 10s
|
||||
elif count % 10 == 0:
|
||||
# Run fast sync otherwise (ever second or so)
|
||||
else:
|
||||
self.startSync()
|
||||
|
||||
xbmc.sleep(1000)
|
||||
|
|
Loading…
Reference in a new issue