Process new files

This commit is contained in:
hygienic-books 2022-03-22 02:36:33 +01:00
parent d4cdbb3606
commit 7bcf366581

View File

@ -325,15 +325,32 @@ if __name__ == '__main__':
watch_dir = config.get(section, "watch_dir") watch_dir = config.get(section, "watch_dir")
inotify_watch = setup_watch(watch_dir) inotify_watch = setup_watch(watch_dir)
output_dir = config.get(section, "output_dir")
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 ...")
while True: season_and_episode = get_season_and_episode(section, config, file_name)
time.sleep(0.2) nfo = generate_nfo(season_and_episode["title_str"], file_name)
for event in inotify_watch.read(): file_moved_to_target_dir = move_file_to_target_dir(
events = [str(flags) for flags in flags.from_mask(event.mask)] section,
if "flags.MOVED_TO" in events: config,
file_name = event.name file_name,
log.info(f"File '{file_name}' was moved to watch directory '{watch_dir}', processing ...") season_and_episode)
if file_moved_to_target_dir:
# TODO https://docs.python.org/3/library/xml.etree.elementtree.html write_nfo_to_disk(
# TODO generate xml nfo,
# TODO: Basic string manipulation via regex in options file file_moved_to_target_dir,
output_dir)