From 9208cf2cb3cb3ff71978c8880d749d229134ad1b Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 5 Feb 2019 18:52:10 +0100 Subject: [PATCH] Optimize headers for communication with PMS to appear like PMP --- resources/lib/clientinfo.py | 7 +++--- resources/lib/library_sync/common.py | 2 +- resources/lib/plexbmchelper/listener.py | 2 +- resources/lib/plexbmchelper/subscribers.py | 13 +++++------ resources/lib/utils.py | 4 ++-- resources/lib/variables.py | 26 +++++++++++++--------- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/resources/lib/clientinfo.py b/resources/lib/clientinfo.py index d576ed44..54378598 100644 --- a/resources/lib/clientinfo.py +++ b/resources/lib/clientinfo.py @@ -32,12 +32,11 @@ def getXArgsDeviceInfo(options=None, include_token=True): "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': v.DEVICE, + 'X-Plex-Model': v.MODEL, 'X-Plex-Device-Name': v.DEVICENAME, 'X-Plex-Platform': v.PLATFORM, - # 'X-Plex-Platform-Version': 'unknown', - # 'X-Plex-Model': 'unknown', + 'X-Plex-Platform-Version': v.PLATFORM_VERSION, 'X-Plex-Product': v.ADDON_NAME, 'X-Plex-Version': v.ADDON_VERSION, 'X-Plex-Client-Identifier': getDeviceId(), diff --git a/resources/lib/library_sync/common.py b/resources/lib/library_sync/common.py index 557d0f33..3748c754 100644 --- a/resources/lib/library_sync/common.py +++ b/resources/lib/library_sync/common.py @@ -5,7 +5,7 @@ import xbmc from .. import app, utils, variables as v -PLAYLIST_SYNC_ENABLED = (v.PLATFORM != 'Microsoft UWP' and +PLAYLIST_SYNC_ENABLED = (v.DEVICE != 'Microsoft UWP' and utils.settings('enablePlaylistSync') == 'true') diff --git a/resources/lib/plexbmchelper/listener.py b/resources/lib/plexbmchelper/listener.py index 7efd94bf..e08dca62 100644 --- a/resources/lib/plexbmchelper/listener.py +++ b/resources/lib/plexbmchelper/listener.py @@ -40,7 +40,7 @@ RESOURCES_XML = ('%s\n' '\n') % (v.XML_HEADER, v.ADDON_NAME, v.PLATFORM, - v.ADDON_VERSION) + v.PLATFORM_VERSION) class MyHandler(BaseHTTPRequestHandler): """ diff --git a/resources/lib/plexbmchelper/subscribers.py b/resources/lib/plexbmchelper/subscribers.py index 07614cab..597d8c14 100644 --- a/resources/lib/plexbmchelper/subscribers.py +++ b/resources/lib/plexbmchelper/subscribers.py @@ -9,7 +9,7 @@ from logging import getLogger from threading import Thread from ..downloadutils import DownloadUtils as DU -from .. import utils, timing +from .. import timing from .. import app from .. import variables as v from .. import json_rpc as js @@ -50,7 +50,7 @@ HEADERS_PMS = { 'Accept': 'text/plain, */*; q=0.01', 'Accept-Language': 'en', 'Accept-Encoding': 'gzip, deflate', - 'User-Agent': '%s %s (%s)' % (v.ADDON_NAME, v.ADDON_VERSION, v.PLATFORM) + 'User-Agent': '%s %s (%s)' % (v.ADDON_NAME, v.ADDON_VERSION, v.DEVICE) } @@ -64,14 +64,13 @@ def params_pms(): # 'audioDecoders=mp3,aac,dts{bitrate:800000&channels:2},' # 'ac3{bitrate:800000&channels:2}', 'X-Plex-Client-Identifier': v.PKC_MACHINE_IDENTIFIER, - 'X-Plex-Device': v.PLATFORM, + 'X-Plex-Device': v.DEVICE, 'X-Plex-Device-Name': v.DEVICENAME, # 'X-Plex-Device-Screen-Resolution': '1916x1018,1920x1080', - 'X-Plex-Model': 'unknown', + 'X-Plex-Model': v.MODEL, 'X-Plex-Platform': v.PLATFORM, - 'X-Plex-Platform-Version': 'unknown', + 'X-Plex-Platform-Version': v.PLATFORM_VERSION, 'X-Plex-Product': v.ADDON_NAME, - 'X-Plex-Provider-Version': v.ADDON_VERSION, 'X-Plex-Version': v.ADDON_VERSION, 'hasMDE': '1', # 'X-Plex-Session-Identifier': ['vinuvirm6m20iuw9c4cx1dcx'], @@ -89,7 +88,7 @@ def headers_companion_client(): 'X-Plex-Client-Identifier': v.PKC_MACHINE_IDENTIFIER, 'X-Plex-Device-Name': v.DEVICENAME, 'X-Plex-Platform': v.PLATFORM, - 'X-Plex-Platform-Version': 'unknown', + 'X-Plex-Platform-Version': v.PLATFORM_VERSION, 'X-Plex-Product': v.ADDON_NAME, 'X-Plex-Version': v.ADDON_VERSION, 'Accept-Encoding': 'gzip, deflate', diff --git a/resources/lib/utils.py b/resources/lib/utils.py index df021cde..df5ba600 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -340,14 +340,14 @@ def valid_filename(text): text = re.sub(r'(?! )\s', '', text) # ASCII characters 0 to 31 (non-printable, just in case) text = re.sub(u'[\x00-\x1f]', '', text) - if v.PLATFORM == 'Windows': + if v.DEVICE == 'Windows': # Whitespace at the end of the filename is illegal text = text.strip() # Dot at the end of a filename is illegal text = re.sub(r'\.+$', '', text) # Illegal Windows characters text = re.sub(r'[/\\:*?"<>|\^]', '', text) - elif v.PLATFORM == 'MacOSX': + elif v.DEVICE == 'MacOSX': # Colon is illegal text = re.sub(r':', '', text) # Files cannot begin with a dot diff --git a/resources/lib/variables.py b/resources/lib/variables.py index 34b48c93..08f92915 100644 --- a/resources/lib/variables.py +++ b/resources/lib/variables.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, unicode_literals import os import sys import re +import platform import xbmc from xbmcaddon import Addon @@ -51,23 +52,28 @@ KODILONGVERSION = xbmc.getInfoLabel('System.BuildVersion') KODI_PROFILE = try_decode(xbmc.translatePath("special://profile")) if xbmc.getCondVisibility('system.platform.osx'): - PLATFORM = "MacOSX" + DEVICE = "MacOSX" elif xbmc.getCondVisibility("system.platform.uwp"): - PLATFORM = "Microsoft UWP" + DEVICE = "Microsoft UWP" elif xbmc.getCondVisibility('system.platform.atv2'): - PLATFORM = "AppleTV2" + DEVICE = "AppleTV2" elif xbmc.getCondVisibility('system.platform.ios'): - PLATFORM = "iOS" + DEVICE = "iOS" elif xbmc.getCondVisibility('system.platform.windows'): - PLATFORM = "Windows" + DEVICE = "Windows" elif xbmc.getCondVisibility('system.platform.raspberrypi'): - PLATFORM = "RaspberryPi" + DEVICE = "RaspberryPi" elif xbmc.getCondVisibility('system.platform.linux'): - PLATFORM = "Linux" + DEVICE = "Linux" elif xbmc.getCondVisibility('system.platform.android'): - PLATFORM = "Android" + DEVICE = "Android" else: - PLATFORM = "Unknown" + DEVICE = "Unknown" + +MODEL = platform.release() or 'Unknown' +# Plex' own platform for e.g. Plex Media Player +PLATFORM = 'Konvergo' +PLATFORM_VERSION = '2.26.0.947-1e21fa2b' DEVICENAME = try_decode(_ADDON.getSetting('deviceName')) if not DEVICENAME: @@ -637,7 +643,7 @@ def database_paths(): # Encoding to be used for our m3u playlist files # m3u files do not have encoding specified by definition, unfortunately. -if PLATFORM == 'Windows': +if DEVICE == 'Windows': M3U_ENCODING = 'mbcs' else: M3U_ENCODING = sys.getfilesystemencoding()