FileBotROuGGy/filebot.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-01-26 17:54:29 +07:00
#!/usr/bin/python3
2022-01-26 17:13:42 +07:00
from glob import glob
import shutil
import os
2022-01-26 17:50:28 +07:00
from pathlib import Path
import subprocess
import re
2022-01-26 17:13:42 +07:00
2022-01-26 17:50:28 +07:00
source_path = Path('/mnt/Download/finished/')
dest_path = '/mnt/Download/PostProcess/'
2022-01-26 17:13:42 +07:00
2022-01-26 18:42:49 +07:00
section_folders = ['4K-Movies', '4K-Series', 'Movies', 'Series']
2022-01-26 18:21:52 +07:00
# source_path = 'C:/Test/finished'
# dest_path = "C:/Test/PostProcess"
2022-01-26 17:52:58 +07:00
print("Checking if rar files and unraring...")
2022-01-26 17:50:28 +07:00
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', ''])
2022-01-26 17:13:42 +07:00
2022-01-26 18:48:08 +07:00
print("Deleting rar, sfv, nfo files...")
for root, dirs, files in os.walk(source_path):
for dir in dirs:
if re.search('sample', dir, re.IGNORECASE) or re.search('proof', dir, re.IGNORECASE):
shutil.rmtree(dir)
2022-01-26 17:50:28 +07:00
2022-01-26 18:21:52 +07:00
for root, dirs, files in os.walk(source_path):
for dir in dirs:
if dir not in section_folders:
match = re.search(r'.*\/(.*)', root)
section_path = match.group(1)
shutil.move(os.path.join(root, dir), os.path.join(dest_path, section_path))