Advertisement
This is comment for paste
Untitled
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import obspython as obs
- from shutil import move
- import os
- import time
- import logging
- # Change the log file location to a user-writable directory
- log_file = os.path.join(os.path.expanduser("~"), "obs_recording_move.log")
- # Output paths and search strings (set dynamically)
- output_paths = {}
- # Set up logging to a file
- logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
- logger = logging.getLogger(__name__)
- # Ensure logging to a file as well
- file_handler = logging.FileHandler(log_file)
- file_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
- logger.addHandler(file_handler)
- # Description of the script for OBS
- def script_description():
- """Return the plugin description."""
- return "This plugin moves the recorded file to a specified folder after recording stops, based on keywords in the filename."
- # Hook to connect recording stop signal
- def script_load(settings):
- """Hook the recording stop signal when the plugin loads."""
- signal_handler = obs.obs_output_get_signal_handler(
- obs.obs_frontend_get_recording_output()
- )
- obs.signal_handler_connect(signal_handler, "stop", signal_handler_function)
- # Update function to set output paths and search strings dynamically
- def script_update(settings):
- """Called when script settings are updated."""
- global output_paths
- output_paths.clear()
- # Retrieve settings from the OBS properties panel
- for i in range(1, 5):
- keyword = obs.obs_data_get_string(settings, f"search_string{i}")
- output_path = obs.obs_data_get_string(settings, f"output_path{i}")
- if keyword and output_path:
- output_paths[keyword] = output_path
- # Property panel for OBS interface configuration
- def script_properties():
- """Define properties for OBS interface configuration."""
- props = obs.obs_properties_create()
- # Add fields for up to 4 keyword-folder pairs
- for i in range(1, 5):
- obs.obs_properties_add_text(
- props, f"search_string{i}", f"Keyword for Output {i}", obs.OBS_TEXT_DEFAULT
- )
- obs.obs_properties_add_path(
- props, f"output_path{i}", f"Output Folder {i}", obs.OBS_PATH_DIRECTORY, "", ""
- )
- return props
- # Signal handler for recording stop
- def signal_handler_function(calldata):
- """Handle the recording stop signal and move the file accordingly."""
- try:
- last_recording = obs.obs_frontend_get_last_recording()
- # Wait a bit to ensure the file is available
- time.sleep(5)
- if not last_recording or not os.path.exists(last_recording):
- logger.error(f"Recording file not found: {last_recording}")
- return
- # Move the file based on keyword matching
- for keyword, output_path in output_paths.items():
- if keyword.lower() in os.path.basename(last_recording).lower():
- # Ensure the output path exists
- os.makedirs(output_path, exist_ok=True)
- destination = os.path.join(output_path, os.path.basename(last_recording))
- move(last_recording, destination)
- logger.info(f"Moved file to: {destination}")
- return # Exit once the file is moved successfully
- # If no matching keyword was found
- logger.warning(f"No keyword match found for recording: {last_recording}")
- except Exception as e:
- logger.error(f"Error occurred during file move: {e}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement