Fix video overlay template sequence to use configured templates from dashboard

- Add _get_outcome_template() method to fetch template assignments from database
- Update _handle_play_video_match() to use configured template for UNDER/OVER videos
- Update _play_result_video() to use configured template for result videos
- Update _switch_to_result_overlay() to use new template lookup method
- Templates are now correctly loaded based on dashboard configuration
- Falls back to match_video.html for UNDER/OVER and results.html for other outcomes
parent d908463e
......@@ -4503,13 +4503,17 @@ class QtVideoPlayer(QObject):
"fixture_id": fixture_id
}
# Get the configured template for this outcome (UNDER/OVER)
# Falls back to match_video.html if not configured
template_name = self._get_outcome_template(result) if result else "match_video.html"
self.window.play_video(
str(match_video_path),
template_data=overlay_data,
template_name="match_video.html", # Use match_video template for overlay
template_name=template_name,
loop_data=None # No looping for match videos
)
logger.info(f"Match video started: {video_filename} with result: {result} and overlay template applied")
logger.info(f"Match video started: {video_filename} with result: {result} and overlay template '{template_name}' applied")
# Player should now wait for other messages while video plays
# Video play will continue until PLAY_VIDEO_MATCH_DONE is sent
......@@ -5110,11 +5114,15 @@ class QtVideoPlayer(QObject):
logger.info(f"Sending results data to overlay: outcome={main_result}, under_over={under_over_result}, winning_outcomes_count={len(winning_outcomes_list)}")
# Play the result video with results overlay template
# Get the configured template for this result outcome
# Falls back to results.html if not configured
template_name = self._get_outcome_template(result) if result else "results.html"
# Play the result video with the configured overlay template
self.window.play_video(
video_path,
template_data=overlay_data,
template_name="results.html", # Use results template
template_name=template_name,
loop_data=None
)
......@@ -5144,7 +5152,7 @@ class QtVideoPlayer(QObject):
logger.info(f"Switching overlay to result template for result: {result}")
# Get result template from configuration
result_template = self._get_result_template(result)
result_template = self._get_outcome_template(result)
# Update overlay with result template
result_overlay_data = {
......@@ -5160,14 +5168,50 @@ class QtVideoPlayer(QObject):
except Exception as e:
logger.error(f"Failed to switch result overlay: {e}")
def _get_result_template(self, result: str) -> str:
"""Get configured result template for the given result"""
def _get_outcome_template(self, outcome: str) -> str:
"""Get configured template for a specific outcome from database configuration.
Args:
outcome: The outcome name (e.g., 'UNDER', 'OVER', 'WIN1', 'KO1', etc.)
Returns:
Template name to use, or default template if not configured
"""
try:
# TODO: Get from template configuration
# For now, return default result template
return "results.html"
from ..database.models import GameConfigModel
import json
session = self.db_manager.get_session()
try:
# Get outcome template assignments from config
assignments_config = session.query(GameConfigModel).filter_by(
config_key='outcome_template_assignments'
).first()
if assignments_config:
assignments = json.loads(assignments_config.config_value)
template = assignments.get(outcome)
if template:
logger.info(f"Found configured template '{template}' for outcome '{outcome}'")
return template
# No configured template - use defaults based on outcome type
if outcome in ['UNDER', 'OVER']:
default = "match_video.html"
else:
default = "results.html"
logger.debug(f"No configured template for outcome '{outcome}', using default: {default}")
return default
finally:
session.close()
except Exception as e:
logger.error(f"Failed to get result template: {e}")
logger.error(f"Failed to get outcome template for {outcome}: {e}")
# Return appropriate default based on outcome type
if outcome in ['UNDER', 'OVER']:
return "match_video.html"
return "results.html"
def _send_match_video_done_message(self, match_id=None, video_filename=None, fixture_id=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment