Tag: music

I am a music lover. So I listen to musics a lot. I not only listen to music, but also share it. For this purpose I made a php script long time ago that is used for song broadcasting. In windows I used winmap’s “dosomething” plugin to broadcast. Nowadays I listen song in my linux machine. No winamp is there. I use amarok to listen song. Amarok is a great player if you ever used it, you’ll realize. But I couldn’t broadcast song using amarok. Being a programmer I didnt search any plugin or script, rather I thought I’d write it myself.

I googled for writing amarok plugin. And I found these are not plugin actually. These are called script. Amarokscript. So I have to write amarok script. In the amarok wiki all the example was in Ruby and Python. But they said, any language can be used even bash would do. So I though why not try it with PHP. As I write PHP a lot. So It’ll be faster.

The amarok wiki in kde.org helped me a lot. Actually I have realy only that page and start writing the script. Bellow goes the main howto.

HOWTO:

An amarokscriopt is an tar archive file. It contians.

script/
README
COPYING
script.php (executable script)
script.spec

README: When you click on the about button/tab for this script in amarok the contents of this file is shown.

COPYING: If you have this file a tab/button named License will be shown. And the text from there will be contained there.

script.php: its the main script. It MUST be executable. In example I used .php extension. It can be any extension. For Ruby its .rb, for python its .py, for perl its .pl, for binary it can be empty or .o. the main point is it MUST be executable.

script.spec: Its the file where you’ll write configureation values for amarok. Amarok will read this file and determine which file is the main script and what type of script is this. In spec file there are 2 main entries. Name and type. If name is not given the first part of the .spec file is used as name. And type is a must.

The main script for me was in PHP. The main script should be executable. So I change the mode of the script to executable.

chmod +x songinfo-broadcaster.php

but even its executable, it can not run. Because shell doesn’t know what interpreter to use to run it. From shell you have to run it by,

$ php songinfo-broadcaster.php

Amarok wont call it that way for sure. If it would call it that way it wouldn’t require the script to be executable. It will be call like,

$ ./songinfo-broadcaster.php

To make sure that this script runs this way add the following line at the top of the script.

The script will look like,

#!/usr/bin/php
<?php
?>

Now I have to code in between the php tags.

Here goes my main script skeleton. The dowork() function does the main script logic.

My script should execute the main logic only when the trackChange event occurred. So I had to catch it. Amarok sends event information in the scripts STDIN. So I read the STDIN. And when its trackChange I call the dowork(). Very simple logic.

I also needed current song information. It can be collected by DCOP api. DCOP is desktop communication protocol. While running amarok issue the following command in consoe,
$ dcop amarok player title

You’ll see the current songs title.

This technique is used to get the current song information. My dowork function is,

One this I MUST say. Every amarok script archive must be a .amarokscript fie. That means when they are in tar archive it will be .amarokscriopt.tar extension and when they are in bz2 archive it will be .amarokscript.tar.bz2.

The script is created.

Now
1)Open amarok
2)Go to Tools->ScriptManger.
3)Click Install Script button
4)Browse the script and load it
5)Select the script and click RUN

I am a music lover. So I listen to musics a lot. I not only listen to music, but also share it. For this purpose I made a php script long time ago that is used for song broadcasting. In windows I used winmap’s “dosomething” plugin to broadcast. Nowadays I listen song in my linux machine. No winamp is there. I use amarok to listen song. Amarok