Get a machineIdentifier if it is missing

- E.g. when PMS IP was entered manually
This commit is contained in:
tomkat83 2016-03-24 09:08:58 +01:00
parent bca89c3a9a
commit 5d2dbaaf1e
2 changed files with 34 additions and 7 deletions

View file

@ -383,7 +383,7 @@ def GetPlexPlaylist(itemid, librarySectionUUID, mediatype='movie'):
try:
xml[0].tag
except (IndexError, TypeError, AttributeError):
logMsg("Error retrieving metadata for %s" % url, -1)
logMsg(title, "Error retrieving metadata for %s" % url, -1)
return None
return xml
@ -425,16 +425,16 @@ def PMSHttpsEnabled(url):
headers={},
timeout=(3, 10))
except requests.exceptions.ConnectionError as e:
logMsg("Server is offline or cannot be reached. Url: %s, "
"Error message: %s" % (url, e), -1)
logMsg(title, "Server is offline or cannot be reached. Url: %s"
", Error message: %s" % (url, e), -1)
return None
except requests.exceptions.ReadTimeout:
logMsg("Server timeout reached for Url %s" % url, -1)
logMsg(title, "Server timeout reached for Url %s" % url, -1)
return None
else:
answer = False
except requests.exceptions.ReadTimeout:
logMsg("Server timeout reached for Url %s" % url, -1)
logMsg(title, "Server timeout reached for Url %s" % url, -1)
return None
if res.status_code == requests.codes.ok:
return answer
@ -442,6 +442,26 @@ def PMSHttpsEnabled(url):
return None
def GetMachineIdentifier(url):
"""
Returns the unique PMS machine identifier of url
Returns None if something went wrong
"""
xml = downloadutils.DownloadUtils().downloadUrl(
url + '/identity', type="GET")
try:
xml.attrib
except:
logMsg(title, 'Could not get the PMS machineIdentifier for %s'
% url, -1)
return None
machineIdentifier = xml.attrib.get('machineIdentifier')
logMsg(title, 'Found machineIdentifier %s for %s'
% (machineIdentifier, url), 1)
return machineIdentifier
def scrobble(ratingKey, state):
"""
Tells the PMS to set an item's watched state to state="watched" or
@ -458,4 +478,4 @@ def scrobble(ratingKey, state):
else:
return
downloadutils.DownloadUtils().downloadUrl(url, type="GET")
logMsg("Toggled watched state for Plex item %s" % ratingKey, 1)
logMsg(title, "Toggled watched state for Plex item %s" % ratingKey, 1)

View file

@ -13,6 +13,7 @@ import utils
import downloadutils
import PlexAPI
from PlexFunctions import GetMachineIdentifier
###############################################################################
@ -76,11 +77,11 @@ class UserClient(threading.Thread):
settings = utils.settings
# Original host
self.machineIdentifier = settings('plex_machineIdentifier')
self.servername = settings('plex_servername')
HTTPS = settings('https') == "true"
host = settings('ipaddress')
port = settings('port')
self.machineIdentifier = settings('plex_machineIdentifier')
server = host + ":" + port
@ -94,6 +95,12 @@ class UserClient(threading.Thread):
# If https is false
elif prefix and not HTTPS:
server = "http://%s" % server
# User entered IP; we need to get the machineIdentifier
if self.machineIdentifier == '' and prefix is True:
self.machineIdentifier = GetMachineIdentifier(server)
if self.machineIdentifier is None:
self.machineIdentifier = ''
settings('plex_machineIdentifier', value=self.machineIdentifier)
self.logMsg('Returning active server: %s' % server)
return server