2015-12-25 06:51:47 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-02-20 06:03:06 +11:00
|
|
|
###############################################################################
|
2017-12-10 00:35:08 +11:00
|
|
|
from logging import getLogger
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2017-01-25 02:53:50 +11:00
|
|
|
from utils import window, settings
|
|
|
|
import variables as v
|
2016-08-30 03:45:26 +10:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2017-12-10 00:35:08 +11:00
|
|
|
log = getLogger("PLEX."+__name__)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-02-20 06:03:06 +11:00
|
|
|
###############################################################################
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
|
2017-12-09 23:54:30 +11:00
|
|
|
def getXArgsDeviceInfo(options=None, include_token=True):
|
2017-01-25 02:53:50 +11:00
|
|
|
"""
|
|
|
|
Returns a dictionary that can be used as headers for GET and POST
|
|
|
|
requests. An authentication option is NOT yet added.
|
|
|
|
|
|
|
|
Inputs:
|
|
|
|
options: dictionary of options that will override the
|
|
|
|
standard header options otherwise set.
|
2017-12-09 23:54:30 +11:00
|
|
|
include_token: set to False if you don't want to include the Plex token
|
|
|
|
(e.g. for Companion communication)
|
2017-01-25 02:53:50 +11:00
|
|
|
Output:
|
|
|
|
header dictionary
|
|
|
|
"""
|
|
|
|
xargs = {
|
|
|
|
'Accept': '*/*',
|
|
|
|
'Connection': 'keep-alive',
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
# "Access-Control-Allow-Origin": "*",
|
|
|
|
# 'X-Plex-Language': 'en',
|
|
|
|
'X-Plex-Device': v.ADDON_NAME,
|
|
|
|
'X-Plex-Client-Platform': v.PLATFORM,
|
|
|
|
'X-Plex-Device-Name': v.DEVICENAME,
|
|
|
|
'X-Plex-Platform': v.PLATFORM,
|
|
|
|
# 'X-Plex-Platform-Version': 'unknown',
|
|
|
|
# 'X-Plex-Model': 'unknown',
|
|
|
|
'X-Plex-Product': v.ADDON_NAME,
|
|
|
|
'X-Plex-Version': v.ADDON_VERSION,
|
2017-01-25 02:58:25 +11:00
|
|
|
'X-Plex-Client-Identifier': getDeviceId(),
|
2017-03-05 03:54:24 +11:00
|
|
|
'X-Plex-Provides': 'client,controller,player,pubsub-player',
|
2017-01-25 02:53:50 +11:00
|
|
|
}
|
2017-12-09 23:54:30 +11:00
|
|
|
if include_token and window('pms_token'):
|
2017-01-25 02:53:50 +11:00
|
|
|
xargs['X-Plex-Token'] = window('pms_token')
|
|
|
|
if options is not None:
|
|
|
|
xargs.update(options)
|
|
|
|
return xargs
|
|
|
|
|
|
|
|
|
2017-01-25 02:58:25 +11:00
|
|
|
def getDeviceId(reset=False):
|
2017-01-25 02:53:50 +11:00
|
|
|
"""
|
|
|
|
Returns a unique Plex client id "X-Plex-Client-Identifier" from Kodi
|
|
|
|
settings file.
|
|
|
|
Also loads Kodi window property 'plex_client_Id'
|
|
|
|
|
|
|
|
If id does not exist, create one and save in Kodi settings file.
|
|
|
|
"""
|
|
|
|
if reset is True:
|
|
|
|
window('plex_client_Id', clear=True)
|
|
|
|
settings('plex_client_Id', value="")
|
|
|
|
|
|
|
|
clientId = window('plex_client_Id')
|
|
|
|
if clientId:
|
|
|
|
return clientId
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2017-01-25 02:53:50 +11:00
|
|
|
clientId = settings('plex_client_Id')
|
|
|
|
# Because Kodi appears to cache file settings!!
|
|
|
|
if clientId != "" and reset is False:
|
2016-04-06 02:23:00 +10:00
|
|
|
window('plex_client_Id', value=clientId)
|
2017-09-06 21:39:44 +10:00
|
|
|
log.info("Unique device Id plex_client_Id loaded: %s" % clientId)
|
2016-01-14 20:20:19 +11:00
|
|
|
return clientId
|
2017-01-25 02:53:50 +11:00
|
|
|
|
2017-09-06 21:39:44 +10:00
|
|
|
log.info("Generating a new deviceid.")
|
2017-01-25 02:53:50 +11:00
|
|
|
from uuid import uuid4
|
|
|
|
clientId = str(uuid4())
|
|
|
|
settings('plex_client_Id', value=clientId)
|
|
|
|
window('plex_client_Id', value=clientId)
|
2017-09-06 21:39:44 +10:00
|
|
|
log.info("Unique device Id plex_client_Id loaded: %s" % clientId)
|
2017-01-25 02:53:50 +11:00
|
|
|
return clientId
|