Trying to access Prefs in URL service not working

I am trying to access one of the plugins user preferences with Prefs[“FORCE_BEST_QUALITY”].
This works in init.py, but not in my URL services.
It returns a KeyError: “No preference named ‘FORCE_BEST_QUALITY’ found.”
That is weard, because when i test it in my init.py it does work.
Is it even possible to access the Prefs in an URL service? Or am I doing something wrong?

You can watch the code in my GitHub repo or below. Please make sure you are looking at my “dev” branch if viewing on GitHub.

Log error:

2018-02-25 02:03:31,453 (458) :  CRITICAL (core:574) - Exception when constructing response (most recent call last):
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\runtime.py", line 951, in construct_response
    el = result._to_xml()
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\objectkit.py", line 667, in _to_xml
    el = Framework.modelling.objects.ModelInterfaceObjectContainer._to_xml(self)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\modelling\objects.py", line 382, in _to_xml
    root = Container._to_xml(self)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\modelling\objects.py", line 139, in _to_xml
    self._append_children(root, self._objects)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\modelling\objects.py", line 145, in _append_children
    el = obj._to_xml()
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\objectkit.py", line 597, in _to_xml
    items = self._core.services.media_objects_for_url(url, allow_deferred=True, metadata_class=type(self))
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\services.py", line 718, in media_objects_for_url
    return self._get_result_from_function_for_url(self.media_objects_for_url_from_service, url, do_normalization, dict(allow_deferred=allow_deferred, metadata_class=metadata_class))
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\services.py", line 741, in _get_result_from_function_for_url
    result = func(url, service, **kwargs)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\services.py", line 687, in media_objects_for_url_from_service
    return self._call_named_function_in_service(MEDIA_OBJECTS_FUNCTION_NAME, service, , allow_deferred=allow_deferred, f_optional=dict(metadata_class=metadata_class))
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\services.py", line 589, in _call_named_function_in_service
    return self._call_named_function_in_sandbox(service.sandbox, fname, None, f_args, f_kwargs, allow_deferred, raise_exceptions, f_optional)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\services.py", line 573, in _call_named_function_in_sandbox
    result = sandbox.call_named_function(fname, allow_deferred=allow_deferred, raise_exceptions=raise_exceptions, args=f_args, kwargs=f_kwargs, mod_name=mod_name, optional_kwargs=f_optional)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\code\sandbox.py", line 294, in call_named_function
    result = f(*args, **kwargs)
  File "C:\Users\mento\AppData\Local\Plex Media Server\Plug-ins\Kijk.bundle\Contents\Services\URL\BrightCove\ServiceCode.pys", line 99, in MediaObjectsForURL
    if Prefs["FORCE_BEST_QUALITY"] and stream["width"] > prevBestWidth:
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\code\sandbox.py", line 108, in <lambda>
    _getitem_           = lambda x, y: x.__getitem__(y),
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\runtimekit.py", line 498, in __getitem__
    return self._sandbox.preferences.get()[name]
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-c40bba82e\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\code\preferences.py", line 332, in __getitem__
    raise KeyError("No preference named '%s' found." % name)
KeyError: "No preference named 'FORCE_BEST_QUALITY' found."

Brightcove URL service:

if Prefs["FORCE_BEST_QUALITY"] and stream["width"] > prevBestWidth:
    mo = []
    prevBestWidth = stream["width"]

DefaultPrefs.json

[
  {
    "id": "FORCE_BEST_QUALITY",
    "label": "Force best quality",
    "type": "bool",
    "default": "false"
  }
]

This is an question for the Channel Plugin Development section of the forum.

So I am moving this post to that section.

Channel prefs are set in DefaultPrefs.json. If you want URL Services to have preferences, you can add a file ServicePrefs.json to your URL Service folder (example).

1 Like