73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
import threading
|
|
import time
|
|
import os
|
|
import json
|
|
from get_playlists import update_playlist_if_needed
|
|
|
|
CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'main_data', 'app_config.txt')
|
|
MEDIA_DATA_PATH = os.path.join(os.path.dirname(__file__), 'static_data', 'media')
|
|
PLAYLIST_DIR = os.path.join(os.path.dirname(__file__), 'static_data', 'playlist')
|
|
LOCAL_PLAYLIST_PATH = os.path.join(PLAYLIST_DIR, 'server_playlist.json')
|
|
|
|
def playlist_update_loop(refresh_time, app_running, config, local_playlist_path, media_dir, playlist_dir):
|
|
while app_running[0]:
|
|
updated = update_playlist_if_needed(local_playlist_path, config, media_dir, playlist_dir)
|
|
if updated:
|
|
print(f"[REFRESH] Playlist updated from server at {time.strftime('%X')}")
|
|
else:
|
|
print(f"[REFRESH] Playlist already up to date at {time.strftime('%X')}")
|
|
time.sleep(refresh_time)
|
|
|
|
|
|
import tkinter as tk
|
|
from player import SimpleTkPlayer, load_latest_playlist
|
|
|
|
def main():
|
|
with open(CONFIG_PATH, 'r') as f:
|
|
config = json.load(f)
|
|
refresh_time = int(config.get('refresh_time', 5)) * 60 # minutes
|
|
app_running = [True]
|
|
update_thread = threading.Thread(
|
|
target=playlist_update_loop,
|
|
args=(refresh_time, app_running, config, LOCAL_PLAYLIST_PATH, MEDIA_DATA_PATH, PLAYLIST_DIR),
|
|
daemon=True
|
|
)
|
|
update_thread.start()
|
|
|
|
root = tk.Tk()
|
|
root.title("Simple Tkinter Player")
|
|
root.configure(bg='black')
|
|
root.attributes('-fullscreen', True)
|
|
|
|
# Load playlist and create player
|
|
playlist = load_latest_playlist()
|
|
player = SimpleTkPlayer(root, playlist)
|
|
player.app_running = app_running
|
|
orig_exit_app = player.exit_app
|
|
def exit_and_stop():
|
|
app_running[0] = False
|
|
orig_exit_app()
|
|
player.exit_app = exit_and_stop
|
|
player.exit_btn.config(command=player.exit_app)
|
|
player.main_start()
|
|
|
|
def reload_playlist_if_updated():
|
|
new_playlist = load_latest_playlist()
|
|
if new_playlist != player.playlist:
|
|
player.playlist = new_playlist
|
|
player.current_index = 0
|
|
player.show_current_media()
|
|
root.after(10000, reload_playlist_if_updated)
|
|
reload_playlist_if_updated()
|
|
|
|
try:
|
|
root.mainloop()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
app_running[0] = False
|
|
update_thread.join()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|