Add validation to Load/Process and Preview actions, update to v0.5.0d
Changes: 1. Extract validation logic into _validate_plugin_settings helper method: - Returns (has_errors, validation_results, token) tuple - Validates API connection, profiles, groups, thresholds, etc. - Reusable across multiple action methods 2. Update validate_settings_action: - Now calls _validate_plugin_settings helper - Formats results for UI display 3. Add validation to load_process_channels_action: - Validates settings before loading channels - Prevents processing with invalid profiles or groups - Returns clear error messages if validation fails 4. Add validation to preview_changes_action: - Validates settings before previewing changes - Ensures settings are still valid when preview is run - Returns clear error messages if validation fails 5. Update version to 0.5.0d Benefits: - Prevents users from proceeding with invalid settings - Provides immediate feedback on configuration errors - Ensures channel profiles and groups exist before processing - Improves user experience with clear error messages - Maintains DRY principle with shared validation logic
This commit is contained in:
@@ -31,7 +31,7 @@ class Plugin:
|
|||||||
"""Dispatcharr Stream-Mapparr Plugin"""
|
"""Dispatcharr Stream-Mapparr Plugin"""
|
||||||
|
|
||||||
name = "Stream-Mapparr"
|
name = "Stream-Mapparr"
|
||||||
version = "0.5.0b"
|
version = "0.5.0d"
|
||||||
description = "🎯 Automatically add matching streams to channels based on name similarity and quality precedence with enhanced fuzzy matching"
|
description = "🎯 Automatically add matching streams to channels based on name similarity and quality precedence with enhanced fuzzy matching"
|
||||||
|
|
||||||
# Settings rendered by UI
|
# Settings rendered by UI
|
||||||
@@ -752,10 +752,16 @@ class Plugin:
|
|||||||
LOGGER.error(traceback.format_exc())
|
LOGGER.error(traceback.format_exc())
|
||||||
return {"status": "error", "message": str(e)}
|
return {"status": "error", "message": str(e)}
|
||||||
|
|
||||||
def validate_settings_action(self, settings, logger):
|
def _validate_plugin_settings(self, settings, logger):
|
||||||
"""Validate all plugin settings including profiles, groups, and API connection."""
|
"""
|
||||||
|
Helper method to validate plugin settings.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple of (has_errors: bool, validation_results: list, token: str or None)
|
||||||
|
"""
|
||||||
validation_results = []
|
validation_results = []
|
||||||
has_errors = False
|
has_errors = False
|
||||||
|
token = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 1. Validate API Connection
|
# 1. Validate API Connection
|
||||||
@@ -765,10 +771,7 @@ class Plugin:
|
|||||||
validation_results.append(f"❌ API Connection: FAILED - {error}")
|
validation_results.append(f"❌ API Connection: FAILED - {error}")
|
||||||
has_errors = True
|
has_errors = True
|
||||||
# Cannot continue without API access
|
# Cannot continue without API access
|
||||||
return {
|
return has_errors, validation_results, token
|
||||||
"status": "error",
|
|
||||||
"message": "Validation failed:\n\n" + "\n".join(validation_results)
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
validation_results.append("✅ API Connection: SUCCESS")
|
validation_results.append("✅ API Connection: SUCCESS")
|
||||||
|
|
||||||
@@ -906,6 +909,19 @@ class Plugin:
|
|||||||
else:
|
else:
|
||||||
validation_results.append("ℹ️ Ignore Tags: None configured")
|
validation_results.append("ℹ️ Ignore Tags: None configured")
|
||||||
|
|
||||||
|
# Return validation results
|
||||||
|
return has_errors, validation_results, token
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[Stream-Mapparr] Error validating settings: {str(e)}")
|
||||||
|
validation_results.append(f"❌ Unexpected error during validation: {str(e)}")
|
||||||
|
has_errors = True
|
||||||
|
return has_errors, validation_results, token
|
||||||
|
|
||||||
|
def validate_settings_action(self, settings, logger):
|
||||||
|
"""Validate all plugin settings including profiles, groups, and API connection."""
|
||||||
|
has_errors, validation_results, token = self._validate_plugin_settings(settings, logger)
|
||||||
|
|
||||||
# Build summary message
|
# Build summary message
|
||||||
if has_errors:
|
if has_errors:
|
||||||
message = "Validation completed with errors:\n\n" + "\n".join(validation_results)
|
message = "Validation completed with errors:\n\n" + "\n".join(validation_results)
|
||||||
@@ -916,21 +932,19 @@ class Plugin:
|
|||||||
message += "\n\nYou can now proceed with 'Load/Process Channels'."
|
message += "\n\nYou can now proceed with 'Load/Process Channels'."
|
||||||
return {"status": "success", "message": message}
|
return {"status": "success", "message": message}
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"[Stream-Mapparr] Error validating settings: {str(e)}")
|
|
||||||
validation_results.append(f"❌ Unexpected error during validation: {str(e)}")
|
|
||||||
return {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Validation failed:\n\n" + "\n".join(validation_results)
|
|
||||||
}
|
|
||||||
|
|
||||||
def load_process_channels_action(self, settings, logger):
|
def load_process_channels_action(self, settings, logger):
|
||||||
"""Load and process channels from specified profile and groups."""
|
"""Load and process channels from specified profile and groups."""
|
||||||
try:
|
try:
|
||||||
# Get API token
|
# Validate settings before proceeding
|
||||||
token, error = self._get_api_token(settings, logger)
|
logger.info("[Stream-Mapparr] Validating settings before loading channels...")
|
||||||
if error:
|
has_errors, validation_results, token = self._validate_plugin_settings(settings, logger)
|
||||||
return {"status": "error", "message": error}
|
|
||||||
|
if has_errors:
|
||||||
|
message = "Cannot load channels - validation failed:\n\n" + "\n".join(validation_results)
|
||||||
|
message += "\n\nPlease fix the errors above before proceeding."
|
||||||
|
return {"status": "error", "message": message}
|
||||||
|
|
||||||
|
logger.info("[Stream-Mapparr] Settings validated successfully, proceeding with channel load...")
|
||||||
|
|
||||||
profile_names_str = settings.get("profile_name", "").strip()
|
profile_names_str = settings.get("profile_name", "").strip()
|
||||||
selected_groups_str = settings.get("selected_groups", "").strip()
|
selected_groups_str = settings.get("selected_groups", "").strip()
|
||||||
@@ -1224,6 +1238,17 @@ class Plugin:
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Validate settings before previewing
|
||||||
|
logger.info("[Stream-Mapparr] Validating settings before previewing changes...")
|
||||||
|
has_errors, validation_results, token = self._validate_plugin_settings(settings, logger)
|
||||||
|
|
||||||
|
if has_errors:
|
||||||
|
message = "Cannot preview changes - validation failed:\n\n" + "\n".join(validation_results)
|
||||||
|
message += "\n\nPlease fix the errors above before proceeding."
|
||||||
|
return {"status": "error", "message": message}
|
||||||
|
|
||||||
|
logger.info("[Stream-Mapparr] Settings validated successfully, proceeding with preview...")
|
||||||
|
|
||||||
# Load channel data from channels.json
|
# Load channel data from channels.json
|
||||||
channels_data = self._load_channels_data(logger)
|
channels_data = self._load_channels_data(logger)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user