Compare commits
16 Commits
7bcf366581
...
master
Author | SHA1 | Date | |
---|---|---|---|
80db904a45 | |||
91370068e4 | |||
af1525a2c3 | |||
c147b56747 | |||
4118e4c781 | |||
1673cbe8bd | |||
a30a31a2fc | |||
7b3df48945 | |||
ab7cc7bab1 | |||
86339a88e4 | |||
1de24ee2d1 | |||
318e29da85 | |||
b0aafc4f95 | |||
a47faa90b9 | |||
834563bae1 | |||
78879b1724 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -238,3 +238,5 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# ---> kodi-nfo-feeder
|
||||||
|
config.ini
|
15
config.ini
15
config.ini
@@ -1,15 +0,0 @@
|
|||||||
[DEFAULT]
|
|
||||||
self_name = kodi-nfo-feeder
|
|
||||||
ignored_target_file_exts = .jpg, .jpeg, .png, .nfo
|
|
||||||
title_regex_search =
|
|
||||||
title_regex_replace =
|
|
||||||
|
|
||||||
[maus]
|
|
||||||
watch_dir = /var/lib/kodi-nfo-feeder/watch
|
|
||||||
output_dir = /var/lib/kodi-nfo-feeder/output
|
|
||||||
# title_regex_search = (\w)-(\s)
|
|
||||||
# title_regex_replace = \1 -\2
|
|
||||||
|
|
||||||
[otto]
|
|
||||||
watch_dir = /var/lib/kodi-nfo-feeder/test/watch
|
|
||||||
output_dir = /var/lib/kodi-nfo-feeder/test/output
|
|
17
examples/config.ini.example
Normal file
17
examples/config.ini.example
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[DEFAULT]
|
||||||
|
self_name = kodi-nfo-feeder
|
||||||
|
ignored_target_file_exts = .jpg, .jpeg, .png, .nfo
|
||||||
|
title_regex_search =
|
||||||
|
title_regex_replace =
|
||||||
|
do_seasons = yes
|
||||||
|
|
||||||
|
[maus]
|
||||||
|
watch_dir = /tmp/kodi-nfo-feeder/maus
|
||||||
|
output_dir = /srv/kodi/tv-shows/scraper-local/Die Sendung mit der Maus (1971)
|
||||||
|
title_regex_search = (\w)-(\s)
|
||||||
|
title_regex_replace = \1 -\2
|
||||||
|
do_seasons = yes
|
||||||
|
run_cmd = touch /srv/kodi/latest-state-change
|
||||||
|
kodi_jsonrpc_address = http://localhost:8080/jsonrpc
|
||||||
|
kodi_jsonrpc_username = username
|
||||||
|
kodi_jsonrpc_password = password
|
12
examples/kodi-nfo-feeder.service.example
Normal file
12
examples/kodi-nfo-feeder.service.example
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=NFO feeder service for Kodi's "local" scraper
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
Environment='PATH=/usr/local/sbin:/usr/local/bin:/usr/bin'
|
||||||
|
ExecStart=/opt/miniconda3/envs/kodi-nfo-feeder/bin/python /opt/python/kodi-nfo-feeder/dev/kodi-nfo-feeder.py
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@@ -1,5 +1,7 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
@@ -11,10 +13,8 @@ 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
|
|
||||||
# TODO Thread config sections
|
|
||||||
|
|
||||||
|
|
||||||
# Exit codes
|
# Exit codes
|
||||||
@@ -34,13 +34,19 @@ class CONST(object):
|
|||||||
{"key": "self_name", "value": "kodi-nfo-feeder"},
|
{"key": "self_name", "value": "kodi-nfo-feeder"},
|
||||||
{"key": "ignored_target_file_exts", "value": ".jpg, .jpeg, .png, .nfo"},
|
{"key": "ignored_target_file_exts", "value": ".jpg, .jpeg, .png, .nfo"},
|
||||||
{"key": "title_regex_search", "value": ""},
|
{"key": "title_regex_search", "value": ""},
|
||||||
{"key": "title_regex_replace", "value": ""}
|
{"key": "title_regex_replace", "value": ""},
|
||||||
|
{"key": "do_seasons", "value": "yes"}
|
||||||
]
|
]
|
||||||
CFG_KNOWN_SECTION = [
|
CFG_KNOWN_SECTION = [
|
||||||
{"key": "watch_dir", "is_mandatory": True},
|
{"key": "watch_dir", "is_mandatory": True},
|
||||||
{"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": "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"]]
|
||||||
|
|
||||||
@@ -59,6 +65,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +91,7 @@ p = inflect.engine()
|
|||||||
ini_defaults = []
|
ini_defaults = []
|
||||||
internal_defaults = {default["key"]: default["value"] for default in CONST.CFG_KNOWN_DEFAULTS}
|
internal_defaults = {default["key"]: default["value"] for default in CONST.CFG_KNOWN_DEFAULTS}
|
||||||
config = ConfigParser(defaults=internal_defaults)
|
config = ConfigParser(defaults=internal_defaults)
|
||||||
config.read(CONST.CFG_DEFAULT_FILENAME)
|
config.read(CONST.CFG_DEFAULT_ABS_PATH)
|
||||||
ignored_target_file_exts_str = config.get(config.default_section, "ignored_target_file_exts")
|
ignored_target_file_exts_str = config.get(config.default_section, "ignored_target_file_exts")
|
||||||
ignored_target_file_exts = re.split(r""",\s?|\s""", ignored_target_file_exts_str)
|
ignored_target_file_exts = re.split(r""",\s?|\s""", ignored_target_file_exts_str)
|
||||||
|
|
||||||
@@ -153,20 +160,32 @@ def validate_config_sections(
|
|||||||
|
|
||||||
|
|
||||||
def setup_watch(
|
def setup_watch(
|
||||||
watch_this: str) -> INotify:
|
csection_name: str,
|
||||||
|
config_obj: configparser.ConfigParser(),
|
||||||
|
inotify_obj: INotify) -> bool:
|
||||||
|
|
||||||
|
global wds
|
||||||
|
|
||||||
|
watch_this = config_obj.get(csection, "watch_dir")
|
||||||
|
|
||||||
if not os.path.exists(watch_this):
|
if not os.path.exists(watch_this):
|
||||||
os.makedirs(watch_this, exist_ok=False)
|
os.makedirs(watch_this, exist_ok=False)
|
||||||
inotify = INotify()
|
|
||||||
watch_flags = flags.MOVED_TO
|
watch_flags = flags.MOVED_TO
|
||||||
try:
|
try:
|
||||||
inotify.add_watch(watch_this, watch_flags)
|
log.debug(f"Watching for '[{csection_name}]' files moved to '{watch_this}' ...")
|
||||||
log.debug(f"Watching for files moved to '{watch_this}' ...")
|
wd_obj = inotify_obj.add_watch(watch_this, watch_flags)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
log.error(f"Watch directory '{watch_this}' does not exist. Please create it. Exiting 3 ...")
|
log.error(f"Section '[{csection_name}]' watch directory '{watch_this}' does not exist. Please create it. "
|
||||||
|
f"Exiting 3 ...")
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
else:
|
else:
|
||||||
return inotify
|
log.debug(f"Created watch descriptor ID {wd_obj} for '[{csection_name}]' watch directory '{watch_this}'.")
|
||||||
|
wds[wd_obj] = {
|
||||||
|
"watch_dir": watch_this,
|
||||||
|
"output_dir": config.get(csection, "output_dir"),
|
||||||
|
"section": csection_name
|
||||||
|
}
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def generate_nfo(
|
def generate_nfo(
|
||||||
@@ -187,26 +206,24 @@ def generate_nfo(
|
|||||||
|
|
||||||
|
|
||||||
def get_basic_cleaned_title(
|
def get_basic_cleaned_title(
|
||||||
section_name: str,
|
csection_name: str,
|
||||||
config_obj: configparser.ConfigParser(),
|
config_obj: configparser.ConfigParser(),
|
||||||
dirty_title: str) -> str:
|
dirty_title: str) -> str:
|
||||||
|
|
||||||
regex_search_pattern = config_obj.get(section_name, "title_regex_search")
|
regex_search_pattern = config_obj.get(csection_name, "title_regex_search")
|
||||||
regex_replace_pattern = config_obj.get(section_name, "title_regex_replace")
|
regex_replace_pattern = config_obj.get(csection_name, "title_regex_replace")
|
||||||
if regex_search_pattern:
|
if regex_search_pattern:
|
||||||
log.debug(regex_search_pattern)
|
|
||||||
log.debug(f"Doing basic title cleaning ...")
|
log.debug(f"Doing basic title cleaning ...")
|
||||||
pattern = re.compile(regex_search_pattern)
|
pattern = re.compile(regex_search_pattern)
|
||||||
clean_title = re.sub(pattern, regex_replace_pattern, dirty_title)
|
clean_title = re.sub(pattern, regex_replace_pattern, dirty_title)
|
||||||
log.debug(f"""Title's now "{clean_title}".""")
|
log.debug(f"""Title's now "{clean_title}".""")
|
||||||
quit()
|
|
||||||
return clean_title
|
return clean_title
|
||||||
else:
|
else:
|
||||||
return dirty_title
|
return dirty_title
|
||||||
|
|
||||||
|
|
||||||
def get_season_and_episode(
|
def get_season_and_episode(
|
||||||
section_name: str,
|
csection_name: str,
|
||||||
config_obj: configparser.ConfigParser(),
|
config_obj: configparser.ConfigParser(),
|
||||||
raw_file_name: str) -> dict:
|
raw_file_name: str) -> dict:
|
||||||
|
|
||||||
@@ -215,20 +232,28 @@ def get_season_and_episode(
|
|||||||
ext = file_name_ext_split[1]
|
ext = file_name_ext_split[1]
|
||||||
season_episode = re.split("[S|E]", season_ep_str[0])
|
season_episode = re.split("[S|E]", season_ep_str[0])
|
||||||
season = f"Season {season_episode[1]}"
|
season = f"Season {season_episode[1]}"
|
||||||
title = season_ep_str[1]
|
try:
|
||||||
basic_cleaned_title = get_basic_cleaned_title(section_name, config_obj, title)
|
title = season_ep_str[1]
|
||||||
|
except IndexError:
|
||||||
|
log.warning(f"File name '{raw_file_name}' is not following expected format. The excepted format "
|
||||||
|
f"is a season-and-episode string followed by space-slash-space and and arbitrary sequence "
|
||||||
|
f"of characters suffixed with a file extension e.g. "
|
||||||
|
f"'S2022E2022032001 - This is a Title.mp4'. Skipping further file processing ...")
|
||||||
|
return {}
|
||||||
|
else:
|
||||||
|
basic_cleaned_title = get_basic_cleaned_title(csection_name, config_obj, title)
|
||||||
|
|
||||||
got_season_and_episode = {
|
got_season_and_episode = {
|
||||||
"season_str": season,
|
"season_str": season,
|
||||||
"title_str": basic_cleaned_title,
|
"title_str": basic_cleaned_title,
|
||||||
"season_ep_list": season_ep_str,
|
"season_ep_list": season_ep_str,
|
||||||
"ext": ext
|
"ext": ext
|
||||||
}
|
}
|
||||||
log.debug(f"""Identified {got_season_and_episode["season_str"]}, """
|
log.debug(f"""Identified {got_season_and_episode["season_str"]}, """
|
||||||
f"""title "{got_season_and_episode["title_str"]}" """
|
f"""title "{got_season_and_episode["title_str"]}" """
|
||||||
f"and episode object {season_ep_str} "
|
f"and episode object {season_ep_str} "
|
||||||
f"with extension '{ext}'.")
|
f"with extension '{ext}'.")
|
||||||
return got_season_and_episode
|
return got_season_and_episode
|
||||||
|
|
||||||
|
|
||||||
def get_target_file_list(
|
def get_target_file_list(
|
||||||
@@ -243,37 +268,40 @@ def get_target_file_list(
|
|||||||
|
|
||||||
|
|
||||||
def move_file_to_target_dir(
|
def move_file_to_target_dir(
|
||||||
section_name: str,
|
csection_name: str,
|
||||||
config_obj: configparser.ConfigParser(),
|
config_obj: configparser.ConfigParser(),
|
||||||
raw_file_name: str,
|
raw_file_name: str,
|
||||||
season_ep_str: dict) -> str:
|
season_ep_str: dict,
|
||||||
|
output_dir_name: str) -> str:
|
||||||
|
|
||||||
this_watch_dir = config_obj.get(section_name, "watch_dir")
|
this_watch_dir = config_obj.get(csection_name, "watch_dir")
|
||||||
source_abs_path = os.path.join(this_watch_dir, raw_file_name)
|
source_abs_path = os.path.join(this_watch_dir, raw_file_name)
|
||||||
|
|
||||||
target_dir = config_obj.get(section_name, "output_dir")
|
target_dir = output_dir_name
|
||||||
target_file_list = get_target_file_list(target_dir)
|
target_file_list = get_target_file_list(target_dir)
|
||||||
|
|
||||||
target_file_name = season_ep_str["season_ep_list"][0]
|
target_file_name = season_ep_str["season_ep_list"][0]
|
||||||
target_ext = season_ep_str["ext"]
|
target_ext = season_ep_str["ext"]
|
||||||
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
|
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
|
||||||
|
|
||||||
if target_file_name_plus_ext in target_file_list:
|
while target_file_name_plus_ext in target_file_list:
|
||||||
log.debug(f"File name already exists in target dir, incrementing counter ...")
|
log.debug(f"Intended file name already exists in target dir, incrementing counter suffix ...")
|
||||||
episode_minus_counter = target_file_name[:-2]
|
episode_minus_counter = target_file_name[:-2]
|
||||||
counter = target_file_name[-2:]
|
counter = target_file_name[-2:]
|
||||||
counter_length = len(counter)
|
counter_length = len(counter)
|
||||||
counter_stripped = int(counter.lstrip("0"))
|
counter_stripped = int(counter.lstrip("0"))
|
||||||
counter_stripped += 1
|
counter_stripped += 1
|
||||||
target_file_name = f"{episode_minus_counter}{str(counter_stripped).zfill(counter_length)}"
|
target_file_name = f"{episode_minus_counter}{str(counter_stripped).zfill(counter_length)}"
|
||||||
|
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
|
||||||
|
|
||||||
target_abs_path = os.path.join(target_dir, f"{target_file_name}{target_ext}")
|
target_abs_path = os.path.join(target_dir, f"{target_file_name}{target_ext}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.debug(f"Moving '{source_abs_path}' to '{target_abs_path}' ...")
|
log.debug(f"Moving '{source_abs_path}' to '{target_abs_path}' ...")
|
||||||
# shutil.move(source_abs_path, target_abs_path)
|
shutil.move(source_abs_path, target_abs_path)
|
||||||
except OSError as ose:
|
except OSError as move_ose:
|
||||||
log.error(f"Failed moving file with an OSError:\n"
|
log.error(f"Failed moving file with an OSError:\n"
|
||||||
f"{ose}\n"
|
f"{move_ose}\n"
|
||||||
f"Continuing file watch ...")
|
f"Continuing file watch ...")
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
@@ -300,15 +328,77 @@ def write_nfo_to_disk(
|
|||||||
log.debug(f"Writing NFO data to '{target_abs_path}':\n"
|
log.debug(f"Writing NFO data to '{target_abs_path}':\n"
|
||||||
f"""{nfo_str.decode("UTF-8")}""")
|
f"""{nfo_str.decode("UTF-8")}""")
|
||||||
nfo_file.write(nfo_str)
|
nfo_file.write(nfo_str)
|
||||||
except OSError as ose:
|
except OSError as nfo_ose:
|
||||||
log.error(f"Failed writing NFO file '{target_abs_path}' with an OSError:\n"
|
log.error(f"Failed writing NFO file '{target_abs_path}' with an OSError:\n"
|
||||||
f"{ose}\n"
|
f"{nfo_ose}\n"
|
||||||
f"Continuing file watch ...")
|
f"Continuing file watch ...")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
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):
|
||||||
@@ -319,38 +409,67 @@ if __name__ == '__main__':
|
|||||||
f"{CONST.CFG_MANDATORY} set. Exiting 2 ...")
|
f"{CONST.CFG_MANDATORY} set. Exiting 2 ...")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
inotify = INotify()
|
||||||
|
wds = {}
|
||||||
log.debug(f"Iterating over config sections ...")
|
log.debug(f"Iterating over config sections ...")
|
||||||
for section in config.sections():
|
|
||||||
log.debug(f"Processing section '[{section}]' ...")
|
|
||||||
|
|
||||||
watch_dir = config.get(section, "watch_dir")
|
for csection in config.sections():
|
||||||
inotify_watch = setup_watch(watch_dir)
|
log.debug(f"Processing section '[{csection}]' ...")
|
||||||
output_dir = config.get(section, "output_dir")
|
setup_watch(csection, config, inotify)
|
||||||
try:
|
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
|
||||||
except OSError as ose:
|
|
||||||
log.error(f"Unable to create section '[{section}]' output dir '{output_dir}' with an OSError:\n"
|
|
||||||
f"{ose}\n"
|
|
||||||
f"Exiting 4 ...")
|
|
||||||
sys.exit(4)
|
|
||||||
else:
|
|
||||||
while True:
|
|
||||||
time.sleep(0.2)
|
|
||||||
for event in inotify_watch.read():
|
|
||||||
events = [str(flags) for flags in flags.from_mask(event.mask)]
|
|
||||||
if "flags.MOVED_TO" in events:
|
|
||||||
file_name = event.name
|
|
||||||
log.info(f"File '{file_name}' was moved to watch directory '{watch_dir}', processing ...")
|
|
||||||
|
|
||||||
season_and_episode = get_season_and_episode(section, config, file_name)
|
while True:
|
||||||
nfo = generate_nfo(season_and_episode["title_str"], file_name)
|
time.sleep(0.2)
|
||||||
file_moved_to_target_dir = move_file_to_target_dir(
|
for event in inotify.read():
|
||||||
section,
|
events = [str(flags) for flags in flags.from_mask(event.mask)]
|
||||||
config,
|
if "flags.MOVED_TO" in events:
|
||||||
file_name,
|
file_name = event.name
|
||||||
season_and_episode)
|
watch_dir_config = wds[event.wd]
|
||||||
if file_moved_to_target_dir:
|
watch_dir = watch_dir_config["watch_dir"]
|
||||||
write_nfo_to_disk(
|
output_dir = watch_dir_config["output_dir"]
|
||||||
nfo,
|
section_name = watch_dir_config["section"]
|
||||||
file_moved_to_target_dir,
|
log.info(f"File '{file_name}' was moved to watch directory "
|
||||||
output_dir)
|
f"""'{watch_dir}', processing ...""")
|
||||||
|
|
||||||
|
season_and_episode = get_season_and_episode(section_name, config, file_name)
|
||||||
|
if not season_and_episode:
|
||||||
|
break
|
||||||
|
|
||||||
|
if config.getboolean(section_name, "do_seasons"):
|
||||||
|
season_str = season_and_episode["season_str"]
|
||||||
|
log.debug(f"Changing output to season-specific dir '{season_str}' ...")
|
||||||
|
output_dir = os.path.join(output_dir, season_str)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
except OSError as ose:
|
||||||
|
log.error(f"Unable to create section '[{section_name}]' output dir "
|
||||||
|
f"'{output_dir}' with an OSError:\n"
|
||||||
|
f"{ose}\n"
|
||||||
|
f"Exiting 4 ...")
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
|
nfo = generate_nfo(season_and_episode["title_str"], file_name)
|
||||||
|
file_moved_to_target_dir = move_file_to_target_dir(
|
||||||
|
section_name,
|
||||||
|
config,
|
||||||
|
file_name,
|
||||||
|
season_and_episode,
|
||||||
|
output_dir)
|
||||||
|
if file_moved_to_target_dir:
|
||||||
|
write_nfo_to_disk(
|
||||||
|
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)
|
@@ -2,3 +2,4 @@ rich
|
|||||||
inflect
|
inflect
|
||||||
inotify_simple
|
inotify_simple
|
||||||
lxml
|
lxml
|
||||||
|
requests
|
@@ -4,8 +4,14 @@
|
|||||||
#
|
#
|
||||||
# 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
|
||||||
@@ -14,5 +20,9 @@ lxml==4.8.0
|
|||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
pygments==2.11.2
|
pygments==2.11.2
|
||||||
# via rich
|
# via rich
|
||||||
rich==12.0.0
|
requests==2.27.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
|
rich==12.0.1
|
||||||
|
# via -r requirements.in
|
||||||
|
urllib3==1.26.9
|
||||||
|
# via requests
|
||||||
|
Reference in New Issue
Block a user