Tag: Amarok

Amarok REST API

January 1, 2009 » Geek

I’ve been working on the guts of a REST API for Amarok though PHP and DCOP. Thought I’d share my JSON format because I’m proud of it. Also because I’m bound to lose the format file sooner or later.

There are two basic things you can do with Amarok: take an action and ask for information. So that’s how I broke it down, action and info blocks in every request.

Rather than codify it in any formal way I’m just going to show examples.

Action – Toggle play/pause condition
Request

{
  'action': {
    '0': {
      'name':'playPause',
      'params': false
    }
  }
}

Response

{
  'action': {
    '0': {
      'name':'playPause',
      'error':false
    }
  }
}

Action – Play and set the equalizer
Request

{
  'action': {
    '0': {
      'name':'play',
      'params': false
    },
    '1': {
      'name':'setEqualizer',
      'params': {
        '0':'20',
        '1':'30',
        '2':'40',
        '3':'10',
        '4':'20',
        '5':'30',
        '6':'40',
        '7':'10',
        '8':'20',
        '9':'30',
        '10':'40',
        '11':'10',
      }
    }
  }
}

Response

{
  'action': {
    '0': {
      'name':'playPause',
      'error':false
    },
    '1': {
      'name':'setEqualizer',
      'error':false
    }
  }
}

Info – Get playing track album name
Request

{
  'info': {
    '0': {
      'name':'album',
      'params': false
    }
  }
}

Response

{
  'info': {
    '0': {
      'name':'album',
      'value':'Doppleganger'
    }
  }
}

Info – Get playing track album name, artist and title.
Request

{
  'info': {
    '0': {
      'name':'album',
      'params':false
    },
    '1': {
      'name':'artist',
      'params':false
    },
    '3': {
      'name':'title',
      'params':false
    }
  }
}

Response

{
  'info': {
    '0': {
      'name':'album',
      'value':'Doppleganger'
    },
    '1': {
      'name':'artist',
      'value':'The Fall of Troy'
    },
    '3': {
      'name':'title',
      'value':'F.C.P.R.E.M.I.X'
    }
  }
}

Both – Go to next track, get that track artist.
Note: I have decided that when both action and info are present they will alternate execution starting on action (i.e. action 0 then info 0 then action 1 and so on.) Thus we will probably want to create a NOP at some point.
Request

{
  'action': {
    '0': {
      'name':'next',
      'params': false
    }
  },
  'info': {
    '0': {
      'name':'artist',
      'params':false
    }
  }
}

Response

{
  'action': {
    '0': {
      'name':'playPause',
      'error':false
    }
  },
  'info': {
    '0': {
      'name':'artist',
      'value':'Far-Less'
    }
  }
}

Making DCOP work with Apache and PHP

January 1, 2009 » Geek

I’ve been working on a design for a web technology based media frame (think digital photo frame that you can program). I have my hardware ducks in a row (ripped apart a laptop, rewired some buttons and flipped the screen around) and now I’m working on software. I put together a reasonable frame work and then decided to add some integration with Amarok. That got hairy fast.

I found a PHP5 DCOP library but no explanation on how to get it to work. Google got me to the point where I knew it was an environment variable thing (the command line dcop has to have access to an X display since DCOP uses X’s ICE protocol to do it’s thing). Unfortunately trying to set the DISPLAY in the exec call doesn’t work, never found out why. Neither did the next 100 things I tried.

Skipping past all that anger and frustration that brought me to a solution, and here it is.

BEWARE this isn’t really a safe way to run a server. If you want to do this, be sure that it is on a machine that can’t harm the rest of your network or files. If you know a better way or some tips on locking things down, please share!

This is all done assuming a Debian machine base.

1)
Make a full-fledged but restricted user. They must have an KDE login, and X must be running with them logged in. Let’s call our user notagoodidea for this example.
2)
Make apache2 run as your user by editing /etc/apache2/envvars

# envvars - default environment variables for apache2ctl

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.

#export APACHE_RUN_USER=www-data
#export APACHE_RUN_GROUP=www-data
export APACHE_RUN_USER=notagoodidea
export APACHE_RUN_GROUP=notagoodidea
export APACHE_PID_FILE=/var/run/apache2.pid

3)
Edit your run script to launch Apache with the DISPLAY variable set, so edit /etc/init.d/apache2 which will probably break on updates and makes me cringe.

...
# apache2               This init.d script is used to start apache2.
#                       It basically just calls apache2ctl.

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin DISPLAY=:0.0"
...

4)
Restart everything and test it out.

It isn’t pretty but it gets the job done.

Amarok Just Gets Cooler

February 22, 2007 » Geek

It’s all in the details man. All of it. Okay not all of it, but a whole huge honkin lot of it.

I had added some Relient K albums to my playlist, but I wanted them higher in the list (right under Run Kid Run) so I selected and dragged them upwards. What did my eyes behold? Something I didn’t expect. I stuck the cover art from the albums right there next to the cursor.

How cool is that?

Now, I don’t know if this essentially useless feature is in any other music program, but it’s got me dragging stuff around and making little collages out of cover art.

You can click through for a full-desktop screenie if you really want to.

Amarok Dragging Album Art

Tags:

Amarok 1.4.2

August 31, 2006 » Geek

I just updated my install of Amarok, which is possibly the greatest music player / jukebox ever. I’d heard alot about the new version, most of it being about the new native capability to play last.fm radio streams without any hacks.

I have to say, I like the new version, it’s gotten a bit of a facelift and somethings have changed. I like the fact that your collection has alphabetic dividers, it makes it easier to find artists.

The site claims that it has added support for MTP devices, but I haven’t hooked my precious Zen MicroPhoto up to it yet. Anyway, just putting up a post recommending the new Amarok.