
J'écoutais assez régulièrement Puls'Radio, or il s'avère que je n'écoute que très peu de radios… voire qu'une seule ! 
Aussi, après avoir découvert la puissance et la légèreté de mplayer, me suis je dit que j'allais me faire une petite application dédiée à l'écoute de ma radio préférée… Comme j'aime bien le Bash, j'ai tout de suite pensé en faire une application avec Platypus.
Et c'est ainsi qu'un PulsPlayer version Mac OS X est né…
PulsPlayer supporte les notifications Growl :

Ce que j'apprécie vraiment avec bash c'est les flux et redirections, en fait : plus j'avance dans leur compréhension et plus je les apprécie…
Afficher la dernière piste en cours de lecture (avec GeekTool)
PulsPlayer enregistre les titres de l'ensemble des pistes, jouées au cours d'une session, dans un fichier temporaire de façon à être récupérées et affichées assez facilement à l'aide de GeekTool, par exemple (capture d'écran) :
if [[ -e "/tmp/www.pulsradio.com" && -n "$(top -l 1 | grep ' PulsPlayer ')" ]]; then
cat "/tmp/www.pulsradio.com" | tail -1 || echo ''
fi
Ci-dessous, une syntaxe beaucoup plus compacte :
[[ -e "/tmp/www.pulsradio.com" && -n "$(top -l 1 | grep ' PulsPlayer ')" ]] && (cat "/tmp/www.pulsradio.com" | tail -1 || echo '')
On pourrait très bien aussi imaginer en faire un Xtra pour Adium à l'instar de Now Playing in Adium.
Code source
PulsPlayer.app/Contents/Resources/script
#!/bin/bash
# PulsPlayer
# HP <http://blogosx.homeunix.org/>
#
# updated Jun. 06, 2007
#
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation
StreamUrl="http://www.pulsradio.com/pls/puls-adsl.m3u"
CurrentSong=""; LastSong=""; myID="$$"
StreamUrlRoot=$(echo "$StreamUrl" | awk -F 'http://' '{print $2}' | awk -F '/' '{print $1}')
myPath=$(dirname "$0")
appName=$(echo "$1" | awk -F '.app' '{print $1}' | awk -F "$(dirname "$1")/" '{print $2}')
lang=$(defaults read '.GlobalPreferences' 'AppleLanguages' | tr -d [:space:] | cut -c2-3)
# include my own function growlnotify
# (based on AppleScript)
source "${myPath}/growlnotify"
# include my own function l10n
# (localise applications based on bash)
source "${myPath}/l10n"
# path to mplayer
# (use mplayer provided by darwinports if present)
binPlayer="${myPath}/mplayer"
if [ -e "/opt/local/bin/mplayer" ]; then
binPlayer="/opt/local/bin/mplayer"
fi
# remove old temporary files
rm "/tmp/mplayer"* "/tmp/$StreamUrlRoot" > /dev/null 2>&1
# create new temporary files
touch "/tmp/mplayer${myID}" "/tmp/$StreamUrlRoot"
# main program
"$binPlayer" -playlist "${StreamUrl}" >> "/tmp/mplayer${myID}" 2>&1 | {
while [ 1 ]
do
# tracks
CurrentSong=$(cat "/tmp/mplayer${myID}" | grep "ICY" | awk -F "'" '{print $2}' | tail -1)
if [ "$CurrentSong" != "$LastSong" ]; then
LastSong="$CurrentSong"
if [ -n "$CurrentSong" ]; then
growlnotify "$appName" "$StreamUrlRoot" "$CurrentSong" | echo "$CurrentSong" >> "/tmp/$StreamUrlRoot"
fi
fi
# purge temp file
tempfileSize=$(du -k "/tmp/mplayer${myID}" | awk '{print $1}')
if [ "$tempfileSize" -gt 1024 ]; then
# ICY Info: StreamTitle='Brisby And Jingles - Losing Love';StreamUrl='';
echo $(cat "/tmp/mplayer${myID}" | grep "ICY" | tail -1) > "/tmp/mplayer${myID}"
fi
# quit (in case of crash)
isRunning=$(ps axc | grep "PulsPlayer" | cut -c2-6 | wc -w)
if [ "$isRunning" -lt 1 ]; then
errorMsg=$(l10n "error" "$lang")
growlnotify "$appName" "$StreamUrlRoot" "$errorMsg" | {
# mplayer processes (related to Application)
mplayerPIDs=$(ps ax | grep "mplayer" | grep "${binPlayer}" | awk '{print $1}')
i=0; ((max=$(echo "$mplayerPIDs" | wc -w)-1))
for PID in ${mplayerPIDs}; do
kill ${PID} > /dev/null 2>&1
((i++))
[ "$i" -ge "$max" ] && break
done
}
# end of loop
break && exit 1
fi
done
}
## Local Variables: ##
## mode:sh ##
## coding: utf-8 ##
## comment-column:0 ##
## comment-start: "# " ##
## comment-end:"##" ##
## End: ##
Télécharger le PulsPlayer
Le PulsPlayer est distribué sous licence GNU Lesser General Public License, et le script pourrait être facilement modifié pour écouter n'importe quelle autre radio 
Télécharger : PulsPlayer 1.2
Archive, ±6.5 Mo
MD5 (PulsPlayer.zip) = dee3894e13c5d9199efa907f08f05281