#!/bin/bash
# *********************************
# ***** 4chan-NowPlaying v0.1 *****
# *********************************
p1=$1
p2=$2
if [ -z $p1 ]; then
echo -e "Error: Insufficient parameters."
echo -e "Syntax:"
echo -e "\t$0 <image_path> [<thread_id>]"
exit 1
fi
# ********* SETTINGS *********
BIN_CURL=/usr/bin/curl
FILE_RESULT=/dev/null
CMD_GET_PLAYER="mpd -V"
CMD_GET_SONG="mpc current"
CMD_GET_INFO="mpc stats"
CMD_GET_COVER="echo -n $p1"
board="g"
thread=$p2
# ****************************
getInfo() {
m_PLAYER=$($CMD_GET_PLAYER | head -n1)
m_SONG=$($CMD_GET_SONG | head -n1)
m_STATS=$($CMD_GET_INFO)
m_COVER=$($CMD_GET_COVER)
if [ ! -e $m_COVER ]; then
echo "$m_COVER: no such file or directory!"
fi
}
sendSong() {
input_MAX_FILE_SIZE="3145728"
input_mode="regist"
input_name="Anonymous"
input_sub="♫"
input_email=""
input_password=""
input_upfile=$m_COVER
input_resto=$thread
input_com="${input_name} is currently listening to:
> ${m_SONG}
Player version: ${m_PLAYER}
Player stats:
${m_STATS}"
if [ ! -z $p2 ]; then
echo "Posting in thread #$p2 on /$board/"
else
echo "Creating new thread on /$board/"
fi
$BIN_CURL \
--output "$FILE_RESULT" \
--location \
--silent \
--form "upfile=@${input_upfile}" \
--form "MAX_FILE_SIZE=${input_MAX_FILE_SIZE}" \
--form "mode=${input_mode}" \
--form "resto=${input_resto}" \
--form "name=${input_name}" \
--form "sub=${input_sub}" \
--form "email=${input_email}" \
--form "password=${input_password}" \
--form "com=${input_com}" \
--url "http://sys.4chan.org/"${board}"/post"
}
getInfo
sendSong
exit $?