From 65c31b1eaaeea2f9e10186bd8a3a470f401c2d02 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 1 May 2017 20:29:28 +0200 Subject: [PATCH] Use Kodi video cache setting for transcoding --- resources/lib/PlexAPI.py | 1 - resources/lib/initialsetup.py | 13 +++++++++++- resources/lib/playutils.py | 3 ++- resources/lib/utils.py | 37 +++++++++++++++++++++++++++++++++-- resources/settings.xml | 1 + 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 7067fd08..b466d1b6 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -2281,7 +2281,6 @@ class API(): 'partIndex': self.part, 'hasMDE': 1, 'location': 'lan', - 'mediaBufferSize': '16384', 'subtitleSize': settings('subtitleSize') # 'copyts': 1, # 'offset': 0, # Resume point diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 9890fb74..534241aa 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -6,7 +6,8 @@ import logging import xbmc import xbmcgui -from utils import settings, window, language as lang, tryEncode +from utils import settings, window, language as lang, tryEncode, \ + get_advancessettings_xml_setting import downloadutils from userclient import UserClient @@ -399,6 +400,16 @@ class InitialSetup(): log.info("Initial setup called.") dialog = self.dialog + # Get current Kodi video cache setting + cache = get_advancessettings_xml_setting(['cache', 'memorysize']) + if cache is not None: + cache = str(cache.text) + else: + # Kodi default cache + cache = '20971520' + log.info('Current Kodi video memory cache in bytes: %s' % cache) + settings('kodi_video_cache', value=cache) + # Optionally sign into plex.tv. Will not be called on very first run # as plexToken will be '' settings('plex_status', value='Not logged in to plex.tv') diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 046e5a4f..6f6415de 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -59,7 +59,8 @@ class PlayUtils(): quality={ 'maxVideoBitrate': self.get_bitrate(), 'videoResolution': self.get_resolution(), - 'videoQuality': '100' + 'videoQuality': '100', + 'mediaBufferSize': int(settings('kodi_video_cache'))/1024, })) # Set playmethod property window('plex_%s.playmethod' % playurl, value="Transcode") diff --git a/resources/lib/utils.py b/resources/lib/utils.py index bdfe6e9d..e416fe59 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -548,6 +548,40 @@ def __setSubElement(element, subelement): return answ +def get_advancessettings_xml_setting(node_list): + """ + Returns the etree element for nodelist (if it exists) and None if not set + + node_list is a list of node names starting from the outside, ignoring the + outter advancedsettings. Example nodelist=['video', 'busydialogdelayms'] + for the following xml would return the etree Element: + + 750 + + Example xml: + + + + + + """ + path = tryDecode(xbmc.translatePath("special://profile/")) + try: + xmlparse = etree.parse("%sadvancedsettings.xml" % path) + except: + log.debug('Could not parse advancedsettings.xml, returning None') + return + root = xmlparse.getroot() + + for node in node_list: + root = root.find(node) + if root is None: + break + return root + + def advancedSettingsXML(): """ Kodi tweaks @@ -595,12 +629,11 @@ def sourcesXML(): try: xmlparse = etree.parse(xmlpath) - except: # Document is blank or missing + except: # Document is blank or missing root = etree.Element('sources') else: root = xmlparse.getroot() - video = root.find('video') if video is None: video = etree.SubElement(root, 'video') diff --git a/resources/settings.xml b/resources/settings.xml index 429c7173..bb80d34e 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -110,6 +110,7 @@ +