#!/bin/bash # TechDJ PyQt6 Launcher Script echo "TechDJ PyQt6 - Native DJ Application" echo "========================================" echo "" # Activate virtual environment if it exists if [ -f "./.venv/bin/activate" ]; then echo "Activating virtual environment (.venv)..." source ./.venv/bin/activate elif [ -f "./venv/bin/activate" ]; then echo "Activating virtual environment (venv)..." source ./venv/bin/activate fi # Check if Python is installed if ! command -v python3 &> /dev/null; then echo "[ERROR] Python 3 is not installed!" echo "Please install Python 3 first." exit 1 fi echo "[OK] Python 3 found: $(python3 --version)" # Check if pip is installed if ! command -v pip3 &> /dev/null; then echo "[WARN] pip3 not found. Installing..." echo "Please run: sudo apt install python3-pip" exit 1 fi # Check if dependencies are installed echo "" echo "Checking dependencies..." MISSING_DEPS=0 # Check PyQt6 if ! python3 -c "import PyQt6" 2>/dev/null; then echo "[ERROR] PyQt6 not installed" MISSING_DEPS=1 else echo "[OK] PyQt6 installed" fi # Check sounddevice if ! python3 -c "import sounddevice" 2>/dev/null; then echo "[ERROR] sounddevice not installed" MISSING_DEPS=1 else echo "[OK] sounddevice installed" fi # Check soundfile if ! python3 -c "import soundfile" 2>/dev/null; then echo "[ERROR] soundfile not installed" MISSING_DEPS=1 else echo "[OK] soundfile installed" fi # Check numpy if ! python3 -c "import numpy" 2>/dev/null; then echo "[ERROR] numpy not installed" MISSING_DEPS=1 else echo "[OK] numpy installed" fi # Check socketio if ! python3 -c "import socketio" 2>/dev/null; then echo "[ERROR] python-socketio not installed" MISSING_DEPS=1 else echo "[OK] python-socketio installed" fi # Check yt-dlp if ! python3 -c "import yt_dlp" 2>/dev/null; then echo "[ERROR] yt-dlp not installed" MISSING_DEPS=1 else echo "[OK] yt-dlp installed" fi # Install missing dependencies if [ $MISSING_DEPS -eq 1 ]; then if [[ "$*" == *"--noint"* ]]; then echo "[WARN] Missing dependencies detected in non-interactive mode" echo "Please run './launch_qt.sh' from terminal to install dependencies" # Continue anyway - dependencies might be installed elsewhere else echo "" echo "[INSTALL] Installing missing dependencies..." echo "This may take a few minutes..." echo "" # Install system dependencies first (for sounddevice) echo "Installing system dependencies..." if command -v apt-get &> /dev/null; then echo "Detected Debian/Ubuntu system" echo "You may need to run: sudo apt-get install portaudio19-dev python3-pyqt6 python3-pyqt6.qtmultimedia libqt6multimedia6-plugins" elif command -v dnf &> /dev/null; then echo "Detected Fedora system" echo "You may need to run: sudo dnf install portaudio-devel python3-qt6" elif command -v pacman &> /dev/null; then echo "Detected Arch system" echo "You may need to run: sudo pacman -S portaudio python-pyqt6" fi echo "" echo "Installing Python packages..." pip3 install --user PyQt6 sounddevice soundfile numpy python-socketio[client] requests yt-dlp if [ $? -ne 0 ]; then echo "[ERROR] Installation failed!" echo "Please install dependencies manually:" echo " pip3 install --user -r requirements.txt" exit 1 fi echo "[OK] Dependencies installed successfully!" fi fi # Try to read server URL from settings SERVER_URL="http://localhost:5000" SETTINGS_FILE="$HOME/.techdj_settings.json" if [ -f "$SETTINGS_FILE" ]; then # Extract server_url from JSON if jq is available if command -v jq &> /dev/null; then SAVED_URL=$(jq -r '.server_url // "http://localhost:5000"' "$SETTINGS_FILE" 2>/dev/null) if [ ! -z "$SAVED_URL" ] && [ "$SAVED_URL" != "null" ]; then SERVER_URL="$SAVED_URL" fi else # Fallback: simple grep if jq not available SAVED_URL=$(grep -o '"server_url"[[:space:]]*:[[:space:]]*"[^"]*"' "$SETTINGS_FILE" 2>/dev/null | cut -d'"' -f4) if [ ! -z "$SAVED_URL" ]; then SERVER_URL="$SAVED_URL" fi fi fi # Check if Flask server is running echo "Checking server at: $SERVER_URL" if curl -s --max-time 2 "${SERVER_URL}/library.json" > /dev/null 2>&1; then echo "[OK] Flask server is running at $SERVER_URL" else echo "[WARN] Flask server not detected at $SERVER_URL" if [[ "$*" == *"--noint"* ]]; then echo "Proceeding in non-interactive mode..." else echo "Please make sure the server is running." echo "" read -p "Continue anyway? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi fi # Launch the application echo "" echo "Launching TechDJ PyQt6..." echo "" python3 techdj_qt.py echo "" echo "TechDJ PyQt6 closed"