plex_api_helper

Code.plex_api_helper.add_media(item, media_type, media_url_id, media_file=None, media_url=None)[source]

Apply media to the specified item.

Adds theme song to the item specified by the rating_key. If the same theme song is already present, it will be skipped.

Parameters:
item : PlexPartialObject

The Plex item to add the theme to.

media_type : str

The type of media to add. Must be one of ‘art’, ‘posters’, or ‘themes’.

media_url_id : str

The url or id of the media.

media_file : Optional[str]

Full path to media file.

media_url : Optional[str]

URL of media.

Returns:
pybool

True if the media was added successfully or already present, False otherwise.

Examples

>>> add_media(item=..., media_type='themes', media_url_id=..., media_url=...)
>>> add_media(item=..., media_type='themes', media_url_url=..., media_file=...)
Code.plex_api_helper.change_lock_status(item, field, lock=False)[source]

Change the lock status of the specified field.

Parameters:
item : PlexPartialObject

The Plex item to unlock the field for.

field : str

The field to unlock.

lock : pybool

True to lock the field, False to unlock the field.

Returns:
pybool

True if the lock status matches the requested lock status, False otherwise.

Examples

>>> change_lock_status(item=..., field='theme', lock=False)
Code.plex_api_helper.get_database_info(item)[source]

Get the database info for the specified item.

Get the database_type, database, agent, database_id which can be used to locate the theme song in ThemerrDB.

Parameters:
item : PlexPartialObject

The Plex item to get the database info for.

Returns:
Tuple[Optional[str], Optional[str], Optional[str], Optional[str]]

The database_type, database, agent, database_id.

Examples

>>> get_database_info(item=...)
Code.plex_api_helper.get_plex_item(rating_key)[source]

Get any item from the Plex Server.

This function is used to get an item from the Plex Server. It can then be used to get the metadata for the item.

Parameters:
rating_key : int

The rating_key of the item to get.

Returns:
PlexPartialObject

The Plex item from the Plex Server.

Examples

>>> get_plex_item(rating_key=1)
...
Code.plex_api_helper.plex_listener()[source]

Listen for events from Plex server.

Send events to plex_listener_handler and errors to Log.Error.

Examples

>>> plex_listener()
...
Code.plex_api_helper.plex_listener_handler(data)[source]

Process events from plex_listener().

Check if we need to add an item to the queue. This is used to automatically add themes to items from the new Plex Movie agent, since metadata agents cannot extend it.

Parameters:
data : dict

Data received from the Plex server.

Examples

>>> plex_listener_handler(data={'type': 'timeline'})
...
Code.plex_api_helper.process_queue()[source]

Add items to the queue.

This is an endless loop to add items to the queue.

Examples

>>> process_queue()
...
Code.plex_api_helper.scheduled_update()[source]

Update all items in the Plex Server.

This is used to update all items in the Plex Server. It is called from a scheduled task.

See also

scheduled_tasks.setup_scheduling
The method where the scheduled task is configurerd.
scheduled_tasks.schedule_loop
The method that runs the pending scheduled tasks.

Examples

>>> scheduled_update()
Code.plex_api_helper.setup_plexapi()[source]

Create the Plex server object.

It is required to use PlexAPI in order to add theme music to movies, as the built-in methods for metadata agents do not work for movies. This method creates the server object.

Returns:
PlexServer

The PlexServer object.

Examples

>>> setup_plexapi()
...
Code.plex_api_helper.start_queue_threads()[source]

Start queue threads.

Start the queue threads based on the number of threads set in the preferences.

Examples

>>> start_queue_threads()
...
Code.plex_api_helper.update_plex_item(rating_key)[source]

Automated update of Plex item using only the rating key.

Given the rating key, this function will automatically handle collecting the required information to update the theme song, and any other metadata.

Parameters:
rating_key : int

The rating key of the item to be updated.

Returns:
pybool

True if the item was updated successfully, False otherwise.

Examples

>>> update_plex_item(rating_key=12345)
Code.plex_api_helper.upload_media(item, method, filepath=None, url=None)[source]

Upload media to the specified item.

Uploads art, poster, or theme to the item specified by the item.

Parameters:
item : PlexPartialObject

The Plex item to upload the theme to.

method : Callable

The method to use to upload the theme.

filepath : Optional[str]

The path to the theme song.

url : Optional[str]

The url to the theme song.

Returns:
pybool

True if the theme was uploaded successfully, False otherwise.

Examples

>>> upload_media(item=..., method=item.uploadArt, url=...)
>>> upload_media(item=..., method=item.uploadPoster, url=...)
>>> upload_media(item=..., method=item.uploadTheme, url=...)
...