Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: Bash | Size: 1.72 KB | Hits: 9 | Expires: Never
Copy text to clipboard
  1. #!/bin/bash
  2.  
  3. # *********************************
  4. # ***** 4chan-NowPlaying v0.1 *****
  5. # *********************************
  6.  
  7. p1=$1
  8. p2=$2
  9.  
  10. if [ -z $p1 ]; then
  11.     echo -e "Error: Insufficient parameters."
  12.     echo -e "Syntax:"
  13.     echo -e "\t$0 <image_path> [<thread_id>]"
  14.     exit 1
  15. fi
  16.  
  17. # ********* SETTINGS *********
  18. BIN_CURL=/usr/bin/curl
  19. FILE_RESULT=/dev/null
  20. CMD_GET_PLAYER="mpd -V"
  21. CMD_GET_SONG="mpc current"
  22. CMD_GET_INFO="mpc stats"
  23. CMD_GET_COVER="echo -n $p1"
  24.  
  25. board="g"
  26. thread=$p2
  27. # ****************************
  28.  
  29. getInfo() {
  30.     m_PLAYER=$($CMD_GET_PLAYER | head -n1)
  31.     m_SONG=$($CMD_GET_SONG | head -n1)
  32.     m_STATS=$($CMD_GET_INFO)
  33.     m_COVER=$($CMD_GET_COVER)
  34.  
  35.     if [ ! -e $m_COVER ]; then
  36.         echo "$m_COVER: no such file or directory!"
  37.     fi
  38. }
  39.  
  40. sendSong() {
  41.     input_MAX_FILE_SIZE="3145728"
  42.     input_mode="regist"
  43.     input_name="Anonymous"
  44.     input_sub="&#9835;"
  45.     input_email=""
  46.     input_password=""
  47.     input_upfile=$m_COVER
  48.     input_resto=$thread
  49.     input_com="${input_name} is currently listening to:
  50. > ${m_SONG}
  51.  
  52. Player version: ${m_PLAYER}
  53. Player stats:
  54. ${m_STATS}"
  55.  
  56.     if [ ! -z $p2 ]; then
  57.         echo "Posting in thread #$p2 on /$board/"
  58.     else
  59.         echo "Creating new thread on /$board/"
  60.     fi
  61.  
  62.     $BIN_CURL \
  63.         --output "$FILE_RESULT" \
  64.         --location \
  65.         --silent \
  66.         --form "upfile=@${input_upfile}" \
  67.         --form "MAX_FILE_SIZE=${input_MAX_FILE_SIZE}" \
  68.         --form "mode=${input_mode}" \
  69.         --form "resto=${input_resto}" \
  70.         --form "name=${input_name}" \
  71.         --form "sub=${input_sub}" \
  72.         --form "email=${input_email}" \
  73.         --form "password=${input_password}" \
  74.         --form "com=${input_com}" \
  75.         --url "http://sys.4chan.org/"${board}"/post"
  76. }
  77.  
  78. getInfo
  79. sendSong
  80.  
  81. exit $?