updated to show when is not online

This commit is contained in:
2025-09-09 17:11:25 +03:00
parent a91b07ede4
commit 26fc946a65
11 changed files with 453 additions and 17 deletions

View File

@@ -4,7 +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, send_playlist_check_feedback
from get_playlists import send_playlist_restart_feedback, send_player_error_feedback, send_playing_status_feedback, send_playlist_check_feedback, get_server_status, get_last_playlist_update_time
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')
@@ -24,6 +24,10 @@ class SimpleTkPlayer:
self.config = self.load_config()
self.playlist_version = self.get_current_playlist_version()
# Offline notification tracking
self.offline_notification = None
self.last_server_status = True
# Initialize all timer variables to None
self.hide_controls_timer = None
self.video_watchdog = None
@@ -104,6 +108,70 @@ class SimpleTkPlayer:
except Exception as e:
print(f"[FEEDBACK] Error sending server check feedback: {e}")
def check_server_status(self):
"""Check server connectivity status and show/hide offline notification"""
try:
server_status = get_server_status()
is_online = server_status['is_online']
# Only update notification if status changed
if is_online != self.last_server_status:
if not is_online:
# Server went offline
self.show_offline_notification(server_status)
else:
# Server came back online
self.hide_offline_notification()
self.last_server_status = is_online
except Exception as e:
print(f"[OFFLINE] Error checking server status: {e}")
def show_offline_notification(self, server_status):
"""Show offline notification at bottom of screen"""
try:
if self.offline_notification:
return # Already showing
# Get last playlist update time from filesystem
last_update = get_last_playlist_update_time()
if last_update:
update_time = last_update.strftime("%Y-%m-%d %H:%M:%S")
message = f"OFFLINE MODE: Playing last available playlist updated at: {update_time}"
else:
message = "OFFLINE MODE: Playing last available playlist"
# Create notification label at bottom of screen
self.offline_notification = tk.Label(
self.root,
text=message,
bg='orange',
fg='black',
font=('Arial', 14, 'bold'),
relief='raised',
bd=2
)
# Position at bottom of screen
self.offline_notification.pack(side='bottom', fill='x', padx=5, pady=5)
self.offline_notification.lift() # Bring to front
print(f"[OFFLINE] Showing offline notification: {message}")
except Exception as e:
print(f"[OFFLINE] Error showing offline notification: {e}")
def hide_offline_notification(self):
"""Hide offline notification when server comes back online"""
try:
if self.offline_notification:
self.offline_notification.destroy()
self.offline_notification = None
print("[OFFLINE] Server back online - hiding offline notification")
except Exception as e:
print(f"[OFFLINE] Error hiding offline notification: {e}")
def ensure_fullscreen(self):
self.root.attributes('-fullscreen', True)
self.root.update_idletasks()
@@ -218,11 +286,49 @@ class SimpleTkPlayer:
self.show_current_media()
def update_playlist_from_server(self):
# Dummy implementation: replace with your actual update logic
# For example, call a function to fetch and reload the playlist
print("[INFO] Updating playlist from server...")
# You can import and call your real update function here
# Example: self.playlist = get_latest_playlist()
"""Update playlist from server and reload if needed"""
try:
from get_playlists import update_playlist_if_needed
import json
print("[INFO] Checking for playlist updates from server...")
# Get config
config_path = os.path.join(os.path.dirname(__file__), 'main_data', 'app_config.txt')
with open(config_path, 'r') as config_file:
config = json.load(config_file)
# Define paths
playlist_dir = os.path.join(os.path.dirname(__file__), 'static_data', 'playlist')
media_dir = os.path.join(os.path.dirname(__file__), 'static_data', 'media')
# Find current playlist file
playlist_files = [f for f in os.listdir(playlist_dir) if f.startswith('server_playlist_v') and f.endswith('.json')]
if playlist_files:
current_playlist_path = os.path.join(playlist_dir, max(playlist_files))
else:
current_playlist_path = os.path.join(playlist_dir, 'server_playlist_v0.json')
# Check and update if needed
updated = update_playlist_if_needed(current_playlist_path, config, media_dir, playlist_dir)
if updated:
print("[INFO] Playlist updated! Reloading...")
# Reload the playlist
self.update_playlist_version()
# Restart playback with new playlist
self.current_index = 0
self.load_playlist()
else:
print("[INFO] Playlist is already up to date.")
except Exception as e:
print(f"[ERROR] Failed to update playlist: {e}")
from get_playlists import send_player_error_feedback
try:
send_player_error_feedback(config, f"Playlist update failed: {str(e)}")
except:
pass
def toggle_pause(self):
if not self.paused:
@@ -321,6 +427,9 @@ class SimpleTkPlayer:
def show_current_media(self):
try:
# Check server status and update offline notification
self.check_server_status()
self.root.attributes('-fullscreen', True)
self.root.update_idletasks()
if not self.playlist:
@@ -859,6 +968,9 @@ class SimpleTkPlayer:
try:
print("[EXIT] Destroying controls...")
# Hide offline notification if showing
self.hide_offline_notification()
# First, try to hide and destroy the main controls window
if hasattr(self, 'controls_win') and self.controls_win:
try: