Cleanup and Fixes
- Disable SSL warnings, finally - Fix Plex Companion errors due to downloadutils switch
This commit is contained in:
parent
260fc7adf8
commit
1f3598a7c4
12 changed files with 48 additions and 107 deletions
|
@ -33,27 +33,21 @@ import time
|
||||||
import urllib2
|
import urllib2
|
||||||
import socket
|
import socket
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import requests
|
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from urllib import urlencode, quote_plus, unquote
|
from urllib import urlencode, quote_plus, unquote
|
||||||
|
|
||||||
import clientinfo
|
|
||||||
import utils
|
|
||||||
import downloadutils
|
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcvfs
|
import xbmcvfs
|
||||||
|
|
||||||
|
import clientinfo
|
||||||
|
import utils
|
||||||
|
import downloadutils
|
||||||
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
|
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
|
||||||
|
|
||||||
# Disable requests logging
|
|
||||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
|
||||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
|
||||||
|
|
||||||
|
|
||||||
@utils.logging
|
@utils.logging
|
||||||
class PlexAPI():
|
class PlexAPI():
|
||||||
|
@ -258,62 +252,6 @@ class PlexAPI():
|
||||||
self.logMsg('Successfully retrieved code and id from plex.tv', 1)
|
self.logMsg('Successfully retrieved code and id from plex.tv', 1)
|
||||||
return code, identifier
|
return code, identifier
|
||||||
|
|
||||||
def TalkToPlexServer(self, url, talkType="GET", verify=True, token=None):
|
|
||||||
"""
|
|
||||||
Start request with PMS with url.
|
|
||||||
|
|
||||||
Returns the parsed XML answer as an etree object.
|
|
||||||
False if the server could not be reached/timeout occured.
|
|
||||||
False if HTTP error code of >=400 was returned.
|
|
||||||
"""
|
|
||||||
header = self.getXArgsDeviceInfo()
|
|
||||||
if token:
|
|
||||||
header['X-Plex-Token'] = token
|
|
||||||
timeout = (3, 10)
|
|
||||||
try:
|
|
||||||
if talkType == "GET":
|
|
||||||
answer = requests.get(url,
|
|
||||||
headers={},
|
|
||||||
params=header,
|
|
||||||
verify=verify,
|
|
||||||
timeout=timeout)
|
|
||||||
# Only seems to be used for initial plex.tv sign in
|
|
||||||
if talkType == "GET2":
|
|
||||||
answer = requests.get(url,
|
|
||||||
headers=header,
|
|
||||||
params={},
|
|
||||||
verify=verify,
|
|
||||||
timeout=timeout)
|
|
||||||
elif talkType == "POST":
|
|
||||||
answer = requests.post(url,
|
|
||||||
data='',
|
|
||||||
headers=header,
|
|
||||||
params={},
|
|
||||||
verify=verify,
|
|
||||||
timeout=timeout)
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
|
||||||
self.logMsg("Server is offline or cannot be reached. Url: %s. "
|
|
||||||
"Error message: %s"
|
|
||||||
% (url, e), -1)
|
|
||||||
return False
|
|
||||||
except requests.exceptions.ReadTimeout:
|
|
||||||
self.logMsg("Server timeout reached for Url %s"
|
|
||||||
% url, -1)
|
|
||||||
return False
|
|
||||||
# We received an answer from the server, but not as expected.
|
|
||||||
if answer.status_code >= 400:
|
|
||||||
self.logMsg("Error, answer from server %s was not as expected. "
|
|
||||||
"HTTP status code: %s" % (url, answer.status_code), -1)
|
|
||||||
return False
|
|
||||||
xml = answer.text.encode('utf-8')
|
|
||||||
self.logMsg("xml received from server %s: %s" % (url, xml), 2)
|
|
||||||
try:
|
|
||||||
xml = etree.fromstring(xml)
|
|
||||||
except:
|
|
||||||
self.logMsg("Error parsing XML answer from %s" % url, -1)
|
|
||||||
return False
|
|
||||||
return xml
|
|
||||||
|
|
||||||
def CheckConnection(self, url, token=None, verifySSL=None):
|
def CheckConnection(self, url, token=None, verifySSL=None):
|
||||||
"""
|
"""
|
||||||
Checks connection to a Plex server, available at url. Can also be used
|
Checks connection to a Plex server, available at url. Can also be used
|
||||||
|
|
|
@ -4,19 +4,12 @@ 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
|
|
||||||
|
|
||||||
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 = 'PlexKodiConnect'
|
||||||
addonName = Addon().getAddonInfo('name')
|
|
||||||
title = "%s %s" % (addonName, __name__)
|
title = "%s %s" % (addonName, __name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@ import xbmcvfs
|
||||||
import utils
|
import utils
|
||||||
import image_cache_thread
|
import image_cache_thread
|
||||||
|
|
||||||
# Disable requests logging
|
# Disable annoying requests warnings
|
||||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
import requests.packages.urllib3
|
||||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,9 @@ import clientinfo
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Disable requests logging
|
# Disable annoying requests warnings
|
||||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
import requests.packages.urllib3
|
||||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings()
|
||||||
# logging.getLogger('requests').setLevel(logging.WARNING)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -263,10 +262,18 @@ class DownloadUtils():
|
||||||
r = r.json()
|
r = r.json()
|
||||||
return r
|
return r
|
||||||
except:
|
except:
|
||||||
self.logMsg("Unable to convert the response for: %s"
|
r.encoding = 'utf-8'
|
||||||
% url, -1)
|
if '200 OK' in r.text:
|
||||||
self.logMsg("Received headers were: %s" % r.headers, -1)
|
# Received fucked up OK from PMS on playstate update
|
||||||
return False
|
pass
|
||||||
|
else:
|
||||||
|
self.logMsg("Unable to convert the response for: %s"
|
||||||
|
% url, -1)
|
||||||
|
self.logMsg("Received headers were: %s"
|
||||||
|
% r.headers, -1)
|
||||||
|
self.logMsg('Received text:', -1)
|
||||||
|
self.logMsg(r.text, -1)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self.logMsg('Unknown answer from PMS %s with status code %s. '
|
self.logMsg('Unknown answer from PMS %s with status code %s. '
|
||||||
'Message:' % (url, r.status_code), -1)
|
'Message:' % (url, r.status_code), -1)
|
||||||
|
|
|
@ -28,14 +28,12 @@ import PlexAPI
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# For logging only
|
# For logging only
|
||||||
addonName = clientinfo.ClientInfo().getAddonName()
|
addonName = 'PlexKodiConnect'
|
||||||
title = "%s %s" % (addonName, __name__)
|
title = "%s %s" % (addonName, __name__)
|
||||||
|
|
||||||
|
|
||||||
def plexCompanion(fullurl, params):
|
def plexCompanion(fullurl, params):
|
||||||
params = PlexFunctions.LiteralEval(params[26:])
|
params = PlexFunctions.LiteralEval(params[26:])
|
||||||
utils.logMsg("entrypoint - plexCompanion",
|
|
||||||
"params is: %s" % params, -1)
|
|
||||||
|
|
||||||
if (params['machineIdentifier'] !=
|
if (params['machineIdentifier'] !=
|
||||||
utils.window('plex_machineIdentifier')):
|
utils.window('plex_machineIdentifier')):
|
||||||
|
|
|
@ -3,9 +3,9 @@ import utils
|
||||||
import xbmc
|
import xbmc
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Disable requests logging
|
# Disable annoying requests warnings
|
||||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
import requests.packages.urllib3
|
||||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
@utils.logging
|
@utils.logging
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcaddon
|
|
||||||
import xbmcvfs
|
import xbmcvfs
|
||||||
|
|
||||||
from mutagen.flac import FLAC, Picture
|
from mutagen.flac import FLAC
|
||||||
from mutagen.id3 import ID3
|
from mutagen.id3 import ID3
|
||||||
from mutagen import id3
|
from mutagen import id3
|
||||||
import base64
|
|
||||||
|
|
||||||
import read_embyserver as embyserver
|
import read_embyserver as embyserver
|
||||||
import utils
|
import utils
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
|
||||||
from utils import logging
|
from utils import logging
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ def plex_type(xbmc_type):
|
||||||
|
|
||||||
|
|
||||||
def getXMLHeader():
|
def getXMLHeader():
|
||||||
return '<?xml version="1.0" encoding="utf-8" ?>'+"\r\n"
|
return '<?xml version="1.0" encoding="utf-8" ?>\r\n'
|
||||||
|
|
||||||
|
|
||||||
def getOKMsg():
|
def getOKMsg():
|
||||||
|
@ -131,7 +133,7 @@ class jsonClass():
|
||||||
"X-Plex-Product": "PlexKodiConnect",
|
"X-Plex-Product": "PlexKodiConnect",
|
||||||
"X-Plex-Device-Name": self.settings['client_name'],
|
"X-Plex-Device-Name": self.settings['client_name'],
|
||||||
"X-Plex-Platform": "Kodi",
|
"X-Plex-Platform": "Kodi",
|
||||||
"X-Plex-Model": getPlatform(),
|
"X-Plex-Model": self.settings['platform'],
|
||||||
"X-Plex-Device": "PC",
|
"X-Plex-Device": "PC",
|
||||||
}
|
}
|
||||||
if self.settings['myplex_user']:
|
if self.settings['myplex_user']:
|
||||||
|
|
|
@ -3,6 +3,7 @@ import traceback
|
||||||
import string
|
import string
|
||||||
import errno
|
import errno
|
||||||
from socket import error as socket_error
|
from socket import error as socket_error
|
||||||
|
|
||||||
from utils import logging
|
from utils import logging
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
|
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
|
||||||
self.serverlist = []
|
self.serverlist = []
|
||||||
self.settings = self.server.settings
|
|
||||||
|
|
||||||
def getServerByHost(self, host):
|
def getServerByHost(self, host):
|
||||||
if len(self.serverlist) == 1:
|
if len(self.serverlist) == 1:
|
||||||
|
@ -39,7 +38,7 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
def do_OPTIONS(s):
|
def do_OPTIONS(s):
|
||||||
s.send_response(200)
|
s.send_response(200)
|
||||||
s.send_header('Content-Length', '0')
|
s.send_header('Content-Length', '0')
|
||||||
s.send_header('X-Plex-Client-Identifier', s.settings['uuid'])
|
s.send_header('X-Plex-Client-Identifier', s.server.settings['uuid'])
|
||||||
s.send_header('Content-Type', 'text/plain')
|
s.send_header('Content-Type', 'text/plain')
|
||||||
s.send_header('Connection', 'close')
|
s.send_header('Connection', 'close')
|
||||||
s.send_header('Access-Control-Max-Age', '1209600')
|
s.send_header('Access-Control-Max-Age', '1209600')
|
||||||
|
@ -71,6 +70,8 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
s.serverlist = s.server.client.getServerList()
|
s.serverlist = s.server.client.getServerList()
|
||||||
s.subMgr = s.server.subscriptionManager
|
s.subMgr = s.server.subscriptionManager
|
||||||
s.js = s.server.jsonClass
|
s.js = s.server.jsonClass
|
||||||
|
s.settings = s.server.settings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request_path = s.path[1:]
|
request_path = s.path[1:]
|
||||||
request_path = re.sub(r"\?.*", "", request_path)
|
request_path = re.sub(r"\?.*", "", request_path)
|
||||||
|
@ -97,7 +98,7 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
resp += ' protocolCapabilities="navigation,playback,timeline"'
|
resp += ' protocolCapabilities="navigation,playback,timeline"'
|
||||||
resp += ' machineIdentifier="%s"' % s.settings['uuid']
|
resp += ' machineIdentifier="%s"' % s.settings['uuid']
|
||||||
resp += ' product="PlexKodiConnect"'
|
resp += ' product="PlexKodiConnect"'
|
||||||
resp += ' platform="%s"' % getPlatform()
|
resp += ' platform="%s"' % s.settings['platform']
|
||||||
resp += ' platformVersion="%s"' % s.settings['plexbmc_version']
|
resp += ' platformVersion="%s"' % s.settings['plexbmc_version']
|
||||||
resp += ' deviceClass="pc"'
|
resp += ' deviceClass="pc"'
|
||||||
resp += "/>"
|
resp += "/>"
|
||||||
|
@ -215,8 +216,10 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
elif request_path == "player/navigation/back":
|
elif request_path == "player/navigation/back":
|
||||||
s.response(getOKMsg(), s.js.getPlexHeaders())
|
s.response(getOKMsg(), s.js.getPlexHeaders())
|
||||||
s.js.jsonrpc("Input.Back")
|
s.js.jsonrpc("Input.Back")
|
||||||
|
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
s.logMsg('Error encountered. Traceback:', -1)
|
||||||
|
s.logMsg(traceback.print_exc(), -1)
|
||||||
|
|
||||||
|
|
||||||
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
from functions import *
|
|
||||||
|
|
||||||
from xbmc import Player
|
from xbmc import Player
|
||||||
|
|
||||||
import downloadutils
|
import downloadutils
|
||||||
from utils import window, logging
|
from utils import window, logging
|
||||||
import PlexFunctions as pf
|
import PlexFunctions as pf
|
||||||
|
from functions import *
|
||||||
|
|
||||||
|
|
||||||
@logging
|
@logging
|
||||||
|
@ -23,7 +24,7 @@ class SubscriptionManager:
|
||||||
self.protocol = "http"
|
self.protocol = "http"
|
||||||
self.port = ""
|
self.port = ""
|
||||||
self.playerprops = {}
|
self.playerprops = {}
|
||||||
self.download = downloadutils.DownloadUtils()
|
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
||||||
self.xbmcplayer = Player()
|
self.xbmcplayer = Player()
|
||||||
|
|
||||||
self.js = jsonClass
|
self.js = jsonClass
|
||||||
|
@ -167,7 +168,7 @@ class SubscriptionManager:
|
||||||
url = serv.get('protocol', 'http') + '://' \
|
url = serv.get('protocol', 'http') + '://' \
|
||||||
+ serv.get('server', 'localhost') + ':' \
|
+ serv.get('server', 'localhost') + ':' \
|
||||||
+ serv.get('port', '32400') + "/:/timeline"
|
+ serv.get('port', '32400') + "/:/timeline"
|
||||||
self.download.downloadUrl(url, type="GET", parameters=params)
|
self.doUtils(url, type="GET", parameters=params)
|
||||||
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
|
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
|
||||||
self.logMsg("params: %s" % params, 2)
|
self.logMsg("params: %s" % params, 2)
|
||||||
self.logMsg("players: %s" % players, 2)
|
self.logMsg("players: %s" % players, 2)
|
||||||
|
@ -244,7 +245,7 @@ class Subscriber:
|
||||||
self.commandID = int(commandID) or 0
|
self.commandID = int(commandID) or 0
|
||||||
self.navlocationsent = False
|
self.navlocationsent = False
|
||||||
self.age = 0
|
self.age = 0
|
||||||
self.download = downloadutils.DownloadUtils()
|
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
||||||
self.subMgr = subMgr
|
self.subMgr = subMgr
|
||||||
self.RequestMgr = RequestMgr
|
self.RequestMgr = RequestMgr
|
||||||
|
|
||||||
|
@ -278,8 +279,8 @@ class Subscriber:
|
||||||
Threaded POST request, because they stall due to PMS response missing
|
Threaded POST request, because they stall due to PMS response missing
|
||||||
the Content-Length header :-(
|
the Content-Length header :-(
|
||||||
"""
|
"""
|
||||||
response = self.download.downloadUrl(url,
|
response = self.doUtils(url,
|
||||||
postBody=msg,
|
postBody=msg,
|
||||||
type="POST")
|
type="POST")
|
||||||
if response in [False, None, 401]:
|
if response in [False, None, 401]:
|
||||||
self.subMgr.removeSubscriber(self.uuid)
|
self.subMgr.removeSubscriber(self.uuid)
|
||||||
|
|
|
@ -23,7 +23,7 @@ import xbmcvfs
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
addonName = xbmcaddon.Addon().getAddonInfo('name')
|
addonName = 'PlexKodiConnect'
|
||||||
|
|
||||||
|
|
||||||
def DateToKodi(stamp):
|
def DateToKodi(stamp):
|
||||||
|
|
Loading…
Reference in a new issue