From 1de24ee2d1cf863cf4263b2fd4ea5f00c5e4787f Mon Sep 17 00:00:00 2001
From: hygienic-books <hygienic-books@tentic.net>
Date: Wed, 23 Mar 2022 13:14:13 +0100
Subject: [PATCH] Run arbitrary command after file's been put in place

---
 kodi-nfo-feeder.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/kodi-nfo-feeder.py b/kodi-nfo-feeder.py
index 572ba53..64450dd 100644
--- a/kodi-nfo-feeder.py
+++ b/kodi-nfo-feeder.py
@@ -1,5 +1,7 @@
+import json
 import os
 import logging
+import subprocess
 import sys
 import time
 import re
@@ -449,3 +451,16 @@ if __name__ == '__main__':
                         nfo,
                         file_moved_to_target_dir,
                         output_dir)
+
+                run_cmd = config.get(section_name, "run_cmd") if config.has_option(section_name, "run_cmd") else False
+                if run_cmd:
+                    log.debug(f"Executing post-move command: {run_cmd} ...")
+                    run_cmd_result = subprocess.getstatusoutput(run_cmd)
+                    run_cmd_exit_code = run_cmd_result[0]
+                    run_cmd_output = run_cmd_result[1]
+                    if run_cmd_exit_code != 0:
+                        log.warning(f"Post-move command failed with exit code {run_cmd_exit_code}:\n"
+                                    f"{run_cmd_output}")
+
+                if config.has_option(section_name, "kodi_jsonrpc_address"):
+                    kodi_library_update(section_name, config)
\ No newline at end of file