Make sure we get the sync lists for the correct server.

Update README
This commit is contained in:
Tim 2015-07-02 17:27:12 +02:00
parent 2aa833d127
commit 55efb0a711
3 changed files with 70 additions and 4 deletions

View file

@ -58,6 +58,7 @@ A python based web front-end for plexWatch.
- public ip address history with last seen date and geo tag location
- recently watched content
- watching history
- synced items
* charts **NOT YET IMPLEMENTED**
- top 10 all time viewed content
@ -71,6 +72,8 @@ A python based web front-end for plexWatch.
- tv seasons
- tv episodes (includes watching history)
* full sync list data on all users syncing items from your library
## Installation and Notes
* [Installation page](../../wiki/Installation) shows you how to install PlexPy.

View file

@ -245,6 +245,39 @@ class PmsConnect(object):
return output
"""
Return the local server identity.
Optional parameters: output_format { dict, json }
Output: array
"""
def get_local_server_identity(self, output_format=''):
url_command = '/identity'
http_handler = HTTPConnection(self.host, self.port, timeout=10)
try:
http_handler.request("GET", url_command + '?X-Plex-Token=' + self.token)
response = http_handler.getresponse()
request_status = response.status
request_content = response.read()
except IOError, e:
logger.warn(u"Failed to access Plex server identity. %s" % e)
return None
if request_status == 200:
if output_format == 'dict':
output = helpers.convert_xml_to_dict(request_content)
elif output_format == 'json':
output = helpers.convert_xml_to_json(request_content)
else:
output = request_content
else:
logger.warn(u"Failed to access Plex server identity. Status code %r" % request_status)
return None
return output
"""
Return processed and validated list of recently added items.
@ -715,9 +748,9 @@ class PmsConnect(object):
return output
"""
Return the local machine identifier.
Return the list of local servers.
Output: string
Output: array
"""
def get_servers_info(self):
recent = self.get_server_list()
@ -749,6 +782,36 @@ class PmsConnect(object):
return server_info
"""
Return the local machine identity.
Output: dict
"""
def get_server_identity(self):
identity = self.get_local_server_identity()
try:
xml_parse = minidom.parseString(identity)
except Exception, e:
logger.warn("Error parsing XML for Plex server identity: %s" % e)
return None
except:
logger.warn("Error parsing XML for Plex server identity.")
return None
xml_head = xml_parse.getElementsByTagName('MediaContainer')
if not xml_head:
logger.warn("Error parsing XML for Plex server identity.")
return None
server_identity = {}
for a in xml_head:
server_identity = {"machine_identifier": self.get_xml_attr(a, 'machineIdentifier'),
"version": self.get_xml_attr(a, 'version')
}
return server_identity
"""
Return image data as array.
Array contains the image content type and image binary

View file

@ -911,11 +911,11 @@ class WebInterface(object):
def get_sync(self, machine_id=None, user_id=None, **kwargs):
pms_connect = pmsconnect.PmsConnect()
server_info = pms_connect.get_servers_info()
server_id = pms_connect.get_server_identity()
plex_tv = plextv.PlexTV()
if not machine_id:
result = plex_tv.get_synced_items(machine_id=server_info[0]['machine_identifier'], user_id=user_id)
result = plex_tv.get_synced_items(machine_id=server_id['machine_identifier'], user_id=user_id)
else:
result = plex_tv.get_synced_items(machine_id=machine_id, user_id=user_id)