Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import time
- import obspython as obs
- import urllib.request
- import urllib.error
- MATCH_COUNT = 4 # Change to add more matches
- patterns = {}
- def script_description():
- return "Moves a file when filename matches Match N to Path N\nMade by Sateviss :chatting:"
- # Hook to connect recording stop signal
- def script_load(settings):
- """Hook stop recording signal on plugin load."""
- signal_handler = obs.obs_output_get_signal_handler(
- obs.obs_frontend_get_recording_output()
- )
- obs.signal_handler_connect(signal_handler, "stop", signal_handler_function)
- print("Attached handler")
- def script_update(settings):
- global MATCH_COUNT
- global patterns
- for i in range(MATCH_COUNT):
- key = obs.obs_data_get_string(settings, f"match{i}")
- val = obs.obs_data_get_string(settings, f"path{i}")
- patterns.update({key:val})
- print(f"Loaded matcher {i}:", key, val)
- def script_properties():
- global MATCH_COUNT
- props = obs.obs_properties_create()
- for i in range(MATCH_COUNT):
- obs.obs_properties_add_text(props, f"match{i}", f"Match {i+1}", obs.OBS_TEXT_DEFAULT)
- obs.obs_properties_add_path(props, f"path{i}", f"Path {i+1}", obs.OBS_PATH_DIRECTORY, None, None)
- return props
- # Signal handler for recording stop
- def signal_handler_function(calldata):
- """Handle the recording stop signal and move the file accordingly."""
- global patterns
- print("Handler triggered")
- try:
- last_recording = obs.obs_frontend_get_last_recording()
- # Wait for the file to be fully available
- time.sleep(5)
- if not last_recording or not os.path.exists(last_recording):
- print(f"Recording file not found: {last_recording}")
- return
- print(f"Trying to match file {last_recording}")
- # Move the file based on matching keyword
- for match, output_path in patterns.items():
- if match.lower() in last_recording.lower():
- print(f"Matched match {match}")
- if os.path.exists(output_path):
- os.rename(last_recording, os.path.join(output_path, os.path.basename(last_recording)))
- print(f"Moved file to: {output_path}")
- else:
- print(f"Output path does not exist: {output_path}")
- break
- else:
- print(f"No keyword match found for recording: {last_recording}")
- except Exception as e:
- print(f"Error occurred during file move: {e}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement