Get a machineIdentifier if it is missing
- E.g. when PMS IP was entered manually
This commit is contained in:
parent
bca89c3a9a
commit
5d2dbaaf1e
2 changed files with 34 additions and 7 deletions
|
@ -383,7 +383,7 @@ def GetPlexPlaylist(itemid, librarySectionUUID, mediatype='movie'):
|
||||||
try:
|
try:
|
||||||
xml[0].tag
|
xml[0].tag
|
||||||
except (IndexError, TypeError, AttributeError):
|
except (IndexError, TypeError, AttributeError):
|
||||||
logMsg("Error retrieving metadata for %s" % url, -1)
|
logMsg(title, "Error retrieving metadata for %s" % url, -1)
|
||||||
return None
|
return None
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
@ -425,16 +425,16 @@ def PMSHttpsEnabled(url):
|
||||||
headers={},
|
headers={},
|
||||||
timeout=(3, 10))
|
timeout=(3, 10))
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
logMsg("Server is offline or cannot be reached. Url: %s, "
|
logMsg(title, "Server is offline or cannot be reached. Url: %s"
|
||||||
"Error message: %s" % (url, e), -1)
|
", Error message: %s" % (url, e), -1)
|
||||||
return None
|
return None
|
||||||
except requests.exceptions.ReadTimeout:
|
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
|
return None
|
||||||
else:
|
else:
|
||||||
answer = False
|
answer = False
|
||||||
except requests.exceptions.ReadTimeout:
|
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
|
return None
|
||||||
if res.status_code == requests.codes.ok:
|
if res.status_code == requests.codes.ok:
|
||||||
return answer
|
return answer
|
||||||
|
@ -442,6 +442,26 @@ def PMSHttpsEnabled(url):
|
||||||
return None
|
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):
|
def scrobble(ratingKey, state):
|
||||||
"""
|
"""
|
||||||
Tells the PMS to set an item's watched state to state="watched" or
|
Tells the PMS to set an item's watched state to state="watched" or
|
||||||
|
@ -458,4 +478,4 @@ def scrobble(ratingKey, state):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
downloadutils.DownloadUtils().downloadUrl(url, type="GET")
|
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)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import utils
|
||||||
import downloadutils
|
import downloadutils
|
||||||
|
|
||||||
import PlexAPI
|
import PlexAPI
|
||||||
|
from PlexFunctions import GetMachineIdentifier
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -76,11 +77,11 @@ class UserClient(threading.Thread):
|
||||||
settings = utils.settings
|
settings = utils.settings
|
||||||
|
|
||||||
# Original host
|
# Original host
|
||||||
self.machineIdentifier = settings('plex_machineIdentifier')
|
|
||||||
self.servername = settings('plex_servername')
|
self.servername = settings('plex_servername')
|
||||||
HTTPS = settings('https') == "true"
|
HTTPS = settings('https') == "true"
|
||||||
host = settings('ipaddress')
|
host = settings('ipaddress')
|
||||||
port = settings('port')
|
port = settings('port')
|
||||||
|
self.machineIdentifier = settings('plex_machineIdentifier')
|
||||||
|
|
||||||
server = host + ":" + port
|
server = host + ":" + port
|
||||||
|
|
||||||
|
@ -94,6 +95,12 @@ class UserClient(threading.Thread):
|
||||||
# If https is false
|
# If https is false
|
||||||
elif prefix and not HTTPS:
|
elif prefix and not HTTPS:
|
||||||
server = "http://%s" % server
|
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)
|
self.logMsg('Returning active server: %s' % server)
|
||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue