updated to send feedback

This commit is contained in:
2025-09-08 13:19:50 +03:00
parent bd4f101fcc
commit e2eecb9cf9
9 changed files with 2825 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import tkinter as tk
import vlc
import subprocess
import sys
from get_playlists import send_playlist_restart_feedback, send_player_error_feedback, send_playing_status_feedback
CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'main_data', 'app_config.txt')
PLAYLIST_DIR = os.path.join(os.path.dirname(__file__), 'static_data', 'playlist')
@@ -19,6 +20,10 @@ class SimpleTkPlayer:
self.is_transitioning = False # Flag to prevent rapid cycling
self.is_exiting = False # Flag to prevent operations during exit
# Load configuration for feedback
self.config = self.load_config()
self.playlist_version = self.get_current_playlist_version()
# Initialize all timer variables to None
self.hide_controls_timer = None
self.video_watchdog = None
@@ -36,6 +41,55 @@ class SimpleTkPlayer:
self.root.after(300, self.move_mouse_to_corner)
self.root.protocol('WM_DELETE_WINDOW', self.exit_app)
def load_config(self):
"""Load configuration for feedback functionality"""
try:
with open(CONFIG_PATH, 'r') as f:
config = json.load(f)
return config
except Exception as e:
print(f"[CONFIG] Error loading config: {e}")
return {}
def get_current_playlist_version(self):
"""Get the current playlist version from the loaded playlist data"""
try:
# Try to find the latest playlist file and extract version
if os.path.exists(PLAYLIST_DIR):
playlist_files = [f for f in os.listdir(PLAYLIST_DIR) if f.startswith('server_playlist_v') and f.endswith('.json')]
if playlist_files:
# Get the highest version number
versions = [int(f.split('_v')[-1].split('.json')[0]) for f in playlist_files]
return max(versions)
return None
except Exception as e:
print(f"[CONFIG] Error getting playlist version: {e}")
return None
def send_error_feedback(self, error_message):
"""Send error feedback to server"""
try:
if self.config:
send_player_error_feedback(self.config, error_message, self.playlist_version)
except Exception as e:
print(f"[FEEDBACK] Error sending error feedback: {e}")
def send_playing_feedback(self, current_media=None):
"""Send playing status feedback to server"""
try:
if self.config:
send_playing_status_feedback(self.config, self.playlist_version, current_media)
except Exception as e:
print(f"[FEEDBACK] Error sending playing feedback: {e}")
def send_restart_feedback(self):
"""Send playlist restart feedback to server"""
try:
if self.config:
send_playlist_restart_feedback(self.config, self.playlist_version)
except Exception as e:
print(f"[FEEDBACK] Error sending restart feedback: {e}")
def ensure_fullscreen(self):
self.root.attributes('-fullscreen', True)
self.root.update_idletasks()
@@ -247,34 +301,51 @@ class SimpleTkPlayer:
check_end()
except Exception as e:
print(f"[VLC] Error playing video {file_path}: {e}")
self.send_error_feedback(f"Video playback error: {str(e)} - {os.path.basename(file_path)}")
if on_end:
on_end()
def show_current_media(self):
self.root.attributes('-fullscreen', True)
self.root.update_idletasks()
if not self.playlist:
print("[PLAYER] Playlist is empty. No media to show.")
self.label.config(text="No media available", fg='white', font=('Arial', 32))
# Try to reload playlist after 10 seconds
self.root.after(10000, self.reload_playlist_and_continue)
return
media = self.playlist[self.current_index]
file_path = os.path.join(MEDIA_DATA_PATH, media['file_name'])
ext = file_path.lower()
duration = media.get('duration', None)
if not os.path.isfile(file_path):
print(f"[PLAYER] File missing: {file_path}. Skipping to next.")
self.next_media()
return
if ext.endswith(('.mp4', '.avi', '.mov', '.mkv')):
self.show_video(file_path, on_end=self.next_media, duration=duration)
elif ext.endswith(('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
# Use PIL for images instead of VLC to avoid display issues
self.show_image_via_pil(file_path, duration if duration is not None else 10, on_end=self.next_media)
else:
print(f"[PLAYER] Unsupported file type: {media['file_name']}")
self.label.config(text=f"Unsupported: {media['file_name']}", fg='yellow')
try:
self.root.attributes('-fullscreen', True)
self.root.update_idletasks()
if not self.playlist:
print("[PLAYER] Playlist is empty. No media to show.")
self.label.config(text="No media available", fg='white', font=('Arial', 32))
# Send error feedback
self.send_error_feedback("Playlist is empty, no media to show")
# Try to reload playlist after 10 seconds
self.root.after(10000, self.reload_playlist_and_continue)
return
media = self.playlist[self.current_index]
file_path = os.path.join(MEDIA_DATA_PATH, media['file_name'])
ext = file_path.lower()
duration = media.get('duration', None)
# Send playing status feedback
self.send_playing_feedback(media['file_name'])
if not os.path.isfile(file_path):
print(f"[PLAYER] File missing: {file_path}. Skipping to next.")
self.send_error_feedback(f"Media file missing: {media['file_name']}")
self.next_media()
return
if ext.endswith(('.mp4', '.avi', '.mov', '.mkv')):
self.show_video(file_path, on_end=self.next_media, duration=duration)
elif ext.endswith(('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
# Use PIL for images instead of VLC to avoid display issues
self.show_image_via_pil(file_path, duration if duration is not None else 10, on_end=self.next_media)
else:
print(f"[PLAYER] Unsupported file type: {media['file_name']}")
self.label.config(text=f"Unsupported: {media['file_name']}", fg='yellow')
self.send_error_feedback(f"Unsupported file type: {media['file_name']}")
self.root.after(2000, self.next_media)
except Exception as e:
print(f"[PLAYER] Error in show_current_media: {e}")
self.send_error_feedback(f"Error showing media: {str(e)}")
# Try to continue with next media after error
self.root.after(2000, self.next_media)
def show_image_via_pil(self, file_path, duration, on_end=None):
@@ -331,6 +402,7 @@ class SimpleTkPlayer:
except Exception as e:
print(f"[PLAYER] PIL image display failed: {e}. Skipping.")
self.send_error_feedback(f"Image display error: {str(e)} - {os.path.basename(file_path)}")
self.label.config(text=f"Image Error: {os.path.basename(file_path)}", fg='red', font=('Arial', 24))
self.root.after(2000, lambda: on_end() if on_end else None)
@@ -440,9 +512,18 @@ class SimpleTkPlayer:
return
self.is_transitioning = True
# Check if we're about to restart the playlist (loop back to beginning)
was_at_end = self.current_index == len(self.playlist) - 1
self.current_index = (self.current_index + 1) % len(self.playlist)
print(f"[PLAYER] Moving to next media: index {self.current_index}")
# Send feedback if playlist restarted
if was_at_end and self.current_index == 0:
print("[FEEDBACK] Playlist loop completed, sending restart feedback")
self.send_restart_feedback()
# Clear any existing timers safely
timer_names = ['video_watchdog', 'image_watchdog', 'image_timer']
for timer_name in timer_names: