Backgroundsync using websockets

This commit is contained in:
tomkat83 2016-03-27 16:57:20 +02:00
parent 5949988b68
commit 6a2094d444
8 changed files with 61 additions and 26 deletions

View file

@ -299,7 +299,7 @@
<string id="30534">Server messages</string>
<string id="30535">[COLOR yellow]Generate a new unique device Id (e.g. when cloning Kodi)[/COLOR]</string>
<string id="30536">Users must log in every time when Kodi restarts</string>
<string id="30537">Restart Kodi if you make changes</string>
<string id="30537">RESTART KODI IF YOU MAKE ANY CHANGES</string>
<string id="30538">Complete Re-Sync necessary</string>
@ -393,6 +393,9 @@
<string id="39048">On Deck: Append season- and episode-number (e.g. S3E2)</string>
<string id="39049">Nothing works? Try a full reset!</string>
<string id="39050">[COLOR yellow]Choose Plex Server from a list[/COLOR]</string>
<string id="39051">Wait before sync new/changed PMS item [s]</string>
<string id="39052">Background Sync</string>
<!-- Plex Entrypoint.py -->

View file

@ -26,7 +26,7 @@
<string id="30535">[COLOR yellow]Neue einzigartige Geräte-ID generieren (z.B. wenn Kodi geklont wurde)[/COLOR]</string>
<string id="30536">Benutzer müssen sich bei jedem Neustart von Kodi neu anmelden</string>
<string id="30537">Bei Änderungen Kodi neu starten</string>
<string id="30537">BEI ÄNDERUNGEN KODI NEU STARTEN</string>
<string id="30538">Komplette Neusynchronisierung nötig</string>
@ -331,6 +331,8 @@
<string id="39048">"Aktuell": Staffel und Episode anfügen (z.B. S3E2)</string>
<string id="39049">Nichts funktioniert? Setze mal alles zurück!</string>
<string id="39050">[COLOR yellow]Plex Server aus Liste auswählen[/COLOR]</string>
<string id="39051">Warten bevor neue/geänderte PMS Einträge gesynct werden [s]</string>
<string id="39052">Hintergrund-Synchronisation</string>
<!-- Plex Entrypoint.py -->
<string id="39200">Plex Home Benutzer abmelden: </string>

View file

@ -472,6 +472,48 @@ def GetMachineIdentifier(url):
return machineIdentifier
def GetPMSStatus(token):
"""
token: Needs to be authorized with a master Plex token
(not a managed user token)!
Calls /status/sessions on currently active PMS. Returns a dict with:
'sessionKey':
{
'userId': Plex ID of the user (if applicable, otherwise '')
'username': Plex name (if applicable, otherwise '')
'ratingKey': Unique Plex id of item being played
}
or an empty dict.
"""
answer = {}
xml = downloadutils.DownloadUtils().downloadUrl(
"{server}" + '/status/sessions',
type="GET",
headerOptions={'X-Plex-Token': token})
try:
xml.attrib
except AttributeError:
return answer
for item in xml:
ratingKey = item.attrib.get('ratingKey')
sessionKey = item.attrib.get('sessionKey')
userId = item.find('User')
username = ''
if userId is not None:
username = userId.attrib.get('title', '')
userId = userId.attrib.get('id', '')
else:
userId = ''
answer[sessionKey] = {
'userId': userId,
'username': username,
'ratingKey': ratingKey
}
return answer
def scrobble(ratingKey, state):
"""
Tells the PMS to set an item's watched state to state="watched" or

View file

@ -177,7 +177,6 @@ class DownloadUtils():
def getHeader(self, authenticate=True, options={}):
plx = PlexAPI.PlexAPI()
if authenticate:
options['X-Plex-Token'] = self.token
header = plx.getXArgsDeviceInfo(options=options)
else:
header = plx.getXArgsDeviceInfo(options=options)

View file

@ -33,24 +33,9 @@ def DateToKodi(stamp):
Output: Y-m-d h:m:s = 2009-04-05 23:16:04
"""
# DATEFORMAT = xbmc.getRegion('dateshort')
# TIMEFORMAT = xbmc.getRegion('meridiem')
# date_time = time.localtime(stamp)
# if DATEFORMAT[1] == 'd':
# localdate = time.strftime('%d-%m-%Y', date_time)
# elif DATEFORMAT[1] == 'm':
# localdate = time.strftime('%m-%d-%Y', date_time)
# else:
# localdate = time.strftime('%Y-%m-%d', date_time)
# if TIMEFORMAT != '/':
# localtime = time.strftime('%I:%M%p', date_time)
# else:
# localtime = time.strftime('%H:%M', date_time)
# return localtime + ' ' + localdate
stamp = float(stamp) + float(window('kodiplextimeoffset'))
try:
# DATEFORMAT = xbmc.getRegion('dateshort')
# TIMEFORMAT = xbmc.getRegion('meridiem')
date_time = time.localtime(float(stamp))
date_time = time.localtime(stamp)
localdate = time.strftime('%Y-%m-%d %H:%M:%S', date_time)
except:
localdate = None

View file

@ -13,7 +13,6 @@ import xbmcgui
import clientinfo
import downloadutils
import librarysync
import playlist
import userclient
import utils
@ -349,7 +348,8 @@ class WebSocket_Client(threading.Thread):
userId = window('currUserId')
server = window('pms_server')
token = window('pms_token')
# Need to use plex.tv token, if any
token = window('plex_token')
deviceId = self.deviceId
# Get the appropriate prefix for the websocket

View file

@ -48,15 +48,18 @@
</category>
<category label="30506"><!-- Sync Options -->
<setting type="lsep" label="30537" /><!-- Restart if you make changes -->
<setting id="enableBackgroundSync" type="bool" label="39026" default="true" visible="true"/>
<setting id="serverSync" type="bool" label="30514" default="true" visible="false"/><!-- Enable fast startup (requires server plugin) -->
<setting id="syncEmptyShows" type="bool" label="30508" default="false" visible="false"/>
<setting id="dbSyncIndicator" label="30507" type="bool" default="true" />
<setting type="sep" /><!-- show syncing progress -->
<setting id="limitindex" type="number" label="30515" default="200" option="int" /><!-- Maximum items to request from the server at once -->
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Force Artwork Caching -->
<setting id="imageCacheLimit" type="enum" label="30513" values="Disabled|5|10|15|20|25" default="5" visible="eq(-1,true)" subsetting="true" /> <!-- Limit artwork cache threads -->
<setting id="syncThreadNumber" type="slider" label="39003" default="5" option="int" range="1,1,20"/>
<setting id="syncEmptyShows" type="bool" label="30508" default="false" visible="false"/>
<setting id="serverSync" type="bool" label="30514" default="true" visible="false"/><!-- Enable fast startup (requires server plugin) -->
<setting type="lsep" label="39052" /><!-- Background Sync -->
<setting id="enableBackgroundSync" type="bool" label="39026" default="true" visible="true"/>
<setting id="saftyMargin" type="slider" label="39051" default="30" option="int" range="10,1,300" visible="eq(-1,true)"/>
<setting type="lsep" label="30538" /><!-- Complete Re-Sync necessary -->
<setting id="enableMusic" type="bool" label="30509" default="true" />

View file

@ -85,7 +85,8 @@ class Service():
"plex_authenticated", "EmbyUserImage", "useDirectPaths",
"replaceSMB", "remapSMB", "remapSMBmovieOrg", "remapSMBtvOrg",
"remapSMBmusicOrg", "remapSMBmovieNew", "remapSMBtvNew",
"remapSMBmusicNew", "suspend_LibraryThread", "plex_terminateNow"
"remapSMBmusicNew", "suspend_LibraryThread", "plex_terminateNow",
"kodiplextimeoffset"
]
for prop in properties:
window(prop, clear=True)