#!/bin/bash # This script (hereby licensed under LGPL-3.0) by SL: Celeste Python / RL: Angela Kahealani # 2012-01-20 23:16:54+00:00 angela@kahealani.com http://www.kahealani.com/kahealani/angela_kahealani.html # collects from Second Life's public chatlog the ShoutCast streams selected for the SHOUTCAST2SL JUKEBOX in Second Life (TM) # into a playlist for Real Life listening, and manages removal from the playlist of streams you later find undesirable. # It first plays local files in ~/Music and allows their deletion if unwanted. # Uncomment your favorite player: player="mplayer" # player="xine" # # HELP # if [ "$1" = "-h" ] then echo "$0 Usage:" echo "Changing stations is as easy as typing: 'q'" echo "To purge a station from your playlist, type: 'qrm'" echo "To stop listening, type: 'q^C>'" echo "To pause or resume listening, type: ' '" exit 0 fi if [ "$1" = "--help" ] then echo "$0 Usage:" echo "Changing stations is as easy as typing: 'q'" echo "To purge a station from your playlist, type: 'qrm'" echo "To stop listening, type: 'q^C>'" echo "To pause or resume listening, type: ' '" exit 0 fi # # ESTABLISH EXECUTION ENVIRONMENT AND REQUIRED RESOURCES # if [ -d ~/chatlogs ] then if [ -f ~/chatlogs/chat.txt ] then echo "Good: I found your chatlog." else echo "I can not find your chatlog, so please:" echo "ln -s ~/.secondlife/avatar_name/ ~/chatlogs" echo "I do not presume which 'avatar name' you use." exit 1 fi else echo "I can not find your chatlogs, so please:" echo " ln -s ~/.secondlife/avatar_name/ ~/chatlogs" echo "I do not presume which 'avatar name' you use." exit 1 fi if [ -d ~/Music ] then if [ -d ~/Music/playlists ] then echo "Good: playlists directory found." else mkdir -p ~/Music/playlists echo "Good: playlists directory created." fi else mkdir -p ~/Music/playlists echo "Good: playlists directory created." fi cd ~/Music # # 1 Infinite Loop # while sleep 1;do #loop forever, presuming concurrency with Second Life (TM) # # PLAY LOCAL FILES FIRST # for f in `find . -iname "*.ogg" -o -iname "*.mp3" | sort`;do echo "======= Begin: $f =======" "$player" "$f" echo "========= End: $f =======" echo -n "Disposition: ('rm' to remove/purge)?: " read a if [ "$a" = "rm" ] then rm "$f" && echo "$f PURGED." || echo "$f KEPT." else echo "$f KEPT." fi done # # UPDATE STREAMS PLAYLIST FROM SECOND LIFE (TM) SHOUTCAST2SL JUKEBOX # echo "Good: Refreshing Playlist from Second Life (TM) Public Chatlog..." if [ -f ~/Music/playlists/Shoutcast2SL.pls ] then cp ~/Music/playlists/Shoutcast2SL.pls /tmp/Shoutcast2SL.pls.$$ else touch /tmp/Shoutcast2SL.pls.$$ fi grep "SHOUTCAST2SL JUKEBOX" ~/chatlogs/chat.txt | cut -c 64- | sort -u | grep http >> /tmp/Shoutcast2SL.pls.$$ sort -u /tmp/Shoutcast2SL.pls.$$ > ~/Music/playlists/Shoutcast2SL.pls rm /tmp/Shoutcast2SL.pls.$$ echo "Good: Pruning the streams previously removed from the playlist:" if [ -f ~/Music/playlists/.Shoutcast2SL.pls ] then if [ -z ~/Music/playlists/.Shoutcast2SL.pls ] then echo "OK: Empty Purge List." else echo -n "Good: Processing Purge List" for u in `cat ~/Music/playlists/.Shoutcast2SL.pls`;do grep -v "$u" ~/Music/playlists/Shoutcast2SL.pls > /tmp/Shoutcast2SL.pls.$$ mv /tmp/Shoutcast2SL.pls.$$ ~/Music/playlists/Shoutcast2SL.pls echo -n "." done echo "" echo "Good: Processed Purge List." fi else echo "OK: NonExistant Purge List." fi # # PLAY STREAMS FROM INTERNET LISTED IN PLAYIST # for f in `cat ~/Music/playlists/Shoutcast2SL.pls`;do echo "======= Begin: $f =======" if [ -e `which "$player"` ] then "$player" "$f" else echo "Bad: We need to install $player..." sudo apt-get install "$player" "$player" "$f" fi echo "========= End: $f =======" echo -n "Disposition: ('rm' to remove/purge)?: " read a if [ "$a" = "rm" ] then echo "$f" >> ~/Music/playlists/.Shoutcast2SL.pls echo "$f PURGED." else echo "$f KEPT." fi done echo ======= END OF PLAYLIST, READY TO START OVER ======= echo -n "Re-En-Able Purged Channels ('yes' to reenable)?: " read a if [ "$a" = "yes" ] then cat ~/Music/playlists/.Shoutcast2SL.pls >> ~/Music/playlists/Shoutcast2SL.pls rm ~/Music/playlists/.Shoutcast2SL.pls echo "Disposition: ALL CHANNELS ENABLED." else echo "Disposition: PURGE LIST KEPT." fi echo ======= 1 Infinite Loop ======= done