Compare commits

..

9 Commits

5 changed files with 60 additions and 34 deletions

2
.gitignore vendored
View File

@@ -238,3 +238,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# ---> kodi-nfo-feeder
config.ini

View File

@@ -1,17 +0,0 @@
[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 = /var/lib/kodi-nfo-feeder/watch
output_dir = /var/lib/kodi-nfo-feeder/output
title_regex_search =
title_regex_replace =
do_seasons = yes
run_cmd =
kodi_jsonrpc_address = http://localhost:8080/jsonrpc
kodi_jsonrpc_username =
kodi_jsonrpc_password =

View 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

View 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

View File

@@ -91,7 +91,7 @@ p = inflect.engine()
ini_defaults = []
internal_defaults = {default["key"]: default["value"] for default in CONST.CFG_KNOWN_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 = re.split(r""",\s?|\s""", ignored_target_file_exts_str)
@@ -232,7 +232,15 @@ def get_season_and_episode(
ext = file_name_ext_split[1]
season_episode = re.split("[S|E]", season_ep_str[0])
season = f"Season {season_episode[1]}"
try:
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 = {
@@ -276,14 +284,16 @@ def move_file_to_target_dir(
target_ext = season_ep_str["ext"]
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
if target_file_name_plus_ext in target_file_list:
log.debug(f"Intended file name already exists in target dir, incrementing counter ...")
while target_file_name_plus_ext in target_file_list:
log.debug(f"Intended file name already exists in target dir, incrementing counter suffix ...")
episode_minus_counter = target_file_name[:-2]
counter = target_file_name[-2:]
counter_length = len(counter)
counter_stripped = int(counter.lstrip("0"))
counter_stripped += 1
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}")
try:
@@ -417,11 +427,13 @@ if __name__ == '__main__':
watch_dir = watch_dir_config["watch_dir"]
output_dir = watch_dir_config["output_dir"]
section_name = watch_dir_config["section"]
log.debug(f"Watch dir config: {watch_dir_config}")
log.info(f"File '{file_name}' was moved to watch directory "
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}' ...")