This commit is contained in:
Gregory Salaun 2022-01-26 17:50:28 +07:00
parent 0199804d81
commit a4e82aa861

View File

@ -1,14 +1,26 @@
from glob import glob from glob import glob
import shutil import shutil
import os import os
from pathlib import Path
import subprocess
import re
source_path = Path('/mnt/Download/finished/')
dest_path = '/mnt/Download/PostProcess/'
rar_file = glob(f"{os.path.join(rls.ContentPath, '')}*rar") 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: if rar_file:
# Now verify that unrar is installed subprocess.run(["/usr/bin/unrar", 'e', rar_file[0], '-idq', ''])
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 for root, dirs, files in os.walk(source_path):
subprocess.run([unrar_sys_package, 'e', rar_file[0], '-idq', rls.ContentPath]) 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))
for src_folder in source_path.iterdir():
shutil.move(src_folder, dest_path)