Navigation
 
Search
 
Random Image
E_DSC_0033.jpg
 
Me. Elsewhere.
 
Archives
 
Darcy
 
Things I Like
git
 
License
 
Amarok REST API

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'
    }
  }
}

Posted January 1st, 2009 - Permalink
Categories: Geek
Tags: , , , , , ,
No Comments »
 
Making DCOP work with Apache and PHP

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.

Posted January 1st, 2009 - Permalink
Categories: Geek
Tags: , , , , ,
No Comments »
 
More Posts
 
Copyright © 2006 - 2010 John Hobbs