5.1.2. Resource — Bundled resource management¶
The Resource module provides functions that manage resource files bundled with a plug-in. Using these functions, the resources included in the bundle can easily be loaded or returned to Plex for display in the user interface. The module also contains functions providing access to shared resource files made available by the framework.
This module defines the following functions:
- Resource.Load(itemName, binary=False)¶
Loads the contents of the named item in the plug-in’s Contents/Resources directory. The binary argument is optional - if set to True, it instructs Python to leave line endings intact rather than converting them to the ending type used by the system. It is generally safe to omit this option, even when dealing with binary files - it is provided for compatibility with the minority of files that are loaded incorrectly by default.
Parameters: - itemName (str) – The name of the item to load
- binary (bool) – Specifies whether to treat the file as binary data
Returns: The contents of the named item
Loads the contents of the named item from the shared resources provided by the framework. See sharedresources for a list of available items.
Parameter: itemName (str) – The name of the item to load Returns: The contents of the named item
- Resource.ExternalPath(itemName)¶
Returns a path to the named item inside the plug-in bundle that is accessible via the media server’s HTTP interface. This function is generally used when assigning internal image resources to media items (the art and thumb attributes) for returning to Plex.
Parameter: itemName (str) – The name of the item Returns: An externally accessible path to the item Return type: str Note
Resources are not accessible via the HTTP interface by default. All resources are considered private until an external path is requested using this function.
Note
A shortcut for this function is available. See Shortcuts for more details.
Returns a path to the named item from the framework’s shared resources that is accessible via the media server’s HTTP interface.
Parameter: itemName (str) – The name of the item Returns: An externally accessible path to the item Return type: str Note
A shortcut for this function is available. See Shortcuts for more details.
- Resource.AddMimeType(ext, mimeType)¶
Registers a new MIME type for a given file extension with the framework. This MIME type will be used when returning resources via the media server’s HTTP interface. Common types and extensions are already defined by the framework; the developer will only need to use this function to register uncommon file types.
Parameters: - ext (str) – The file extension to register (should start with a period character, e.g. .png)
- mimeType (str) – The MIME type to register (e.g. image/png)
- Resource.MimeTypeForExtension(ext)¶
Returns the registered MIME type for the given file extension.
Parameter: ext (str) – The file extension to look up Returns: The MIME type registered for the extension, or application/octet-stream if no MIME type could be found. Return type: str