Compare commits
No commits in common. "86339a88e4ccdbd00f028f9141f7a0d21982b142" and "834563bae12daf4641c58c7311fa030fcc1afe27" have entirely different histories.
86339a88e4
...
834563bae1
12
config.ini
12
config.ini
@ -8,10 +8,10 @@ do_seasons = yes
|
|||||||
[maus]
|
[maus]
|
||||||
watch_dir = /var/lib/kodi-nfo-feeder/watch
|
watch_dir = /var/lib/kodi-nfo-feeder/watch
|
||||||
output_dir = /var/lib/kodi-nfo-feeder/output
|
output_dir = /var/lib/kodi-nfo-feeder/output
|
||||||
title_regex_search =
|
title_regex_search = (\w)-(\s)
|
||||||
title_regex_replace =
|
title_regex_replace = \1 -\2
|
||||||
do_seasons = yes
|
do_seasons = yes
|
||||||
run_cmd =
|
|
||||||
kodi_jsonrpc_address = http://localhost:8080/jsonrpc
|
[otto]
|
||||||
kodi_jsonrpc_username =
|
watch_dir = /var/lib/kodi-nfo-feeder/test/watch
|
||||||
kodi_jsonrpc_password =
|
output_dir = /var/lib/kodi-nfo-feeder/test/output
|
@ -1,7 +1,5 @@
|
|||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
@ -13,8 +11,9 @@ import inflect
|
|||||||
from inotify_simple import INotify, flags
|
from inotify_simple import INotify, flags
|
||||||
import lxml.etree
|
import lxml.etree
|
||||||
import lxml.builder
|
import lxml.builder
|
||||||
import requests
|
|
||||||
from requests.auth import HTTPBasicAuth
|
|
||||||
|
# TODO Create season subdir if it doesn't exist
|
||||||
|
|
||||||
|
|
||||||
# Exit codes
|
# Exit codes
|
||||||
@ -42,11 +41,7 @@ class CONST(object):
|
|||||||
{"key": "output_dir", "is_mandatory": True},
|
{"key": "output_dir", "is_mandatory": True},
|
||||||
{"key": "title_regex_search", "is_mandatory": False},
|
{"key": "title_regex_search", "is_mandatory": False},
|
||||||
{"key": "title_regex_replace", "is_mandatory": False},
|
{"key": "title_regex_replace", "is_mandatory": False},
|
||||||
{"key": "do_seasons", "is_mandatory": False},
|
{"key": "do_seasons", "is_mandatory": False}
|
||||||
{"key": "run_cmd", "is_mandatory": False},
|
|
||||||
{"key": "kodi_jsonrpc_address", "is_mandatory": False},
|
|
||||||
{"key": "kodi_jsonrpc_username", "is_mandatory": False},
|
|
||||||
{"key": "kodi_jsonrpc_password", "is_mandatory": False}
|
|
||||||
]
|
]
|
||||||
CFG_MANDATORY = [section_cfg["key"] for section_cfg in CFG_KNOWN_SECTION if section_cfg["is_mandatory"]]
|
CFG_MANDATORY = [section_cfg["key"] for section_cfg in CFG_KNOWN_SECTION if section_cfg["is_mandatory"]]
|
||||||
|
|
||||||
@ -65,7 +60,6 @@ logging.basicConfig(
|
|||||||
log = logging.getLogger("rich")
|
log = logging.getLogger("rich")
|
||||||
# Our own code logs with this level
|
# Our own code logs with this level
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
logging.getLogger("urllib3.connectionpool").setLevel(logging.WARNING)
|
|
||||||
install(show_locals=True)
|
install(show_locals=True)
|
||||||
|
|
||||||
|
|
||||||
@ -327,68 +321,6 @@ def write_nfo_to_disk(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def kodi_library_update(
|
|
||||||
csection_name: str,
|
|
||||||
config_obj: configparser.ConfigParser()) -> bool:
|
|
||||||
|
|
||||||
kodi_jsonrpc_address = config_obj.get(csection_name, "kodi_jsonrpc_address")
|
|
||||||
kodi_jsonrpc_username = config_obj.get(csection_name, "kodi_jsonrpc_username") if \
|
|
||||||
config.has_option(csection_name, "kodi_jsonrpc_username") else None
|
|
||||||
kodi_jsonrpc_password = config_obj.get(csection_name, "kodi_jsonrpc_password") if \
|
|
||||||
config.has_option(csection_name, "kodi_jsonrpc_password") else None
|
|
||||||
|
|
||||||
require_auth = False
|
|
||||||
if (kodi_jsonrpc_username and not kodi_jsonrpc_password) or \
|
|
||||||
(not kodi_jsonrpc_username and kodi_jsonrpc_password):
|
|
||||||
log.warning(f"Please make sure that both a Kodi username /and/ and password are set via "
|
|
||||||
f"the 'kodi_jsonrpc_username' and 'kodi_jsonrpc_password' config options, respectively. "
|
|
||||||
f"If Kodi's web interface is configured to not require authentication please set "
|
|
||||||
f"both 'kodi_jsonrpc_username' and 'kodi_jsonrpc_password' to empty values (or simply remove "
|
|
||||||
f"both lines from the config file).\n"
|
|
||||||
f"Skipping Kodi video library reload ...")
|
|
||||||
return False
|
|
||||||
elif kodi_jsonrpc_username and kodi_jsonrpc_password:
|
|
||||||
require_auth = True
|
|
||||||
|
|
||||||
json_payload_str = {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": "VideoLibrary.Scan",
|
|
||||||
"id": f"""{config_obj.get(csection_name, "self_name")}_trigger-vid-lib-scan"""
|
|
||||||
}
|
|
||||||
json_payload = json.dumps(json_payload_str)
|
|
||||||
req_header = {"content-type": "application/json"}
|
|
||||||
s = requests.Session()
|
|
||||||
req = requests.Request(
|
|
||||||
"POST",
|
|
||||||
kodi_jsonrpc_address,
|
|
||||||
data=json_payload,
|
|
||||||
auth=requests.auth.HTTPBasicAuth(
|
|
||||||
kodi_jsonrpc_username,
|
|
||||||
kodi_jsonrpc_password
|
|
||||||
) if require_auth else None,
|
|
||||||
headers=req_header)
|
|
||||||
prepped = req.prepare()
|
|
||||||
newline = "\n"
|
|
||||||
log.debug(f"Triggering Kodi library update ...")
|
|
||||||
log.debug(f"Request method: {req.method}\n"
|
|
||||||
f"URL: {req.url}\n"
|
|
||||||
f"""{newline.join(f"Header '{header}': '{value}'" for header, value in list(req.headers.items()))}\n"""
|
|
||||||
f"Payload: {json_payload}")
|
|
||||||
try:
|
|
||||||
with s.send(prepped) as s:
|
|
||||||
got_json_response = s.content
|
|
||||||
if s.status_code == requests.codes.ok:
|
|
||||||
log.debug(f"Kodi library update successful")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
log.error(f"Request failed, response code was {s.status_code}:\n"
|
|
||||||
f"{json.loads(got_json_response)}")
|
|
||||||
return False
|
|
||||||
except requests.exceptions.ConnectionError:
|
|
||||||
log.info(f"Kodi JSON-RPC endpoint {kodi_jsonrpc_address} is not currently connectable.")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
validate_default_section(config)
|
validate_default_section(config)
|
||||||
if config_has_valid_section(config):
|
if config_has_valid_section(config):
|
||||||
@ -448,16 +380,3 @@ if __name__ == '__main__':
|
|||||||
nfo,
|
nfo,
|
||||||
file_moved_to_target_dir,
|
file_moved_to_target_dir,
|
||||||
output_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)
|
|
@ -1,5 +1,4 @@
|
|||||||
rich
|
rich
|
||||||
inflect
|
inflect
|
||||||
inotify_simple
|
inotify_simple
|
||||||
lxml
|
lxml
|
||||||
requests
|
|
@ -4,14 +4,8 @@
|
|||||||
#
|
#
|
||||||
# pip-compile
|
# pip-compile
|
||||||
#
|
#
|
||||||
certifi==2021.10.8
|
|
||||||
# via requests
|
|
||||||
charset-normalizer==2.0.12
|
|
||||||
# via requests
|
|
||||||
commonmark==0.9.1
|
commonmark==0.9.1
|
||||||
# via rich
|
# via rich
|
||||||
idna==3.3
|
|
||||||
# via requests
|
|
||||||
inflect==5.4.0
|
inflect==5.4.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
inotify-simple==1.3.5
|
inotify-simple==1.3.5
|
||||||
@ -20,9 +14,5 @@ lxml==4.8.0
|
|||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
pygments==2.11.2
|
pygments==2.11.2
|
||||||
# via rich
|
# via rich
|
||||||
requests==2.27.1
|
rich==12.0.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
rich==12.0.1
|
|
||||||
# via -r requirements.in
|
|
||||||
urllib3==1.26.9
|
|
||||||
# via requests
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user