Ultimamente he estado usando el Music Player Daemon (MPD) para escuchar música. Tambien me he dado cuenta que en Twitter hace varios días está de trending topic el hashtag #nowplaying, donde la gente publica lo que está escuchando. En base a ésto y a un poco de imaginación y tiempo libre, cree un script en bash que me permite publicar lo que estoy escuchando.
El script, llamado mpd-twitter, usa el cliente mpc para conectarse a mpd y obtener el artista y nombre de la reproducción actual, hacer el parseo necesario y posteriormente publica un estado en twitter.
#!/bin/bash # # Author: Zerial# Version: 0.1 # URL: http://dev.zerial.org/mpd-twitter # License: GPL # CONF_FILE=$HOME/.mpd-twitter USER=$(grep ^USERNAME $CONF_FILE |cut -f 2 -d "=") PASS=$(grep ^PASSWORD $CONF_FILE |cut -f 2 -d "=") if [ -f $CONF_FILE ]; then BEFORE=$(grep ^BEFORE $CONF_FILE |cut -f 2 -d "=") AFTER=$(grep ^AFTER $CONF_FILE |cut -f 2 -d "=") else Xdialog --title "Error" --beep --msgbox "Can't read your local config file. Please copy the /usr/local/share/mpd-twitter/mpd-twitter.local to $HOME/.mpd-twitter" 200 100 exit fi CURRENT_SONG=$(mpc current) MY_UPDATE="$BEFORE $CURRENT_SONG $AFTER" curl -u "$USER:$PASS" -d "status=$MY_UPDATE" -d "source=mpd-twit" "http://twitter.com/statuses/update.json" exit
El archivo de configuración, que debe estar ubicado en ~/.mpd-twitter, es:
# # Local Config file for mpd-twitter # # # Config the username and password # USERNAME=your_username PASSWORD=your_password # # Text before and text after the song. # example: # if BEFORE=Listening and AFTER=(powered by xxx) # mpd-twitter will send "Listening(powered by xxx)" # BEFORE=#nowplaying AFTER=(powered by mpd)
Para los usuarios de Archlinux que quieran probarlo, he creado un PKGBUILD:
# Contributor: Zerialpkgname=mpd-twitter pkgver=0.1 pkgrel=4 pkgdesc="Publish on twitter what you are listening on MPD" arch=('i686' 'x86_64') url="http://dev.zerial.org/mpd-twitter" license=('GPL') depends=('xdialog' 'curl' 'mpc') source=(http://dev.zerial.org/mpd-twitter/${pkgname}_${pkgver}.tar.gz) md5sums=('3d73b79fa38bd60f637386146137999b') build(){ cd $startdir/src/$pkgname install -d $startdir/pkg/usr/local/share/mpd-twitter mkdir $startdir/pkg/usr/bin install -m744 $startdir/src/$pkgname/mpd-twitter.local $startdir/pkg/usr/local/share/mpd-twitter/ install -m755 $startdir/src/$pkgname/mpd-twitter $startdir/pkg/usr/bin/ }
Tambien lo pueden encontrar en el repositorio AUR.
La idea es lanzar el script con algun hotkey de nuestro gestor de ventanas y asi, cada véz que quieras mostrar lo que estás escuchando, simplemente precionas la combinacion de teclas que configuraste. Por ejemplo, en DWM la he configurado asi:
[...]
/* commands */
static const char *mpdtwittercmd[] = { "mpd-twitter", NULL };
static Key keys[] = {
[...]
{ MODKEY|ShiftMask, XK_t, spawn, {.v = mpdtwittercmd } },
[...]
De esta forma, cada vez que presiono Alt+Shift + T, aparece en twitter lo que estoy escuchando.


2 respuestas hasta ahora ↓
1
Alvaro Véliz
// Feb 22, 2010 a las 11:27 am
Tengo 2 aportes:
* Yo ocupo Rhythmbox y es posible obtener lo que estamos escuchando con el comando “rhythmbox-client –print-playing”, eso permitiría agregar rhythmbox al cliente
* El segundo comentario es que en lugar de entregar el nombre de usuario y password sería mejor crear el script como aplicación genérica (dentro de lo posible) y utilizar OAUTH
2
xabz
// Abr 11, 2010 a las 1:43 am
Muchas gracias me funciono muy bien. Saludos
Deja un Comentario