Skip to content

Instantly share code, notes, and snippets.

@usure
Created October 30, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usure/1326321 to your computer and use it in GitHub Desktop.
Save usure/1326321 to your computer and use it in GitHub Desktop.
cmusTweeter
#!/bin/bash
#Twitter tweeter by http://360percents.com
#v1.1 on May 12th 2011
#Edited by TheShadowFog
PROGRAM='cmus'
#DIRECTORY="$HOME/log"
username="email"
password="password"
#EXTRA OPTIONS
sleeptime=13 #add pause between requests
if ps ax | grep -v grep | grep $PROGRAM > /dev/null
then
echo "CMUS is running"
else
echo "cmus is not running! Start cmus and then try again."
exit 1
fi
#Uncomment below. if you want logging
#if [ -d "$DIRECTORY" ]; then #If log file does not exist. Create it
# echo "Log file exists!"
#else
# touch log
#fi
# echo "Printing to twitter."
while :
do
ARTIST=$( cmus-remote -Q 2>/dev/null | grep artist | cut -d " " -f 3- )
TITLE=$( cmus-remote -Q 2>/dev/null | grep title | cut -d " " -f 3- )
#ttytter -status="#nowplaying >> #$TITLE - #$ARTIST." >> /dev/null/
if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
echo "[FAIL] Tweet is over 140 chars!" && exit 1
fi
touch "cookie.txt" #create a temp. cookie file
#INITIAL PAGE
#echo "[+] Fetching twitter.com..." && sleep $sleeptime
initpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"`
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//'`
#LOGIN
#echo "[+] Submitting the login form..." && sleep $sleeptime
loginpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"`
#HOME PAGE
#echo "[+] Getting your twitter home page..." && sleep $sleeptime
homepage=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/"`
#TWEET
#echo "[+] Posting a new tweet..." && sleep $sleeptime
tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1`
update=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" -d "authenticity_token=$tweettoken&tweet1=$tweet&tweet[display_coordinates]=false" "http://mobile.twitter.com/"`
#LOGOUT
#echo "[+] Logging out..."
#logout=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/session/destroy"`
#rm "cookie.txt"
#echo "Checking for new song"
tweet="#nowplaying >> #$TITLE" #must be less than 140 chars
echo "Tweet sent. Sleeping for 13 seconds." >> log
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment