2018-07-13 02:46:02 +10:00
|
|
|
#!/usr/bin/env python
|
2015-12-25 06:51:47 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-13 02:46:02 +10:00
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
2020-12-19 03:10:20 +11:00
|
|
|
from builtins import str
|
2017-12-10 00:35:08 +11:00
|
|
|
from logging import getLogger
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2019-10-31 23:01:08 +11:00
|
|
|
import xbmc
|
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
from . import utils
|
|
|
|
from . import variables as v
|
2016-08-30 03:45:26 +10:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
LOG = getLogger('PLEX.clientinfo')
|
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": "*",
|
2019-10-31 23:01:08 +11:00
|
|
|
'Accept-Language': xbmc.getLanguage(xbmc.ISO_639_1),
|
2019-02-06 04:52:10 +11:00
|
|
|
'X-Plex-Device': v.DEVICE,
|
|
|
|
'X-Plex-Model': v.MODEL,
|
2017-01-25 02:53:50 +11:00
|
|
|
'X-Plex-Device-Name': v.DEVICENAME,
|
|
|
|
'X-Plex-Platform': v.PLATFORM,
|
2019-02-06 04:52:10 +11:00
|
|
|
'X-Plex-Platform-Version': v.PLATFORM_VERSION,
|
2017-01-25 02:53:50 +11:00
|
|
|
'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
|
|
|
}
|
2018-06-22 03:24:37 +10:00
|
|
|
if include_token and utils.window('pms_token'):
|
|
|
|
xargs['X-Plex-Token'] = utils.window('pms_token')
|
2017-01-25 02:53:50 +11:00
|
|
|
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:
|
2017-12-10 02:18:46 +11:00
|
|
|
v.PKC_MACHINE_IDENTIFIER = None
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.window('plex_client_Id', clear=True)
|
|
|
|
utils.settings('plex_client_Id', value="")
|
2017-01-25 02:53:50 +11:00
|
|
|
|
2017-12-10 02:18:46 +11:00
|
|
|
client_id = v.PKC_MACHINE_IDENTIFIER
|
|
|
|
if client_id:
|
|
|
|
return client_id
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
client_id = utils.settings('plex_client_Id')
|
2017-01-25 02:53:50 +11:00
|
|
|
# Because Kodi appears to cache file settings!!
|
2017-12-10 02:18:46 +11:00
|
|
|
if client_id != "" and reset is False:
|
|
|
|
v.PKC_MACHINE_IDENTIFIER = client_id
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.window('plex_client_Id', value=client_id)
|
|
|
|
LOG.info("Unique device Id plex_client_Id loaded: %s", client_id)
|
2017-12-10 02:18:46 +11:00
|
|
|
return client_id
|
2017-01-25 02:53:50 +11:00
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
LOG.info("Generating a new deviceid.")
|
2017-01-25 02:53:50 +11:00
|
|
|
from uuid import uuid4
|
2017-12-10 02:18:46 +11:00
|
|
|
client_id = str(uuid4())
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.settings('plex_client_Id', value=client_id)
|
2017-12-10 02:18:46 +11:00
|
|
|
v.PKC_MACHINE_IDENTIFIER = client_id
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.window('plex_client_Id', value=client_id)
|
|
|
|
LOG.info("Unique device Id plex_client_Id generated: %s", client_id)
|
2017-12-10 02:18:46 +11:00
|
|
|
return client_id
|