martes, 12 de julio de 2011

Cómo poner "Now playing" con Clementine+Kopete

Hasta hace un par de meses mi reproductor de música favorito en KDE era Amarok. Eso, hasta que me encontré con Clementine, el cuál posee una interfaz mucho más simple para la navegación de archivos que para mí fué lo fundamental. Por otra parte, mi aplicación de mensajería favorita es Kopete. Amarok y Kopete se llevan muy bien puesto que el último incluye la función "Now playing" para varios reproductores salvo mi Clementine :-(

Pero no todo está perdido! Si ponemos en un recipiente un poquito de BASH+QDBUS+Cron podemos hacer nuestro propio script "Now Playing" para establecer el mensaje de estado de Kopete con la canción y el artista que actualmente está sonando en Clementine.

Manos a la obra:

Primero creamos nuestro script en el directorio bin de nuestro home (por inercia, elección y formación utilizo nombres de archivos y variables en inglés):


pico ~/bin/ClementineNowPlaying.sh



Siendo pico el editor de texto que más utilizo. Puedes utilizar tu preferido (Kate/KWrite/Vi...).

Básicamente (y muy básicamente puesto que estoy lejos de ser un experto en BASH scripting) nuestro script obtendrá la canción y el artista que actualmente está reproduciendo Clementine, luego los pondrá en el mensaje de estado de Kopete adornado con la frase "Now playing...".

A continuación pegan el siguiente código dentro del archivo, he agregado comentarios sobre qué hace cada línea:


#!/bin/bash

#Primero  obtenemos el índice de la pista que actualmente esta sonando en Clementine

currentTrackIndex=$(/usr/bin/qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack)

#Luego utilizamos ese índice para obtener toda la información de la pista actual

#Con el comando grep nos quedamos sólo la línea que contiene el nombre del artista, esta línea es por ejemplo artist: Bon Jovi
artist=$(/usr/bin/qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata $currentTrackIndex | grep artist)

#Se aplica el mismo procedimiento para el título, esta variable quedará de la forma title: Always
title=$(/usr/bin/qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata $currentTrackIndex | grep title)

#Luego de la cadena original (ej: "artist: Bon Jovi") queremos borrar la subcadena "artist: " y eso lo hacemos así:
artist=${artist/artist: /}

#Lo mismo para el título:
title=${title/title: /}

#Finalmente enviamos la frase con las variables al mensaje de estado de Kopete:
/usr/bin/qdbus org.kde.kopete /Kopete org.kde.Kopete.setStatusMessage "Now playing $title by $artist"



Guardamos los cambios y cerramos nuestro editor de texto.
Le otorgamos permisos de ejecución a nuestro script:


chmod +x ~/bin/ClementineNowPlaying.sh


Es tiempo de probar nuestro script: ejecutamos Clementine con alguna canción y abrimos Kopete.
En el terminal ejecutamos nuestro script:


./bin/ClementineNowPlaying.sh


Chequeamos que Kopete ha realizado correctamente el cambio de estado:



Finalmente necesitamos que nuestro script se ejecute cada cierto intervalo de tiempo para asegurarnos que mostrará la información lo más actualizada posible sobre lo que escuchamos. Para eso utilizaremos el gestor de tareas de Linux: Cron.
Con el siguiente comando abriremos el editor del Cron:


crontab -e


Una vez ahí, presionamos la tecla i para iniciar la inserción de texto y pondremos la siguiente línea:


* * * * * DISPLAY=:0.0 /home/francisco/bin/ClementineNowPlaying.sh &>/dev/null


Esta línea quiere decir que ejecutaremos nuestro script cada minuto, de cada hora, de cada día, etc...
Para salir del editor presionamos la tecla ESC y luego ponemos : x y presionamos enter.
Para comprobar que hemos guardado los cambios ponemos:


crontab -l


Si no es así, volver sobre el paso anterior hasta que resulte! (Lo sé, ese editor no es de los más intuitivos).
Cuando resulte habremos terminado!

Suerte!

Cualquier pregunta con respecto a esto no duden en enviarla como comentario.

Note: I can answer in english as well, so if you know what it is about everything here but although of that you may need some help, so please don't hesitate and leave a comment ;-)

domingo, 10 de julio de 2011

The change will save me

[youtube http://www.youtube.com/watch?v=ZITh-XIikgI&w=560&h=349]

Hey now, take your pills and
Hey now, make your breakfast
Hey now, comb your hair and off to work
Crash land, no illusions, no collision, no intrusion
My imagination runs away

I know, I know, I know what I am chasing
I know, I know, I know that this is changing me

I am flying on a star into a meteor tonight
I am flying on a star, star, star
I will make it through the day
And then the day becomes the night
I will make it through the night

Hey now, take the U-Bahn, five stops, change the station
Hey now, don’t forget that change will save you
Hey now, count a thousand-million people, that’s astounding
Chasing through the city with their stars on bright

I know, I know, I know what I am chasing
I know, I know, I know that this is changing me

I am flying on a star into a meteor tonight

I am flying on a star, star, star
I will make it through the day
And then the day becomes the night
I will make it through the night

I don’t mind repeating, I am not complete
I have never been the gifted type
Hey, man, tell me something, are you off to somewhere?
Do you want to go with me tonight?

I know, I know, I know that this is changing
We walk the streets to feel the ground I’m chasing: ÜBerlin

I am flying on a star into a meteor tonight
I am flying on a star, star, star
I will make it through the day
And then the day and then the day becomes the night
I will make it through the night
Real Time Web Analytics