#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Written by: Josh.5 Date: 5 April 2021, (10:00 PM) Copyright: Copyright (C) 2021 Josh Sunnex This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import logging from unmanic.libs.unplugins.settings import PluginSettings from plexapi.server import PlexServer # Configure plugin logger logger = logging.getLogger("Unmanic.Plugin.notify_plex") class Settings(PluginSettings): settings = { 'Plex URL': 'http://localhost:32400', 'Plex Token': '', 'Notify on Task Failure?': False, } def update_plex(plex_url, plex_token): plex = PlexServer(plex_url, plex_token) # Call to Plex to trigger an update plex.library.update() logger.info("Notifying Plex ({}) to update its library.".format(plex_url)) def on_postprocessor_task_results(data): """ Runner function - provides a means for additional postprocessor functions based on the task success. The 'data' object argument includes: task_processing_success - Boolean, did all task processes complete successfully. file_move_processes_success - Boolean, did all postprocessor movement tasks complete successfully. destination_files - List containing all file paths created by postprocessor file movements. source_data - Dictionary containing data pertaining to the original source file. :param data: :return: """ # Configure settings object (maintain compatibility with v1 plugins) if data.get('library_id'): settings = Settings(library_id=data.get('library_id')) else: settings = Settings() if not data.get('task_processing_success') and not settings.get_setting('Notify on Task Failure?'): return data plex_url = settings.get_setting('Plex URL') plex_token = settings.get_setting('Plex Token') update_plex(plex_url, plex_token) return data