def info(): url = "http://" + request.host # cpu cpu = str(psutil.cpu_percent()) + "%" # mem memory = psutil.virtual_memory() available = round(memory.available / 1024.0 / 1024.0, 1) total = round(memory.total / 1024.0 / 1024.0, 1) memory = (str(available) + "MB free / " + str(total) + "MB total ( " + str(memory.percent) + "% )") # disk disk = psutil.disk_usage("/") # Divide from Bytes -> KB -> MB -> GB free = round(disk.free / 1024.0 / 1024.0 / 1024.0, 1) total = round(disk.total / 1024.0 / 1024.0 / 1024.0, 1) disk = (str(free) + "GB free / " + str(total) + "GB total ( " + str(disk.percent) + "% )") # youtube-dl youtubedl_version = k.youtubedl_version is_pi = get_platform() == "raspberry_pi" return render_template("info.html", site_title=site_name, title="Info", url=url, memory=memory, cpu=cpu, disk=disk, youtubedl_version=youtubedl_version, is_pi=is_pi, pikaraoke_version=VERSION, admin=is_admin(), admin_enabled=admin_password != None)
def __init__(self, port=5000, download_path="/usr/lib/pikaraoke/songs", hide_ip=False, hide_raspiwifi_instructions=False, hide_splash_screen=False, omxplayer_adev="both", dual_screen=False, high_quality=False, volume=0, log_level=logging.DEBUG, splash_delay=2, youtubedl_path="/usr/local/bin/yt-dlp", omxplayer_path=None, use_omxplayer=False, use_vlc=True, vlc_path=None, vlc_port=None, logo_path=None, show_overlay=False): # override with supplied constructor args if provided self.port = port self.hide_ip = hide_ip self.hide_raspiwifi_instructions = hide_raspiwifi_instructions self.hide_splash_screen = hide_splash_screen self.omxplayer_adev = omxplayer_adev self.download_path = download_path self.dual_screen = dual_screen self.high_quality = high_quality self.splash_delay = int(splash_delay) self.volume_offset = volume self.youtubedl_path = youtubedl_path self.omxplayer_path = omxplayer_path self.use_omxplayer = use_omxplayer self.use_vlc = use_vlc self.vlc_path = vlc_path self.vlc_port = vlc_port self.logo_path = self.default_logo_path if logo_path == None else logo_path self.show_overlay = show_overlay # other initializations self.platform = get_platform() self.vlcclient = None self.omxclient = None self.screen = None logging.basicConfig( format="[%(asctime)s] %(levelname)s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S", level=int(log_level), ) logging.debug( """ http port: %s hide IP: %s hide RaspiWiFi instructions: %s, hide splash: %s splash_delay: %s omx audio device: %s dual screen: %s high quality video: %s download path: %s default volume: %s youtube-dl path: %s omxplayer path: %s logo path: %s Use OMXPlayer: %s Use VLC: %s VLC path: %s VLC port: %s log_level: %s show overlay: %s""" % (self.port, self.hide_ip, self.hide_raspiwifi_instructions, self.hide_splash_screen, self.splash_delay, self.omxplayer_adev, self.dual_screen, self.high_quality, self.download_path, self.volume_offset, self.youtubedl_path, self.omxplayer_path, self.logo_path, self.use_omxplayer, self.use_vlc, self.vlc_path, self.vlc_port, log_level, self.show_overlay)) # Generate connection URL and QR code, retry in case pi is still starting up # and doesn't have an IP yet (occurs when launched from /etc/rc.local) end_time = int(time.time()) + 30 if self.platform == "raspberry_pi": while int(time.time()) < end_time: addresses_str = check_output(["hostname", "-I"]).strip().decode("utf-8") addresses = addresses_str.split(" ") self.ip = addresses[0] if not self.is_network_connected(): logging.debug("Couldn't get IP, retrying....") else: break else: self.ip = self.get_ip() logging.debug("IP address (for QR code and splash screen): " + self.ip) self.url = "http://%s:%s" % (self.ip, self.port) # get songs from download_path self.get_available_songs() self.get_youtubedl_version() # clean up old sessions self.kill_player() self.generate_qr_code() if self.use_vlc: if (self.show_overlay): self.vlcclient = vlcclient.VLCClient(port=self.vlc_port, path=self.vlc_path, qrcode=self.qr_code_path, url=self.url) else: self.vlcclient = vlcclient.VLCClient(port=self.vlc_port, path=self.vlc_path) else: self.omxclient = omxclient.OMXClient( path=self.omxplayer_path, adev=self.omxplayer_adev, dual_screen=self.dual_screen, volume_offset=self.volume_offset) if not self.hide_splash_screen: self.initialize_screen() self.render_splash_screen()
import subprocess import sys import threading import time from io import BytesIO from pathlib import Path from subprocess import check_output import pygame import qrcode from unidecode import unidecode from lib import omxclient, vlcclient from lib.get_platform import get_platform if get_platform() != "windows": from signal import SIGALRM, alarm, signal class Karaoke: raspi_wifi_config_ip = "10.0.0.1" raspi_wifi_conf_file = "/etc/raspiwifi/raspiwifi.conf" raspi_wifi_config_installed = os.path.exists(raspi_wifi_conf_file) queue = [] available_songs = [] now_playing = None now_playing_filename = None now_playing_user = None now_playing_transpose = 0
def __init__(self, port=5002, path=None, qrcode=None, url=None): # HTTP remote control server self.http_password = "".join([ random.choice(string.ascii_letters + string.digits) for n in range(32) ]) self.port = port self.http_endpoint = "http://localhost:%s/requests/status.xml" % self.port self.http_command_endpoint = self.http_endpoint + "?command=" self.is_transposing = False self.qrcode = qrcode self.url = url # Handle vlc paths self.platform = get_platform() if path == None: self.path = get_default_vlc_path(self.platform) else: self.path = path # Determine tmp directories (for things like extracted cdg files) if self.platform == "windows": self.tmp_dir = os.path.expanduser( r"~\\AppData\\Local\\Temp\\pikaraoke\\") else: self.tmp_dir = "/tmp/pikaraoke/" # Set up command line args self.cmd_base = [ self.path, "-f", "--play-and-exit", "--extraintf", "http", "--http-port", "%s" % self.port, "--http-password", self.http_password, "--no-embedded-video", "--no-keyboard-events", "--no-mouse-events", "--mouse-hide-timeout", "0", "--video-on-top", "--no-video-title", "--mouse-hide-timeout", "0", ] if self.platform == "osx": self.cmd_base += [ "--no-macosx-show-playback-buttons", "--no-macosx-show-playmode-buttons", "--no-macosx-interfacestyle", "--macosx-nativefullscreenmode", "--macosx-continue-playback", "0", ] if self.qrcode and self.url: self.cmd_base += self.get_marquee_cmd() logging.info("VLC command base: " + " ".join(self.cmd_base)) self.volume_offset = 10 self.process = None
legacy_directory = os.path.expanduser("~\pikaraoke\songs") if os.path.exists(legacy_directory): return legacy_directory else: return "~\pikaraoke-songs" else: legacy_directory = "~/pikaraoke/songs" if os.path.exists(legacy_directory): return legacy_directory else: return "~/pikaraoke-songs" if __name__ == "__main__": platform = get_platform() default_port = 5000 default_volume = 0 default_splash_delay = 5 default_log_level = logging.INFO default_dl_dir = get_default_dl_dir(platform) default_omxplayer_path = "/usr/bin/omxplayer" default_adev = "both" default_youtubedl_path = get_default_youtube_dl_path(platform) default_vlc_path = get_default_vlc_path(platform) default_vlc_port = 5002 # parse CLI args parser = argparse.ArgumentParser()