Advertisement
Guest User

Untitled

a guest
Oct 29th, 2024
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. import os
  2. import time
  3. import obspython as obs
  4. import urllib.request
  5. import urllib.error
  6.  
  7. MATCH_COUNT = 4 # Change to add more matches
  8. patterns = {}
  9.  
  10. def script_description():
  11.     return "Moves a file when filename matches Match N to Path N\nMade by Sateviss :chatting:"
  12.  
  13. # Hook to connect recording stop signal
  14. def script_load(settings):
  15.     """Hook stop recording signal on plugin load."""
  16.     signal_handler = obs.obs_output_get_signal_handler(
  17.         obs.obs_frontend_get_recording_output()
  18.     )
  19.     obs.signal_handler_connect(signal_handler, "stop", signal_handler_function)
  20.     print("Attached handler")
  21.    
  22. def script_update(settings):
  23.     global MATCH_COUNT
  24.     global patterns
  25.  
  26.     for i in range(MATCH_COUNT):
  27.         key = obs.obs_data_get_string(settings, f"match{i}")
  28.         val = obs.obs_data_get_string(settings, f"path{i}")
  29.         patterns.update({key:val})
  30.         print(f"Loaded matcher {i}:", key, val)
  31.  
  32. def script_properties():
  33.     global MATCH_COUNT
  34.     props = obs.obs_properties_create()
  35.  
  36.     for i in range(MATCH_COUNT):
  37.         obs.obs_properties_add_text(props, f"match{i}", f"Match {i+1}", obs.OBS_TEXT_DEFAULT)
  38.         obs.obs_properties_add_path(props, f"path{i}", f"Path {i+1}", obs.OBS_PATH_DIRECTORY, None, None)
  39.  
  40.     return props
  41.  
  42. # Signal handler for recording stop
  43. def signal_handler_function(calldata):
  44.     """Handle the recording stop signal and move the file accordingly."""
  45.     global patterns
  46.    
  47.     print("Handler triggered")
  48.     try:
  49.         last_recording = obs.obs_frontend_get_last_recording()
  50.  
  51.         # Wait for the file to be fully available
  52.         time.sleep(5)
  53.  
  54.         if not last_recording or not os.path.exists(last_recording):
  55.             print(f"Recording file not found: {last_recording}")
  56.             return
  57.  
  58.         print(f"Trying to match file {last_recording}")
  59.         # Move the file based on matching keyword
  60.         for match, output_path in patterns.items():
  61.             if match.lower() in last_recording.lower():
  62.                 print(f"Matched match {match}")
  63.                 if os.path.exists(output_path):
  64.                     os.rename(last_recording, os.path.join(output_path, os.path.basename(last_recording)))
  65.                     print(f"Moved file to: {output_path}")
  66.                 else:
  67.                     print(f"Output path does not exist: {output_path}")
  68.                 break
  69.         else:
  70.             print(f"No keyword match found for recording: {last_recording}")
  71.  
  72.     except Exception as e:
  73.         print(f"Error occurred during file move: {e}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement