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 socket
|
||||
from threading import Thread
|
||||
import requests
|
||||
import xml.etree.ElementTree as etree
|
||||
|
||||
import re
|
||||
import json
|
||||
from urllib import urlencode, quote_plus, unquote
|
||||
|
||||
import clientinfo
|
||||
import utils
|
||||
import downloadutils
|
||||
import xbmcaddon
|
||||
import xbmcgui
|
||||
import xbmc
|
||||
import xbmcvfs
|
||||
|
||||
import clientinfo
|
||||
import utils
|
||||
import downloadutils
|
||||
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
|
||||
|
||||
# Disable requests logging
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
|
||||
|
||||
@utils.logging
|
||||
class PlexAPI():
|
||||
|
@ -258,62 +252,6 @@ class PlexAPI():
|
|||
self.logMsg('Successfully retrieved code and id from plex.tv', 1)
|
||||
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):
|
||||
"""
|
||||
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
|
||||
import re
|
||||
from copy import deepcopy
|
||||
import requests
|
||||
|
||||
from xbmcaddon import Addon
|
||||
|
||||
import downloadutils
|
||||
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 = 'PlexKodiConnect'
|
||||
title = "%s %s" % (addonName, __name__)
|
||||
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@ import xbmcvfs
|
|||
import utils
|
||||
import image_cache_thread
|
||||
|
||||
# Disable requests logging
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
# Disable annoying requests warnings
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
|
|
@ -10,10 +10,9 @@ import clientinfo
|
|||
|
||||
###############################################################################
|
||||
|
||||
# Disable requests logging
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
# logging.getLogger('requests').setLevel(logging.WARNING)
|
||||
# Disable annoying requests warnings
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
@ -263,10 +262,18 @@ class DownloadUtils():
|
|||
r = r.json()
|
||||
return r
|
||||
except:
|
||||
r.encoding = 'utf-8'
|
||||
if '200 OK' in r.text:
|
||||
# Received fucked up OK from PMS on playstate update
|
||||
pass
|
||||
else:
|
||||
self.logMsg("Unable to convert the response for: %s"
|
||||
% url, -1)
|
||||
self.logMsg("Received headers were: %s" % r.headers, -1)
|
||||
return False
|
||||
self.logMsg("Received headers were: %s"
|
||||
% r.headers, -1)
|
||||
self.logMsg('Received text:', -1)
|
||||
self.logMsg(r.text, -1)
|
||||
return True
|
||||
else:
|
||||
self.logMsg('Unknown answer from PMS %s with status code %s. '
|
||||
'Message:' % (url, r.status_code), -1)
|
||||
|
|
|
@ -28,14 +28,12 @@ import PlexAPI
|
|||
###############################################################################
|
||||
|
||||
# For logging only
|
||||
addonName = clientinfo.ClientInfo().getAddonName()
|
||||
addonName = 'PlexKodiConnect'
|
||||
title = "%s %s" % (addonName, __name__)
|
||||
|
||||
|
||||
def plexCompanion(fullurl, params):
|
||||
params = PlexFunctions.LiteralEval(params[26:])
|
||||
utils.logMsg("entrypoint - plexCompanion",
|
||||
"params is: %s" % params, -1)
|
||||
|
||||
if (params['machineIdentifier'] !=
|
||||
utils.window('plex_machineIdentifier')):
|
||||
|
|
|
@ -3,9 +3,9 @@ import utils
|
|||
import xbmc
|
||||
import requests
|
||||
|
||||
# Disable requests logging
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
# Disable annoying requests warnings
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
@utils.logging
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
import os
|
||||
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
import xbmcvfs
|
||||
|
||||
from mutagen.flac import FLAC, Picture
|
||||
from mutagen.flac import FLAC
|
||||
from mutagen.id3 import ID3
|
||||
from mutagen import id3
|
||||
import base64
|
||||
|
||||
import read_embyserver as embyserver
|
||||
import utils
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import base64
|
||||
import json
|
||||
import string
|
||||
|
||||
import xbmc
|
||||
|
||||
from utils import logging
|
||||
|
||||
|
||||
|
@ -48,7 +50,7 @@ def plex_type(xbmc_type):
|
|||
|
||||
|
||||
def getXMLHeader():
|
||||
return '<?xml version="1.0" encoding="utf-8" ?>'+"\r\n"
|
||||
return '<?xml version="1.0" encoding="utf-8" ?>\r\n'
|
||||
|
||||
|
||||
def getOKMsg():
|
||||
|
@ -131,7 +133,7 @@ class jsonClass():
|
|||
"X-Plex-Product": "PlexKodiConnect",
|
||||
"X-Plex-Device-Name": self.settings['client_name'],
|
||||
"X-Plex-Platform": "Kodi",
|
||||
"X-Plex-Model": getPlatform(),
|
||||
"X-Plex-Model": self.settings['platform'],
|
||||
"X-Plex-Device": "PC",
|
||||
}
|
||||
if self.settings['myplex_user']:
|
||||
|
|
|
@ -3,6 +3,7 @@ import traceback
|
|||
import string
|
||||
import errno
|
||||
from socket import error as socket_error
|
||||
|
||||
from utils import logging
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||
def __init__(self, *args, **kwargs):
|
||||
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
|
||||
self.serverlist = []
|
||||
self.settings = self.server.settings
|
||||
|
||||
def getServerByHost(self, host):
|
||||
if len(self.serverlist) == 1:
|
||||
|
@ -39,7 +38,7 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||
def do_OPTIONS(s):
|
||||
s.send_response(200)
|
||||
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('Connection', 'close')
|
||||
s.send_header('Access-Control-Max-Age', '1209600')
|
||||
|
@ -71,6 +70,8 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||
s.serverlist = s.server.client.getServerList()
|
||||
s.subMgr = s.server.subscriptionManager
|
||||
s.js = s.server.jsonClass
|
||||
s.settings = s.server.settings
|
||||
|
||||
try:
|
||||
request_path = s.path[1:]
|
||||
request_path = re.sub(r"\?.*", "", request_path)
|
||||
|
@ -97,7 +98,7 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||
resp += ' protocolCapabilities="navigation,playback,timeline"'
|
||||
resp += ' machineIdentifier="%s"' % s.settings['uuid']
|
||||
resp += ' product="PlexKodiConnect"'
|
||||
resp += ' platform="%s"' % getPlatform()
|
||||
resp += ' platform="%s"' % s.settings['platform']
|
||||
resp += ' platformVersion="%s"' % s.settings['plexbmc_version']
|
||||
resp += ' deviceClass="pc"'
|
||||
resp += "/>"
|
||||
|
@ -215,8 +216,10 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||
elif request_path == "player/navigation/back":
|
||||
s.response(getOKMsg(), s.js.getPlexHeaders())
|
||||
s.js.jsonrpc("Input.Back")
|
||||
|
||||
except:
|
||||
traceback.print_exc()
|
||||
s.logMsg('Error encountered. Traceback:', -1)
|
||||
s.logMsg(traceback.print_exc(), -1)
|
||||
|
||||
|
||||
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import re
|
||||
import threading
|
||||
from functions import *
|
||||
|
||||
from xbmc import Player
|
||||
|
||||
import downloadutils
|
||||
from utils import window, logging
|
||||
import PlexFunctions as pf
|
||||
from functions import *
|
||||
|
||||
|
||||
@logging
|
||||
|
@ -23,7 +24,7 @@ class SubscriptionManager:
|
|||
self.protocol = "http"
|
||||
self.port = ""
|
||||
self.playerprops = {}
|
||||
self.download = downloadutils.DownloadUtils()
|
||||
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
||||
self.xbmcplayer = Player()
|
||||
|
||||
self.js = jsonClass
|
||||
|
@ -167,7 +168,7 @@ class SubscriptionManager:
|
|||
url = serv.get('protocol', 'http') + '://' \
|
||||
+ serv.get('server', 'localhost') + ':' \
|
||||
+ 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'))
|
||||
self.logMsg("params: %s" % params, 2)
|
||||
self.logMsg("players: %s" % players, 2)
|
||||
|
@ -244,7 +245,7 @@ class Subscriber:
|
|||
self.commandID = int(commandID) or 0
|
||||
self.navlocationsent = False
|
||||
self.age = 0
|
||||
self.download = downloadutils.DownloadUtils()
|
||||
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
||||
self.subMgr = subMgr
|
||||
self.RequestMgr = RequestMgr
|
||||
|
||||
|
@ -278,7 +279,7 @@ class Subscriber:
|
|||
Threaded POST request, because they stall due to PMS response missing
|
||||
the Content-Length header :-(
|
||||
"""
|
||||
response = self.download.downloadUrl(url,
|
||||
response = self.doUtils(url,
|
||||
postBody=msg,
|
||||
type="POST")
|
||||
if response in [False, None, 401]:
|
||||
|
|
|
@ -23,7 +23,7 @@ import xbmcvfs
|
|||
|
||||
###############################################################################
|
||||
|
||||
addonName = xbmcaddon.Addon().getAddonInfo('name')
|
||||
addonName = 'PlexKodiConnect'
|
||||
|
||||
|
||||
def DateToKodi(stamp):
|
||||
|
|
Loading…
Reference in a new issue