Skip to content

Commit

Permalink
refactor: move app routes to separate files (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicwomg authored Jan 6, 2025
1 parent 30b49b6 commit 9cc8d93
Show file tree
Hide file tree
Showing 34 changed files with 2,112 additions and 1,852 deletions.
751 changes: 58 additions & 693 deletions pikaraoke/app.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pikaraoke/karaoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ def play_file(self, file_path, semitones=0):
semitones != 0 or self.normalize_audio or is_transcoding_required(file_path)
)

logging.debug(f"Requires transcoding: {requires_transcoding}")

try:
fr = FileResolver(file_path)
except Exception as e:
Expand Down
25 changes: 0 additions & 25 deletions pikaraoke/lib/background_music.py

This file was deleted.

69 changes: 69 additions & 0 deletions pikaraoke/lib/current_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import subprocess
import sys
import time

import cherrypy
from flask import current_app, request

from pikaraoke.karaoke import Karaoke


def is_admin() -> bool:
"""Determine if the current app's admin password matches the admin cookie value
This function checks if the provided password is `None` or if it matches
the value of the "admin" cookie in the current Flask request. If the password
is `None`, the function assumes the user is an admin. If the "admin" cookie
is present and its value matches the provided password, the function returns `True`.
Otherwise, it returns `False`.
Returns:
bool: `True` if the password matches the admin cookie or if the password is `None`,
`False` otherwise.
"""
password = get_admin_password()
return password is None or request.cookies.get("admin") == password


def get_karaoke_instance() -> Karaoke:
"""Get the current app's Karaoke instance
This function returns the Karaoke instance stored in the current app's configuration.
Returns:
Karaoke: The Karaoke instance stored in the current app's configuration.
"""
return current_app.k


def get_admin_password() -> str:
"""Get the admin password from the current app's configuration
This function returns the admin password stored in the current app's configuration.
Returns:
str: The admin password stored in the current app's configuration.
"""
return current_app.config["ADMIN_PASSWORD"]


def get_site_name() -> str:
"""Get the site name from the current app's configuration
This function returns the site name stored in the current app's configuration.
Returns:
str: The site name stored in the current app's configuration.
"""
return current_app.config["SITE_NAME"]


def delayed_halt(cmd):
time.sleep(1.5)
current_app.k.queue_clear()
cherrypy.engine.stop()
cherrypy.engine.exit()
current_app.k.stop()
if cmd == 0:
sys.exit()
if cmd == 1:
os.system("shutdown now")
if cmd == 2:
os.system("reboot")
if cmd == 3:
process = subprocess.Popen(["raspi-config", "--expand-rootfs"])
process.wait()
os.system("reboot")
5 changes: 1 addition & 4 deletions pikaraoke/lib/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

from pikaraoke.lib.get_platform import is_raspberry_pi


def launch_splash_screen(karaoke, window_size=None):
if karaoke.is_raspberry_pi:
service = service(executable_path="/usr/bin/chromedriver")
service = Service(executable_path="/usr/bin/chromedriver")
else:
service = None
options = Options()
Expand Down
Loading

0 comments on commit 9cc8d93

Please sign in to comment.