#!/bin/bash #------------------------------------------------------- # LINUX TWITTER NOW PLAYING SHELL SCRIPT # # Reads id3 tag of the mp3 file played by the your # mp3 player. Puts it on twitter. # # Prereqs: Needs id3 installed. # # Example: twitternp "I love this song." # Twitters: "I am listening to Get Your Snack On by Amon Tobin at the moment. I love this song." # (you will be asked to confirm by pressing ENTER, so that you dont twitter garbage) # # Written by st0rz.net/storzblog, 2008 # This script might not work on your system. # USE AT OWN RISK! # # Depending on how many files are open on your system # this might work really slow ;/ #------------------------------------------------------- # _____ ____ ___ _____ # | ____| _ \_ _|_ _| # | _| | | | | | | |(_) # | |___| |_| | | | | _ # |_____|____/___| |_|(_) USER=xxxxx PASSWORD=xxxxxx # mp3 player you are using # tested with: xmms, vlc, rhythmbox PLAYER="xmms" # use the 2 keywords ARTIST and TITLE in any way here, will be replaced later on NPMSG="I am listening to TITLE by ARTIST at the moment." # _____ _ _ ____ __ _____ ____ ___ _____ # | ____| \ | | _ \ ___ / _| | ____| _ \_ _|_ _| # | _| | \| | | | | / _ \| |_ | _| | | | | | | | # | |___| |\ | |_| | | (_) | _| | |___| |_| | | | | # |_____|_| \_|____/ \___/|_| |_____|____/___| |_| #------------------------------------------------------- #------------------------------------------------------- # NOW PLAYING... id3 -v &> /dev/null || { echo "Please install id3." ; exit 1 ; } TRACK="$(lsof -b 2> /dev/null | grep "$PLAYER.*\.mp3" | expand | tr -s " " | cut -d" " -f9)" [ -n "$TRACK" ] || { echo "No mp3 playing at the moment." ; exit 2 ; } DATA="$(id3 -l $(lsof | grep "$PLAYER.*REG.*mp3" | expand | tr -s " " | cut -d" " -f9))" TITLE="$(echo "$DATA" | grep Title | sed -r 's/Title : (.*)Artist.*/\1/g;s/^[ ]*//;s/[ ]*$//' )" ARTIST="$(echo "$DATA" | grep Artist | cut -d: -f3 | sed 's/^[ ]*//;s/[ ]*$//')" MESSAGE="$(echo "$NPMSG" | sed "s/ARTIST/$ARTIST/;s/TITLE/$TITLE/") $1" echo "$MESSAGE" echo "Continue? [ENTER] (Yes) or [CTRL-C] (No)" read #------------------------------------------------------- # Twittering... echo CHR="$(echo "$MESSAGE" | wc -m)" if [ $CHR -gt 140 ] ; then echo "Warning: Message will be trunkated (> 140 chars)." echo "Continue? [ENTER] (Yes) or [CTRL-C] (No)" read fi curl --basic --user "${USER}:${PASSWORD}" --data-ascii "status=$(echo $MESSAGE|tr ' ' '+')" \ "http://twitter.com/statuses/update.json" # you could analyze server answer here ;) echo