diff --git a/filebot.py b/filebot.py index fee0bee..ed88aba 100644 --- a/filebot.py +++ b/filebot.py @@ -1,14 +1,26 @@ from glob import glob import shutil import os +from pathlib import Path +import subprocess +import re + +source_path = Path('/mnt/Download/finished/') +dest_path = '/mnt/Download/PostProcess/' + +for root, dirs, files in os.walk(source_path): + for dir in dirs: + for file in files: + rar_file = glob(f"{os.path.join(root, '')}*rar") + if rar_file: + subprocess.run(["/usr/bin/unrar", 'e', rar_file[0], '-idq', '']) + +for root, dirs, files in os.walk(source_path): + for dir in dirs: + for file in files: + if re.search(r'\.r\d{2,3}', file) or file.endswith('.rar') or file.endswith('.sfv') or file.endswith('.nfo'): + os.remove(os.path.join(root, file)) -rar_file = glob(f"{os.path.join(rls.ContentPath, '')}*rar") -if rar_file: - # Now verify that unrar is installed - unrar_sys_package = '/usr/bin/unrar' - if os.path.isfile(unrar_sys_package): - console.print("Found rar files, extracting the files now", style="bold red") - - # run the system package unrar and save the extracted file to its parent dir - subprocess.run([unrar_sys_package, 'e', rar_file[0], '-idq', rls.ContentPath]) \ No newline at end of file +for src_folder in source_path.iterdir(): + shutil.move(src_folder, dest_path) \ No newline at end of file