2015-12-25 06:54:34 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##################################################################################################
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
import json
|
2015-12-25 06:54:34 +11:00
|
|
|
import requests
|
2015-04-22 07:34:56 +10:00
|
|
|
import logging
|
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
|
|
|
|
import utils
|
|
|
|
import clientinfo
|
|
|
|
|
|
|
|
##################################################################################################
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
# Disable requests logging
|
2015-12-25 06:54:34 +11:00
|
|
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
2015-05-27 13:42:14 +10:00
|
|
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
2015-12-25 06:54:34 +11:00
|
|
|
#logging.getLogger('requests').setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
##################################################################################################
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
class DownloadUtils():
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
# Borg - multiple instances, shared state
|
|
|
|
_shared_state = {}
|
2015-12-25 06:54:34 +11:00
|
|
|
clientInfo = clientinfo.ClientInfo()
|
2015-04-22 07:34:56 +10:00
|
|
|
addonName = clientInfo.getAddonName()
|
2015-04-03 21:13:01 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
# Requests session
|
|
|
|
s = None
|
2015-12-25 06:54:34 +11:00
|
|
|
timeout = 30
|
|
|
|
|
2015-03-22 21:58:02 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def __init__(self):
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
self.__dict__ = self._shared_state
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def logMsg(self, msg, lvl=1):
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
className = self.__class__.__name__
|
|
|
|
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def setUsername(self, username):
|
2015-12-25 06:54:34 +11:00
|
|
|
# Reserved for userclient only
|
2015-04-22 07:34:56 +10:00
|
|
|
self.username = username
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("Set username: %s" % username, 2)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def setUserId(self, userId):
|
2015-12-25 06:54:34 +11:00
|
|
|
# Reserved for userclient only
|
2015-04-22 07:34:56 +10:00
|
|
|
self.userId = userId
|
|
|
|
self.logMsg("Set userId: %s" % userId, 2)
|
|
|
|
|
|
|
|
def setServer(self, server):
|
2015-12-25 06:54:34 +11:00
|
|
|
# Reserved for userclient only
|
2015-04-22 07:34:56 +10:00
|
|
|
self.server = server
|
|
|
|
self.logMsg("Set server: %s" % server, 2)
|
|
|
|
|
|
|
|
def setToken(self, token):
|
2015-12-25 06:54:34 +11:00
|
|
|
# Reserved for userclient only
|
2015-04-22 07:34:56 +10:00
|
|
|
self.token = token
|
|
|
|
self.logMsg("Set token: %s" % token, 2)
|
|
|
|
|
2015-04-25 11:57:04 +10:00
|
|
|
def setSSL(self, ssl, sslclient):
|
2015-12-25 06:54:34 +11:00
|
|
|
# Reserved for userclient only
|
2015-04-25 11:57:04 +10:00
|
|
|
self.sslverify = ssl
|
|
|
|
self.sslclient = sslclient
|
|
|
|
self.logMsg("Verify SSL host certificate: %s" % ssl, 2)
|
|
|
|
self.logMsg("SSL client side certificate: %s" % sslclient, 2)
|
2015-04-24 20:17:08 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def postCapabilities(self, deviceId):
|
|
|
|
|
2015-05-03 12:28:24 +10:00
|
|
|
# Post settings to session
|
2015-12-25 06:54:34 +11:00
|
|
|
url = "{server}/emby/Sessions/Capabilities/Full?format=json"
|
2015-05-03 12:28:24 +10:00
|
|
|
data = {
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-05-03 12:28:24 +10:00
|
|
|
'PlayableMediaTypes': "Audio,Video",
|
2015-05-16 16:31:08 +10:00
|
|
|
'SupportsMediaControl': True,
|
|
|
|
'SupportedCommands': (
|
|
|
|
|
|
|
|
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
|
|
|
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
|
|
|
"GoHome,PageUp,NextLetter,GoToSearch,"
|
|
|
|
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
|
|
|
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
2015-08-06 14:30:33 +10:00
|
|
|
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
2015-05-16 16:31:08 +10:00
|
|
|
|
|
|
|
"Mute,Unmute,SetVolume,"
|
|
|
|
"Play,Playstate,PlayNext"
|
|
|
|
)
|
2015-05-03 12:28:24 +10:00
|
|
|
}
|
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
self.logMsg("Capabilities URL: %s" % url, 2)
|
2015-12-25 06:54:34 +11:00
|
|
|
self.logMsg("Postdata: %s" % data, 2)
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
self.downloadUrl(url, postBody=data, type="POST")
|
|
|
|
self.logMsg("Posted capabilities to %s" % self.server, 2)
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-05-14 04:49:27 +10:00
|
|
|
# Attempt at getting sessionId
|
2015-12-25 06:54:34 +11:00
|
|
|
url = "{server}/emby/Sessions?DeviceId=%s&format=json" % deviceId
|
|
|
|
result = self.downloadUrl(url)
|
2015-05-14 04:49:27 +10:00
|
|
|
try:
|
2015-12-25 06:54:34 +11:00
|
|
|
sessionId = result[0]['Id']
|
|
|
|
|
|
|
|
except (KeyError, TypeError):
|
2015-05-14 04:49:27 +10:00
|
|
|
self.logMsg("Failed to retrieve sessionId.", 1)
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-08-15 15:20:06 +10:00
|
|
|
else:
|
2015-12-25 06:54:34 +11:00
|
|
|
self.logMsg("Session: %s" % result, 2)
|
|
|
|
self.logMsg("SessionId: %s" % sessionId, 1)
|
|
|
|
utils.window('emby_sessionId', value=sessionId)
|
|
|
|
|
2015-08-15 15:20:06 +10:00
|
|
|
# Post any permanent additional users
|
2015-12-25 06:54:34 +11:00
|
|
|
additionalUsers = utils.settings('additionalUsers')
|
|
|
|
if additionalUsers:
|
|
|
|
|
|
|
|
additionalUsers = additionalUsers.split(',')
|
|
|
|
self.logMsg(
|
|
|
|
"List of permanent users added to the session: %s"
|
|
|
|
% additionalUsers, 1)
|
|
|
|
|
|
|
|
# Get the user list from server to get the userId
|
|
|
|
url = "{server}/emby/Users?format=json"
|
|
|
|
result = self.downloadUrl(url)
|
|
|
|
|
|
|
|
for additional in additionalUsers:
|
|
|
|
addUser = additional.decode('utf-8').lower()
|
|
|
|
|
|
|
|
# Compare to server users to list of permanent additional users
|
|
|
|
for user in result:
|
|
|
|
username = user['Name'].lower()
|
|
|
|
|
2015-08-15 15:20:06 +10:00
|
|
|
if username in addUser:
|
2015-12-25 06:54:34 +11:00
|
|
|
userId = user['Id']
|
|
|
|
url = (
|
|
|
|
"{server}/emby/Sessions/%s/Users/%s?format=json"
|
|
|
|
% (sessionId, userId)
|
|
|
|
)
|
|
|
|
self.downloadUrl(url, postBody={}, type="POST")
|
|
|
|
|
2015-05-14 04:49:27 +10:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
def startSession(self):
|
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
self.deviceId = self.clientInfo.getDeviceId()
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
# User is identified from this point
|
|
|
|
# Attach authenticated header to the session
|
2015-04-24 20:17:08 +10:00
|
|
|
verify = None
|
2015-04-25 11:57:04 +10:00
|
|
|
cert = None
|
|
|
|
header = self.getHeader()
|
2015-04-24 20:17:08 +10:00
|
|
|
|
2015-04-25 11:57:04 +10:00
|
|
|
# If user enabled host certificate verification
|
2015-05-03 07:40:30 +10:00
|
|
|
try:
|
|
|
|
verify = self.sslverify
|
2015-04-25 11:57:04 +10:00
|
|
|
cert = self.sslclient
|
2015-05-03 07:40:30 +10:00
|
|
|
except:
|
|
|
|
self.logMsg("Could not load SSL settings.", 1)
|
2015-04-25 11:57:04 +10:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
# Start session
|
|
|
|
self.s = requests.Session()
|
2015-04-24 20:17:08 +10:00
|
|
|
self.s.headers = header
|
|
|
|
self.s.verify = verify
|
2015-04-25 11:57:04 +10:00
|
|
|
self.s.cert = cert
|
2015-04-22 07:34:56 +10:00
|
|
|
# Retry connections to the server
|
|
|
|
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
|
|
|
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
self.logMsg("Requests session started on: %s" % self.server, 1)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-08-14 19:03:12 +10:00
|
|
|
def stopSession(self):
|
|
|
|
try:
|
|
|
|
self.s.close()
|
|
|
|
except:
|
|
|
|
self.logMsg("Requests session could not be terminated.", 1)
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
def getHeader(self, authenticate=True):
|
|
|
|
|
|
|
|
clientInfo = self.clientInfo
|
|
|
|
|
|
|
|
deviceName = clientInfo.getDeviceName()
|
2015-12-25 06:54:34 +11:00
|
|
|
deviceId = clientInfo.getDeviceId()
|
2015-03-14 08:24:59 +11:00
|
|
|
version = clientInfo.getVersion()
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
if not authenticate:
|
|
|
|
# If user is not authenticated
|
2015-12-25 06:54:34 +11:00
|
|
|
auth = (
|
|
|
|
'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
|
|
|
% (deviceName, deviceId, version))
|
|
|
|
header = {
|
|
|
|
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
'Accept-encoding': 'gzip',
|
|
|
|
'Accept-Charset': 'UTF-8,*',
|
|
|
|
'Authorization': auth
|
|
|
|
}
|
2015-04-22 07:34:56 +10:00
|
|
|
self.logMsg("Header: %s" % header, 2)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
else:
|
2015-04-22 07:34:56 +10:00
|
|
|
userId = self.userId
|
|
|
|
token = self.token
|
|
|
|
# Attached to the requests session
|
2015-12-25 06:54:34 +11:00
|
|
|
auth = (
|
|
|
|
'MediaBrowser UserId="%s", Client="Kodi", Device="%s", DeviceId="%s", Version="%s"'
|
|
|
|
% (userId, deviceName, deviceId, version))
|
|
|
|
header = {
|
|
|
|
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
'Accept-encoding': 'gzip',
|
|
|
|
'Accept-Charset': 'UTF-8,*',
|
|
|
|
'Authorization': auth,
|
|
|
|
'X-MediaBrowser-Token': token
|
|
|
|
}
|
2015-04-22 07:34:56 +10:00
|
|
|
self.logMsg("Header: %s" % header, 2)
|
2015-12-25 06:54:34 +11:00
|
|
|
|
|
|
|
return header
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
def downloadUrl(self, url, postBody=None, type="GET", parameters=None, authenticate=True):
|
2015-03-14 13:37:03 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
self.logMsg("=== ENTER downloadUrl ===", 2)
|
|
|
|
|
|
|
|
timeout = self.timeout
|
|
|
|
default_link = ""
|
|
|
|
|
2015-05-03 15:27:43 +10:00
|
|
|
try:
|
|
|
|
# If user is authenticated
|
|
|
|
if (authenticate):
|
|
|
|
# Get requests session
|
|
|
|
try:
|
|
|
|
s = self.s
|
2015-12-25 06:54:34 +11:00
|
|
|
# Replace for the real values
|
|
|
|
url = url.replace("{server}", self.server)
|
|
|
|
url = url.replace("{UserId}", self.userId)
|
2015-05-03 15:27:43 +10:00
|
|
|
|
|
|
|
# Prepare request
|
|
|
|
if type == "GET":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = s.get(url, json=postBody, params=parameters, timeout=timeout)
|
2015-05-03 15:27:43 +10:00
|
|
|
elif type == "POST":
|
|
|
|
r = s.post(url, json=postBody, timeout=timeout)
|
|
|
|
elif type == "DELETE":
|
|
|
|
r = s.delete(url, json=postBody, timeout=timeout)
|
|
|
|
|
|
|
|
except AttributeError:
|
2015-12-25 06:54:34 +11:00
|
|
|
# request session does not exists
|
2015-05-03 15:27:43 +10:00
|
|
|
# Get user information
|
2015-12-25 06:54:34 +11:00
|
|
|
self.userId = utils.window('emby_currUser')
|
|
|
|
self.server = utils.window('emby_server%s' % self.userId)
|
|
|
|
self.token = utils.window('emby_accessToken%s' % self.userId)
|
2015-05-03 15:27:43 +10:00
|
|
|
header = self.getHeader()
|
|
|
|
verifyssl = False
|
|
|
|
cert = None
|
|
|
|
|
|
|
|
# IF user enables ssl verification
|
2015-12-25 06:54:34 +11:00
|
|
|
if utils.settings('sslverify') == "true":
|
|
|
|
verifyssl = True
|
|
|
|
if utils.settings('sslcert') != "None":
|
|
|
|
cert = utils.settings('sslcert')
|
2015-05-03 15:27:43 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
# Replace for the real values
|
|
|
|
url = url.replace("{server}", self.server)
|
|
|
|
url = url.replace("{UserId}", self.userId)
|
2015-05-03 15:27:43 +10:00
|
|
|
|
|
|
|
# Prepare request
|
|
|
|
if type == "GET":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = requests.get(url,
|
|
|
|
json=postBody,
|
|
|
|
params=parameters,
|
|
|
|
headers=header,
|
|
|
|
timeout=timeout,
|
|
|
|
cert=cert,
|
|
|
|
verify=verifyssl)
|
|
|
|
|
2015-05-03 15:27:43 +10:00
|
|
|
elif type == "POST":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = requests.post(url,
|
|
|
|
json=postBody,
|
|
|
|
headers=header,
|
|
|
|
timeout=timeout,
|
|
|
|
cert=cert,
|
|
|
|
verify=verifyssl)
|
|
|
|
|
2015-05-03 15:27:43 +10:00
|
|
|
elif type == "DELETE":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = requests.delete(url,
|
|
|
|
json=postBody,
|
|
|
|
headers=header,
|
|
|
|
timeout=timeout,
|
|
|
|
cert=cert,
|
|
|
|
verify=verifyssl)
|
2015-05-03 15:27:43 +10:00
|
|
|
|
|
|
|
# If user is not authenticated
|
|
|
|
elif not authenticate:
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-05-03 15:27:43 +10:00
|
|
|
header = self.getHeader(authenticate=False)
|
2015-05-03 07:40:30 +10:00
|
|
|
verifyssl = False
|
|
|
|
|
2015-05-03 15:27:43 +10:00
|
|
|
# If user enables ssl verification
|
2015-05-03 07:40:30 +10:00
|
|
|
try:
|
2015-05-03 15:27:43 +10:00
|
|
|
verifyssl = self.sslverify
|
|
|
|
except AttributeError:
|
2015-05-03 07:40:30 +10:00
|
|
|
pass
|
2015-05-03 15:27:43 +10:00
|
|
|
|
2015-05-03 07:40:30 +10:00
|
|
|
# Prepare request
|
|
|
|
if type == "GET":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = requests.get(url,
|
|
|
|
json=postBody,
|
|
|
|
params=parameters,
|
|
|
|
headers=header,
|
|
|
|
timeout=timeout,
|
|
|
|
verify=verifyssl)
|
|
|
|
|
2015-05-03 07:40:30 +10:00
|
|
|
elif type == "POST":
|
2015-12-25 06:54:34 +11:00
|
|
|
r = requests.post(url,
|
|
|
|
json=postBody,
|
|
|
|
headers=header,
|
|
|
|
timeout=timeout,
|
|
|
|
verify=verifyssl)
|
2015-04-27 09:15:40 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
##### THE RESPONSE #####
|
|
|
|
self.logMsg(r.url, 2)
|
2015-04-22 07:34:56 +10:00
|
|
|
if r.status_code == 204:
|
2015-05-03 15:27:43 +10:00
|
|
|
# No body in the response
|
2015-04-24 20:17:08 +10:00
|
|
|
self.logMsg("====== 204 Success ======", 2)
|
2015-05-03 15:27:43 +10:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
elif r.status_code == requests.codes.ok:
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
try:
|
2015-04-22 07:34:56 +10:00
|
|
|
# UTF-8 - JSON object
|
|
|
|
r = r.json()
|
2015-04-24 20:17:08 +10:00
|
|
|
self.logMsg("====== 200 Success ======", 2)
|
2015-06-05 20:12:09 +10:00
|
|
|
self.logMsg("Response: %s" % r, 2)
|
2015-04-22 07:34:56 +10:00
|
|
|
return r
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
except:
|
2015-12-25 06:54:34 +11:00
|
|
|
if r.headers.get('content-type') != "text/html":
|
2015-05-05 05:09:01 +10:00
|
|
|
self.logMsg("Unable to convert the response for: %s" % url, 1)
|
2015-05-03 15:27:43 +10:00
|
|
|
else:
|
|
|
|
r.raise_for_status()
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
##### EXCEPTIONS #####
|
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
except requests.exceptions.ConnectionError as e:
|
2015-05-03 15:27:43 +10:00
|
|
|
# Make the addon aware of status
|
2015-12-25 06:54:34 +11:00
|
|
|
if utils.window('emby_online') != "false":
|
2015-05-03 15:27:43 +10:00
|
|
|
self.logMsg("Server unreachable at: %s" % url, 0)
|
|
|
|
self.logMsg(e, 2)
|
2015-12-25 06:54:34 +11:00
|
|
|
utils.window('emby_online', value="false")
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
except requests.exceptions.ConnectTimeout as e:
|
|
|
|
self.logMsg("Server timeout at: %s" % url, 0)
|
2015-04-27 09:15:40 +10:00
|
|
|
self.logMsg(e, 1)
|
2015-04-22 07:34:56 +10:00
|
|
|
|
|
|
|
except requests.exceptions.HTTPError as e:
|
|
|
|
|
2015-04-27 09:15:40 +10:00
|
|
|
if r.status_code == 401:
|
2015-04-22 07:34:56 +10:00
|
|
|
# Unauthorized
|
2015-12-25 06:54:34 +11:00
|
|
|
status = utils.window('emby_serverStatus')
|
2015-05-12 17:34:03 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
if 'X-Application-Error-Code' in r.headers:
|
|
|
|
# Emby server errors
|
2015-05-14 14:48:35 +10:00
|
|
|
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
|
|
|
# Parental control - access restricted
|
2015-12-25 06:54:34 +11:00
|
|
|
utils.window('emby_serverStatus', value="restricted")
|
|
|
|
xbmcgui.Dialog().notification(
|
|
|
|
heading="Emby server",
|
|
|
|
message="Access restricted.",
|
|
|
|
icon=xbmcgui.NOTIFICATION_ERROR,
|
|
|
|
time=5000)
|
2015-05-14 14:48:35 +10:00
|
|
|
return False
|
2015-12-25 06:54:34 +11:00
|
|
|
|
2015-08-31 11:17:09 +10:00
|
|
|
elif r.headers['X-Application-Error-Code'] == "UnauthorizedAccessException":
|
2015-12-25 06:54:34 +11:00
|
|
|
# User tried to do something his emby account doesn't allow
|
2015-08-31 11:17:09 +10:00
|
|
|
pass
|
2015-05-12 17:34:03 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
elif status not in ("401", "Auth"):
|
|
|
|
# Tell userclient token has been revoked.
|
|
|
|
utils.window('emby_serverStatus', value="401")
|
2015-04-22 07:34:56 +10:00
|
|
|
self.logMsg("HTTP Error: %s" % e, 0)
|
2015-12-25 06:54:34 +11:00
|
|
|
xbmcgui.Dialog().notification(
|
|
|
|
heading="Error connecting",
|
|
|
|
message="Unauthorized.",
|
|
|
|
icon=xbmcgui.NOTIFICATION_ERROR)
|
2015-05-14 14:48:35 +10:00
|
|
|
return 401
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
elif r.status_code in (301, 302):
|
2015-04-27 09:15:40 +10:00
|
|
|
# Redirects
|
|
|
|
pass
|
|
|
|
elif r.status_code == 400:
|
|
|
|
# Bad requests
|
2015-03-14 08:24:59 +11:00
|
|
|
pass
|
|
|
|
|
2015-04-24 20:17:08 +10:00
|
|
|
except requests.exceptions.SSLError as e:
|
|
|
|
self.logMsg("Invalid SSL certificate for: %s" % url, 0)
|
2015-04-27 09:15:40 +10:00
|
|
|
self.logMsg(e, 1)
|
2015-04-24 20:17:08 +10:00
|
|
|
|
2015-04-22 07:34:56 +10:00
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
self.logMsg("Unknown error connecting to: %s" % url, 0)
|
2015-04-27 09:15:40 +10:00
|
|
|
self.logMsg(e, 1)
|
2015-04-22 07:34:56 +10:00
|
|
|
|
2015-12-25 06:54:34 +11:00
|
|
|
return default_link
|