Cleaned out https checks
- Disabled HTTP certificate warnings in log
This commit is contained in:
parent
9b7774dfc0
commit
2806c8002a
8 changed files with 104 additions and 64 deletions
|
@ -645,7 +645,11 @@ class PlexAPI():
|
||||||
# Ping to check whether we need HTTPs or HTTP
|
# Ping to check whether we need HTTPs or HTTP
|
||||||
url = (self.getPMSProperty(ATV_udid, uuid_id, 'ip') + ':'
|
url = (self.getPMSProperty(ATV_udid, uuid_id, 'ip') + ':'
|
||||||
+ self.getPMSProperty(ATV_udid, uuid_id, 'port'))
|
+ self.getPMSProperty(ATV_udid, uuid_id, 'port'))
|
||||||
if PMSHttpsEnabled(url):
|
https = PMSHttpsEnabled(url)
|
||||||
|
if https is None:
|
||||||
|
# Error contacting url
|
||||||
|
continue
|
||||||
|
elif https:
|
||||||
self.updatePMSProperty(ATV_udid, uuid_id, 'scheme', 'https')
|
self.updatePMSProperty(ATV_udid, uuid_id, 'scheme', 'https')
|
||||||
else:
|
else:
|
||||||
self.updatePMSProperty(ATV_udid, uuid_id, 'scheme', 'http')
|
self.updatePMSProperty(ATV_udid, uuid_id, 'scheme', 'http')
|
||||||
|
|
|
@ -63,22 +63,19 @@ class PlexCompanion(threading.Thread):
|
||||||
message_count = 0
|
message_count = 0
|
||||||
is_running = False
|
is_running = False
|
||||||
while not self.threadStopped():
|
while not self.threadStopped():
|
||||||
while self.threadSuspended():
|
|
||||||
if self.threadStopped():
|
|
||||||
break
|
|
||||||
xbmc.sleep(3000)
|
|
||||||
# If we are not authorized, sleep
|
# If we are not authorized, sleep
|
||||||
# Otherwise, we trigger a download which leads to a
|
# Otherwise, we trigger a download which leads to a
|
||||||
# re-authorizations
|
# re-authorizations
|
||||||
if window('emby_serverStatus'):
|
while self.threadSuspended() or window('emby_serverStatus'):
|
||||||
xbmc.sleep(3000)
|
if self.threadStopped():
|
||||||
continue
|
break
|
||||||
|
xbmc.sleep(1000)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
httpd.handle_request()
|
httpd.handle_request()
|
||||||
message_count += 1
|
message_count += 1
|
||||||
|
|
||||||
if message_count > 30:
|
if message_count > 100:
|
||||||
if self.client.check_client_registration():
|
if self.client.check_client_registration():
|
||||||
self.logMsg("Client is still registered", 1)
|
self.logMsg("Client is still registered", 1)
|
||||||
else:
|
else:
|
||||||
|
@ -96,7 +93,7 @@ class PlexCompanion(threading.Thread):
|
||||||
xbmc.sleep(50)
|
xbmc.sleep(50)
|
||||||
except:
|
except:
|
||||||
self.logMsg("Error in loop, continuing anyway", 1)
|
self.logMsg("Error in loop, continuing anyway", 1)
|
||||||
self.logMsg(traceback.print_exc(), 1)
|
self.logMsg(traceback.format_exc(), 1)
|
||||||
xbmc.sleep(50)
|
xbmc.sleep(50)
|
||||||
|
|
||||||
self.client.stop_all()
|
self.client.stop_all()
|
||||||
|
|
|
@ -4,12 +4,17 @@ from ast import literal_eval
|
||||||
from urlparse import urlparse, parse_qs
|
from urlparse import urlparse, parse_qs
|
||||||
import re
|
import re
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
import requests
|
||||||
|
|
||||||
from xbmcaddon import Addon
|
from xbmcaddon import Addon
|
||||||
|
|
||||||
import downloadutils
|
import downloadutils
|
||||||
from utils import logMsg, settings
|
from utils import logMsg, settings
|
||||||
|
|
||||||
|
# Disable requests logging
|
||||||
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||||
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
|
|
||||||
|
|
||||||
addonName = Addon().getAddonInfo('name')
|
addonName = Addon().getAddonInfo('name')
|
||||||
title = "%s %s" % (addonName, __name__)
|
title = "%s %s" % (addonName, __name__)
|
||||||
|
@ -394,7 +399,8 @@ def getPlexRepeat(kodiRepeat):
|
||||||
|
|
||||||
def PMSHttpsEnabled(url):
|
def PMSHttpsEnabled(url):
|
||||||
"""
|
"""
|
||||||
Returns True if the PMS wants to talk https, False otherwise
|
Returns True if the PMS wants to talk https, False otherwise. None if error
|
||||||
|
occured, e.g. the connection timed out
|
||||||
|
|
||||||
With with e.g. url=192.168.0.1:32400 (NO http/https)
|
With with e.g. url=192.168.0.1:32400 (NO http/https)
|
||||||
|
|
||||||
|
@ -403,17 +409,37 @@ def PMSHttpsEnabled(url):
|
||||||
|
|
||||||
Prefers HTTPS over HTTP
|
Prefers HTTPS over HTTP
|
||||||
"""
|
"""
|
||||||
xml = downloadutils.DownloadUtils().downloadUrl(
|
# True if https, False if http
|
||||||
'https://%s/identity' % url)
|
answer = True
|
||||||
try:
|
try:
|
||||||
# received a valid XML - https connection is possible
|
# Don't use downloadutils here, otherwise we may get un-authorized!
|
||||||
xml.attrib
|
res = requests.get('https://%s/identity' % url,
|
||||||
logMsg('PMSHttpsEnabled', 'PMS on %s talks HTTPS' % url, 1)
|
headers={},
|
||||||
return True
|
verify=False,
|
||||||
except:
|
timeout=(3, 10))
|
||||||
# couldn't get an xml - switch to http traffic
|
# Don't verify SSL since we can connect for sure then!
|
||||||
logMsg('PMSHttpsEnabled', 'PMS on %s talks HTTPS' % url, 1)
|
except requests.exceptions.ConnectionError as e:
|
||||||
return False
|
# Might have SSL deactivated. Try with http
|
||||||
|
try:
|
||||||
|
res = requests.get('http://%s/identity' % 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)
|
||||||
|
return None
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
logMsg("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)
|
||||||
|
return None
|
||||||
|
if res.status_code == requests.codes.ok:
|
||||||
|
return answer
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def scrobble(ratingKey, state):
|
def scrobble(ratingKey, state):
|
||||||
|
|
|
@ -81,13 +81,28 @@ def reConnect():
|
||||||
utils.logMsg("entrypoint reConnect",
|
utils.logMsg("entrypoint reConnect",
|
||||||
"Connection resets requested", 0)
|
"Connection resets requested", 0)
|
||||||
dialog = xbmcgui.Dialog()
|
dialog = xbmcgui.Dialog()
|
||||||
|
# Resetting, please wait
|
||||||
dialog.notification(
|
dialog.notification(
|
||||||
heading=addonName,
|
heading=addonName,
|
||||||
message=string(39207),
|
message=string(39207),
|
||||||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
||||||
|
time=2000,
|
||||||
sound=False)
|
sound=False)
|
||||||
# Pause library sync thread - user needs to be auth in order to sync
|
# Pause library sync thread - user needs to be auth in order to sync
|
||||||
utils.window('suspend_LibraryThread', value='true')
|
utils.window('suspend_LibraryThread', value='true')
|
||||||
|
# Wait max for 5 seconds for all lib scans to finish
|
||||||
|
counter = 0
|
||||||
|
while utils.window('emby_dbScan') == 'true':
|
||||||
|
if counter > 500:
|
||||||
|
# Failed to reset PMS and plex.tv connects. Try to restart Kodi.
|
||||||
|
dialog.ok(heading=addonName,
|
||||||
|
message=string(39208))
|
||||||
|
# Resuming threads, just in case
|
||||||
|
utils.window('suspend_LibraryThread', clear=True)
|
||||||
|
# Abort reConnection
|
||||||
|
return
|
||||||
|
counter += 1
|
||||||
|
xbmc.sleep(50)
|
||||||
|
|
||||||
# Delete plex credentials in settings
|
# Delete plex credentials in settings
|
||||||
utils.settings('myplexlogin', value="true")
|
utils.settings('myplexlogin', value="true")
|
||||||
|
@ -97,18 +112,13 @@ def reConnect():
|
||||||
utils.settings('plexHomeSize', value="1")
|
utils.settings('plexHomeSize', value="1")
|
||||||
utils.settings('plexAvatar', value="")
|
utils.settings('plexAvatar', value="")
|
||||||
|
|
||||||
# Wait max for 5 seconds for all lib scans to finish
|
# Reset connection details
|
||||||
counter = 0
|
utils.settings('plex_machineIdentifier', value="")
|
||||||
while utils.window('emby_dbScan') == 'true':
|
utils.settings('plex_servername', value="")
|
||||||
if counter > 100:
|
utils.settings('https', value="")
|
||||||
dialog.ok(heading=addonName,
|
utils.settings('ipaddress', value="")
|
||||||
message=string(39208))
|
utils.settings('port', value="")
|
||||||
# Resuming threads, just in case
|
|
||||||
utils.window('suspend_LibraryThread', clear=True)
|
|
||||||
# Abort reConnection
|
|
||||||
return
|
|
||||||
counter += 1
|
|
||||||
xbmc.sleep(50)
|
|
||||||
# Log out currently signed in user:
|
# Log out currently signed in user:
|
||||||
utils.window('emby_serverStatus', value="401")
|
utils.window('emby_serverStatus', value="401")
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,7 @@ class LibrarySync(Thread):
|
||||||
updatedAt=self.getPMSfromKodiTime(lastSync),
|
updatedAt=self.getPMSfromKodiTime(lastSync),
|
||||||
containerSize=self.limitindex)
|
containerSize=self.limitindex)
|
||||||
# Just skip if something went wrong
|
# Just skip if something went wrong
|
||||||
if not items:
|
if items is None:
|
||||||
continue
|
continue
|
||||||
# Get one itemtype, because they're the same in the PMS section
|
# Get one itemtype, because they're the same in the PMS section
|
||||||
try:
|
try:
|
||||||
|
@ -528,7 +528,7 @@ class LibrarySync(Thread):
|
||||||
view['id'],
|
view['id'],
|
||||||
lastViewedAt=self.getPMSfromKodiTime(lastSync),
|
lastViewedAt=self.getPMSfromKodiTime(lastSync),
|
||||||
containerSize=self.limitindex)
|
containerSize=self.limitindex)
|
||||||
if not items:
|
if items is None:
|
||||||
continue
|
continue
|
||||||
for item in items:
|
for item in items:
|
||||||
itemId = item.attrib.get('ratingKey')
|
itemId = item.attrib.get('ratingKey')
|
||||||
|
@ -1081,7 +1081,7 @@ class LibrarySync(Thread):
|
||||||
viewName = view['name']
|
viewName = view['name']
|
||||||
all_plexmovies = PlexFunctions.GetPlexSectionResults(
|
all_plexmovies = PlexFunctions.GetPlexSectionResults(
|
||||||
viewId, args=None, containerSize=self.limitindex)
|
viewId, args=None, containerSize=self.limitindex)
|
||||||
if not all_plexmovies:
|
if all_plexmovies is None:
|
||||||
self.logMsg("Couldnt get section items, aborting for view.", 1)
|
self.logMsg("Couldnt get section items, aborting for view.", 1)
|
||||||
continue
|
continue
|
||||||
# Populate self.updatelist and self.allPlexElementsId
|
# Populate self.updatelist and self.allPlexElementsId
|
||||||
|
|
|
@ -32,6 +32,8 @@ import threading
|
||||||
import time
|
import time
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
import xbmc
|
||||||
|
|
||||||
import downloadutils
|
import downloadutils
|
||||||
from PlexFunctions import PMSHttpsEnabled
|
from PlexFunctions import PMSHttpsEnabled
|
||||||
from utils import window
|
from utils import window
|
||||||
|
@ -120,7 +122,7 @@ class plexgdm:
|
||||||
|
|
||||||
self.__printDebug("Sending registration data: HTTP/1.0 200 OK\r\n%s" % (self.client_data), 3)
|
self.__printDebug("Sending registration data: HTTP/1.0 200 OK\r\n%s" % (self.client_data), 3)
|
||||||
self.client_registered = True
|
self.client_registered = True
|
||||||
time.sleep(0.5)
|
xbmc.sleep(500)
|
||||||
|
|
||||||
self.__printDebug("Client Update loop stopped",1)
|
self.__printDebug("Client Update loop stopped",1)
|
||||||
|
|
||||||
|
@ -241,8 +243,12 @@ class plexgdm:
|
||||||
update['class'] = each.split(':')[1].strip()
|
update['class'] = each.split(':')[1].strip()
|
||||||
|
|
||||||
# Quickly test if we need https
|
# Quickly test if we need https
|
||||||
if PMSHttpsEnabled(
|
https = PMSHttpsEnabled(
|
||||||
'%s:%s' % (update['server'], update['port'])):
|
'%s:%s' % (update['server'], update['port']))
|
||||||
|
if https is None:
|
||||||
|
# Error contacting server
|
||||||
|
continue
|
||||||
|
elif https:
|
||||||
update['protocol'] = 'https'
|
update['protocol'] = 'https'
|
||||||
else:
|
else:
|
||||||
update['protocol'] = 'http'
|
update['protocol'] = 'http'
|
||||||
|
@ -321,7 +327,7 @@ class plexgdm:
|
||||||
if discovery_count > self.discovery_interval:
|
if discovery_count > self.discovery_interval:
|
||||||
self.discover()
|
self.discover()
|
||||||
discovery_count=0
|
discovery_count=0
|
||||||
time.sleep(1)
|
xbmc.sleep(1000)
|
||||||
|
|
||||||
def start_discovery(self, daemon = False):
|
def start_discovery(self, daemon = False):
|
||||||
if not self._discovery_is_running:
|
if not self._discovery_is_running:
|
||||||
|
@ -355,8 +361,8 @@ if __name__ == '__main__':
|
||||||
client.start_all()
|
client.start_all()
|
||||||
while not client.discovery_complete:
|
while not client.discovery_complete:
|
||||||
print "Waiting for results"
|
print "Waiting for results"
|
||||||
time.sleep(1)
|
xbmc.sleep(1000)
|
||||||
time.sleep(20)
|
xbmc.sleep(20000)
|
||||||
print client.getServerList()
|
print client.getServerList()
|
||||||
if client.check_client_registration():
|
if client.check_client_registration():
|
||||||
print "Successfully registered"
|
print "Successfully registered"
|
||||||
|
|
|
@ -76,8 +76,8 @@ class UserClient(threading.Thread):
|
||||||
settings = utils.settings
|
settings = utils.settings
|
||||||
|
|
||||||
# Original host
|
# Original host
|
||||||
self.machineIdentifier = utils.settings('plex_machineIdentifier')
|
self.machineIdentifier = settings('plex_machineIdentifier')
|
||||||
self.servername = utils.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')
|
||||||
|
@ -91,13 +91,10 @@ class UserClient(threading.Thread):
|
||||||
# If https is true
|
# If https is true
|
||||||
if prefix and HTTPS:
|
if prefix and HTTPS:
|
||||||
server = "https://%s" % server
|
server = "https://%s" % server
|
||||||
return server
|
|
||||||
# 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
|
||||||
return server
|
self.logMsg('Returning active server: %s' % server)
|
||||||
# If only the host:port is required
|
|
||||||
elif not prefix:
|
|
||||||
return server
|
return server
|
||||||
|
|
||||||
def getSSLverify(self):
|
def getSSLverify(self):
|
||||||
|
@ -410,6 +407,7 @@ class UserClient(threading.Thread):
|
||||||
self.auth = False
|
self.auth = False
|
||||||
if self.authenticate():
|
if self.authenticate():
|
||||||
# Successfully authenticated and loaded a user
|
# Successfully authenticated and loaded a user
|
||||||
|
log("Successfully authenticated!", 1)
|
||||||
log("Current user: %s" % self.currUser, 1)
|
log("Current user: %s" % self.currUser, 1)
|
||||||
log("Current userId: %s" % self.currUserId, 1)
|
log("Current userId: %s" % self.currUserId, 1)
|
||||||
log("Current accessToken: xxxx", 1)
|
log("Current accessToken: xxxx", 1)
|
||||||
|
|
27
service.py
27
service.py
|
@ -135,11 +135,9 @@ class Service():
|
||||||
# 3. User has access to the server
|
# 3. User has access to the server
|
||||||
|
|
||||||
if window('emby_online') == "true":
|
if window('emby_online') == "true":
|
||||||
|
|
||||||
# Emby server is online
|
# Emby server is online
|
||||||
# Verify if user is set and has access to the server
|
# Verify if user is set and has access to the server
|
||||||
if (user.currUser is not None) and user.HasAccess:
|
if (user.currUser is not None) and user.HasAccess:
|
||||||
|
|
||||||
# If an item is playing
|
# If an item is playing
|
||||||
if xplayer.isPlaying():
|
if xplayer.isPlaying():
|
||||||
try:
|
try:
|
||||||
|
@ -189,14 +187,20 @@ class Service():
|
||||||
|
|
||||||
# Start the Websocket Client
|
# Start the Websocket Client
|
||||||
# if not self.websocket_running:
|
# if not self.websocket_running:
|
||||||
|
# log('Starting websocket thread', 1)
|
||||||
# self.websocket_running = True
|
# self.websocket_running = True
|
||||||
# ws.start()
|
# ws.start()
|
||||||
# Start the syncing thread
|
# Start the syncing thread
|
||||||
if not self.library_running:
|
if not self.library_running:
|
||||||
|
log('Starting libary sync thread', 1)
|
||||||
self.library_running = True
|
self.library_running = True
|
||||||
library.start()
|
library.start()
|
||||||
|
# Start the Plex Companion thread
|
||||||
|
if not self.plexCompanion_running and \
|
||||||
|
self.runPlexCompanion == "true":
|
||||||
|
self.plexCompanion_running = True
|
||||||
|
plexCompanion.start()
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if (user.currUser is None) and self.warn_auth:
|
if (user.currUser is None) and self.warn_auth:
|
||||||
# Alert user is not authenticated and suppress future warning
|
# Alert user is not authenticated and suppress future warning
|
||||||
self.warn_auth = False
|
self.warn_auth = False
|
||||||
|
@ -216,6 +220,7 @@ class Service():
|
||||||
if monitor.waitForAbort(5):
|
if monitor.waitForAbort(5):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
break
|
break
|
||||||
|
xbmc.sleep(50)
|
||||||
else:
|
else:
|
||||||
# Wait until Emby server is online
|
# Wait until Emby server is online
|
||||||
# or Kodi is shut down.
|
# or Kodi is shut down.
|
||||||
|
@ -238,9 +243,7 @@ class Service():
|
||||||
icon="special://home/addons/plugin.video."
|
icon="special://home/addons/plugin.video."
|
||||||
"plexkodiconnect/icon.png",
|
"plexkodiconnect/icon.png",
|
||||||
sound=False)
|
sound=False)
|
||||||
|
|
||||||
self.server_online = False
|
self.server_online = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Server is online
|
# Server is online
|
||||||
if not self.server_online:
|
if not self.server_online:
|
||||||
|
@ -257,9 +260,8 @@ class Service():
|
||||||
"plexkodiconnect/icon.png",
|
"plexkodiconnect/icon.png",
|
||||||
time=2000,
|
time=2000,
|
||||||
sound=False)
|
sound=False)
|
||||||
|
|
||||||
self.server_online = True
|
self.server_online = True
|
||||||
log("Server is online and ready.", 1)
|
log("Server %s is online and ready." % server, 1)
|
||||||
window('emby_online', value="true")
|
window('emby_online', value="true")
|
||||||
|
|
||||||
# Start the userclient thread
|
# Start the userclient thread
|
||||||
|
@ -267,17 +269,14 @@ class Service():
|
||||||
self.userclient_running = True
|
self.userclient_running = True
|
||||||
user.start()
|
user.start()
|
||||||
|
|
||||||
# Start the Plex Companion thread
|
|
||||||
if not self.plexCompanion_running and \
|
|
||||||
self.runPlexCompanion == "true":
|
|
||||||
self.plexCompanion_running = True
|
|
||||||
plexCompanion.start()
|
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if monitor.waitForAbort(1):
|
if monitor.waitForAbort(1):
|
||||||
# Abort was requested while waiting.
|
# Abort was requested while waiting.
|
||||||
break
|
break
|
||||||
|
xbmc.sleep(50)
|
||||||
|
|
||||||
if monitor.waitForAbort(1):
|
if monitor.waitForAbort(1):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
|
@ -315,8 +314,8 @@ class Service():
|
||||||
delay = int(utils.settings('startupDelay'))
|
delay = int(utils.settings('startupDelay'))
|
||||||
|
|
||||||
xbmc.log("Delaying Plex startup by: %s sec..." % delay)
|
xbmc.log("Delaying Plex startup by: %s sec..." % delay)
|
||||||
# Plex: add 3 seconds just for good measure
|
# Plex: add 5 seconds just for good measure
|
||||||
if delay and xbmc.Monitor().waitForAbort(delay+3):
|
if delay and xbmc.Monitor().waitForAbort(delay+5):
|
||||||
# Start the service
|
# Start the service
|
||||||
xbmc.log("Abort requested while waiting. Emby for kodi not started.")
|
xbmc.log("Abort requested while waiting. Emby for kodi not started.")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue