thank you for the info, I wrote a script to handle it with OMV and Docker, so both JDownloader and Filebot can run in their own container:
python: Select all
import os
import logging
import subprocess
import re
import shutil
FOLDER_PATH = '/srv/dev-disk-by-uuid-5ce16d9f-6b80-4417-a53e-f0806c9ed406/downloads/jdownloader'
DESTINATION_PATH = '/srv/dev-disk-by-uuid-5ce16d9f-6b80-4417-a53e-f0806c9ed406/downloads/toArchive/ITALIAN'
FILE_EXTENSIONS = ('.mkv', '.mp4', '.avi')
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def process_files_in_folder(folder_path):
moved_files = [] # To keep track of moved files
for root, _, files in os.walk(folder_path):
for filename in files:
if any(filename.endswith(ext) for ext in FILE_EXTENSIONS):
file_path = os.path.join(root, filename)
if process_file(file_path): # Check if the file was moved
moved_files.append(file_path)
return moved_files
def process_file(file_path):
logger.info(f"Processing file: {file_path}")
if "TMDBID-" in file_path:
id_start = file_path.index("TMDBID-") + len("TMDBID-")
movie_id = re.search(r"TMDBID-(\d+)", file_path).group(1)
logger.info(f"Processing movie ID: {movie_id}")
move_file_and_folder(file_path, DESTINATION_PATH)
return True
elif "ID-" in file_path:
id_start = file_path.index("ID-") + len("ID-")
show_id = re.search(r"ID-(\d+)", file_path).group(1)
logger.info(f"Processing TV show ID: {show_id}")
move_file_and_folder(file_path, DESTINATION_PATH)
return True
return False
def move_file_and_folder(source, destination_folder):
try:
parent_folder = os.path.dirname(source)
# Replace "ID-" with "TVDBID-" only if it's not part of a longer word
parent_folder = re.sub(r'\bID-', 'TVDBID-', parent_folder)
destination_parent = os.path.join(destination_folder, os.path.basename(parent_folder))
os.makedirs(destination_parent, exist_ok=True)
filename = os.path.basename(source)
destination_path = os.path.join(destination_parent, filename)
shutil.move(source, destination_path)
logger.info(f"File and its parent folder moved from {source} to {destination_path}")
except shutil.Error as e:
logger.error(f"File and folder move failed: {e}")
def remove_empty_subfolders(root_folder):
for folder_path, _, _ in os.walk(root_folder, topdown=False):
if folder_path != root_folder: # Skip the root folder itself
try:
os.rmdir(folder_path)
logger.info(f"Empty subfolder removed: {folder_path}")
except OSError as e:
logger.error(f"Error while removing subfolder: {folder_path} - {e}")
def run_command(command):
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
logger.error(f"Command execution failed: {e}")
if __name__ == "__main__":
logger.info("Starting script...")
moved_files = process_files_in_folder(FOLDER_PATH)
logger.info(f"Number of moved files: {len(moved_files)}")
if moved_files:
remove_empty_subfolders(FOLDER_PATH)
logger.info("Running Docker command...")
docker_command = "docker exec filebot-node ./opt/filebot-node/task 0"
run_command(docker_command)
logger.info("Running rclone move command...")
rclone_command = (
"flock -n /tmp/rclone_lockfile.lock rclone move "
"/mnt/workingfolder/toWikiBox1 wikibox1:/multimedia/library -v --progress "
"--transfers 1 --delete-empty-src-dirs "
"--log-file=/mnt/workingfolder/transferLogs/move_MANUAL.txt"
)
run_command(rclone_command)
logger.info("Script finished.")