#!/bin/bash # OPENMIC: STREAM LIVE # Streams openmic live from input/ALSA # Includes and Declarations (global variables, formatting, and functions) source "${APPLICATION_ROOT}/scripts/system/system-functions" source "${APPLICATION_ROOT}/scripts/system/system-declarations" # Get active config name, construct path to streamable config file (for validation) CURRENTLY_ACTIVE_CONFIG_NAME=$(<"$CONFIG_FILE_IDENTIFIER_PATH") STREAMABLE_CONFIG_FILE_PATH="$CONFIG_DIRECTORY/config-$CURRENTLY_ACTIVE_CONFIG_NAME.json" # Check if config file exists if [[ -f "$STREAMABLE_CONFIG_FILE_PATH" ]]; # If exists then # Parse JSON config file for each crucial streaming variable v1='testing_host' TESTING_HOST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v1//p" $STREAMABLE_CONFIG_FILE_PATH)) v2='testing_port' TESTING_PORT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v2//p" $STREAMABLE_CONFIG_FILE_PATH)) v3='testing_user' TESTING_USER=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v3//p" $STREAMABLE_CONFIG_FILE_PATH)) v4='testing_password' TESTING_PASSWORD=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v4//p" $STREAMABLE_CONFIG_FILE_PATH)) v5='testing_mount' TESTING_MOUNT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v5//p" $STREAMABLE_CONFIG_FILE_PATH)) v6='playlist_url' PLAYLIST_URL=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v6//p" $STREAMABLE_CONFIG_FILE_PATH)) v7='randomize_playlist_files' RANDOMIZE_PLAYLIST_FILES=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v7//p" $STREAMABLE_CONFIG_FILE_PATH)) v8='hardware_audio_frame_size' HARDWARE_AUDIO_FRAME_SIZE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v8//p" $STREAMABLE_CONFIG_FILE_PATH)) # Parse JSON config file for each metadata streaming variable v9='testing_metadata_artist' TESTING_METADATA_ARTIST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v9//p" $STREAMABLE_CONFIG_FILE_PATH)) # TESTING_METADATA_ARTIST="${TESTING_METADATA_ARTIST// /\+}" vA='testing_metadata_title' TESTING_METADATA_TITLE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$vA//p" $STREAMABLE_CONFIG_FILE_PATH)) # TESTING_METADATA_TITLE="${TESTING_METADATA_TITLE// /\+}" # Ensure all configuration files are not blank if [ -z "${TESTING_HOST}" ] || [ -z "${TESTING_PORT}" ] || [ -z "${TESTING_USER}" ] || [ -z "${TESTING_PASSWORD}" ] || [ -z "${TESTING_MOUNT}" ] || [ -z "${PLAYLIST_URL}" ] || [ -z "${RANDOMIZE_PLAYLIST_FILES}" ] || [ -z "${HARDWARE_AUDIO_FRAME_SIZE}" ] then # Fault if config variable is blank error_message "[l] Stream ALSA (to Testing): Streaming failed. Please check your configuration settings." echo "" else # Notice of Execution confirmation_message "${COLOR_GREEN}[l] Stream ALSA (to Testing):${COLOR_DEFAULT}"; # Encode and Submit Metadata Change (Hack: two requests to get changes to take) CONVERTED_TESTING_METADATA_TITLE=$(url_encode_string "$TESTING_METADATA_TITLE") CONVERTED_TESTING_METADATA_ARTIST=$(url_encode_string "$TESTING_METADATA_ARTIST") curl "http://$TESTING_USER:$TESTING_PASSWORD@$TESTING_HOST:$TESTING_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_TESTING_METADATA_TITLE'&artist='$CONVERTED_TESTING_METADATA_ARTIST'" sleep 5 curl "http://$TESTING_USER:$TESTING_PASSWORD@$TESTING_HOST:$TESTING_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_TESTING_METADATA_TITLE'&artist='$CONVERTED_TESTING_METADATA_ARTIST'" # Liquidsoap Log echo -e "\n" echo -e "\n" echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[STARTING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n" echo -e "${COLOR_MAGENTA}" # Launch Liquidsoap using variables liquidsoap ' set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE'); stream_master_source = output.icecast( %mp3(bitrate=192,samplerate=44100), host="'$TESTING_HOST'", port='$TESTING_PORT', user="'$TESTING_USER'", password="'$TESTING_PASSWORD'", mount="'$TESTING_MOUNT'", input.alsa(bufferize = true) ) stream_master_source ' echo -e ${COLOR_DEFAULT} echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[EXITING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n" echo -e "\n" echo -e "\n" echo -e "\n" fi # If no config file exists else error_message "[l] Stream ALSA (to Testing): No config file specified. To stream, please assign a config." echo "" fi