Guest User

FileBot - BatchOperations

a guest
Aug 13th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. """
  2. Run all FileBot argument .txt files in '_BatchOperations_' folder (https://www.filebot.net/forums/viewtopic.php?f=4&t=3244)
  3.  
  4. 1) Place this script in the same folder as 'filebot.exe'
  5. 2) Run it to create the '_BatchOperations_' directory and a '.repeat' file
  6. 3) Add .txt files to the '_BatchOperations_' folder, each containing valid FileBot arguments (Refer to link above).
  7. 4) Run this script again, and it will scan the '_BatchOperations_' folder and run FileBot once for each .txt file found.
  8.  
  9. * Optional: Automatically repeat the operation
  10.    0 == Repeat disabled (Default)
  11.    If you'd like to re-run the filebot commands every X seconds, you can change the '0' in the '.repeat' file,
  12.    which is inside the '_BatchOperations_' folder. Changing the value to anything >0 (numbers only) will enable repeats every X second.
  13.    * If using this script as a .pyw or .exe, then you'll have to use TaskManager to kill the program
  14.    
  15. """
  16.  
  17. from pathlib import Path
  18. import subprocess
  19. import sys
  20. import time
  21.  
  22. # ===== Dependencies =====
  23. filebot_exe = Path('./filebot.exe').resolve()
  24. batch_folder = filebot_exe.parents[0] / './_BatchOperations_/'
  25. repeat_file = batch_folder / './.repeat'
  26.  
  27. batch_folder.mkdir(exist_ok=True, parents=True)
  28. if repeat_file.exists() is False:
  29.     print(f"Creating .repeat file: {repeat_file}...")
  30.     with repeat_file.open('w') as file:
  31.         file.write('0')
  32.    
  33. # ====== Main =====
  34. while True:
  35.     filebot_args = list(batch_folder.glob('*.txt'))
  36.     if len(filebot_args) >= 1:
  37.         for file in filebot_args:
  38.             print(f"Running argument file: {file}")
  39.             subprocess.run([str(filebot_exe), f"@{str(file)}"], creationflags=0x08000000)
  40.     else:
  41.         print('No argument files found, exiting...')
  42.         break
  43.        
  44.     try:
  45.         with repeat_file.open('r') as repeat:
  46.             sleep_time = int(repeat.read())
  47.             if sleep_time == 0:
  48.                 print('Repeat disabled, exiting...')
  49.                 break
  50.             elif sleep_time < 0:
  51.                 print(f"Sleep time must be a positive number not \'{sleep_time}\', exiting...")
  52.                 break
  53.             else:
  54.                 print(f"Sleeping for {sleep_time} seconds")
  55.                 time.sleep(sleep_time)
  56.        
  57.     except ValueError as e:
  58.         print(f"File does not contain a valid number, exiting...\n\n{e}")
  59.         break
  60.  
  61. sys.exit()
  62.  
Add Comment
Please, Sign In to add comment