Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, April 08, 2010

Combo station urls

In this blog post I'll tell you how to create Last.fm combo station urls. Last.fm station urls always start with "lastfm://". For combo station urls, an example might look like
lastfm://rql/dGFnOnBvcCBub3Qgc2ltYXJ0OiJMYWR5IEdhZ2Ei
See that long character string after rql/ ? That is just simple Base64 encoding and RQL means "Radio Query Language". If you'd use a decoder like this one,it will decode to
tag:pop not simart:"Lady Gaga"
So, there are key-value pairs and logical connectors (valid ones are 'and', 'or' and 'not'). The above query means "play everything in direction of 'pop' tag, but not Lady Gaga's similiar artists". I think you got the idea...
The point I did not mention yet is that there are some nice options available. Let's change our query a bit:
tag:pop not simart:"Lady Gaga" opt:mainstr|0.55 opt:rep|0.6 opt:discovery|true
Huh? Lots of opt(ions)! mainstr stands for "Maintream", where the value range is from 0-1(0% to 100%). The less the value, the more unknown artists will occur in your station. Same goes for rep(etition), but in this case you can control the artist(or track?) repetition rate. I think "discovery" is kind of self-explanatory(discovery mode on/off). Here you got a nice table with names, values and descriptions:
NameValueDescription
user[username]personal station
library[username]a users library
loved[username]loved tracks of user. After Nov 17 2010 this station is not available anymore!
rec[username]recommendations for a user
neigh[username]neighbour radio of user
ptag[tag of user]|[username]Personal tag radio of a user. The '|' is NO or!. After Nov 17 2010 this station is not available anymore!
playlist[playlist-id]A playlist station. Use user.getPlaylist API call to get playlist id's of a user's playlist. After Nov 17 2010 this station is not available anymore!
adv[username]Play a user's mix radio.
simart"[artist name]"Similiar artists of an artist. Keep the quotes around.
tag[tag]Global tag radio
group"Group Name" or [groupid]Group radio
opt:rep|[0-1](default: 0.5)Specifies the track repetition, means how long it will take until the track is played again
opt:mainstr|[0-1] (default: 0.5)Type of tracks played(obscure to popular)
opt:discovery|[true|false] (default: false)Discovery mode on/off
Note that the options are all optional and thus have a default value. Connect name and value with a ':', except for the opt: values. If a value contains a space, it must be enclosed with double-quotes(""). Known Issues
  • Discovery mode is subscribers only.
  • In the Base64 RFC specification there is a space after 76 characters in the encoded string. Apparently the web and the desktop client cannot handle this space, so you have to remove it and everything will work fine.
Have fun with constructing the urls and implementing it in your app!
Very much thanks to Norman (nova77LF)(glorious creator of the Radio Query Language) for clarification on some points :)

Sunday, March 14, 2010

Testing Java HTML parsers

A few weeks ago I had to code some data export for which I had to test the speed of a bunch of Java HTML parser/cleaner libraries to have a valid XHTML output.
Jens proposed me to publish the results here and I thought that would be a really great idea.
At first, I'd like to present each one to you first and hopefully give some useful pieces of information on them. "Maven" means if the library can be found in the Maven repositories.

Jericho HTML-Parser

License: Eclipse Public License/LGPL
Maven: Yes
Has many features, like recognizing PHP tags and is easy to use.

JTidy

License: MIT License
Maven: Yes, but only the "old" builds
JTidy is tiny and pretty fast, can output wellformed XHTML.
Has bad internal exception handling(lots of empty catch blocks!)

HTMLCleaner

License: BSD License
Maven: No
DOM based, supports XPATH(really cool). Has a good bunch of confuguration options.

NekoHTML

License: Apache Software License
Maven: Yes
Good, fast, seems to be famous

TagSoup

License: Apache 2.0
Maven: Yes
Parses HTML and provides a SAX handler. Entry class is "Parser" to which a custom SAX handler can be given.

HTML Parser

License: GPL

HotSAX

License: LGPL
HotSAX looked pretty fast, but according to the homepage it is still in pre-alpha stadium, so it was not useful for my task.

Java Swing HTML parser

Comes with Sun Java.
XHTML is a more strict form of HTML 4.01, but this parser only supports HTML 3.2, so it was not in question for my purposes. Just wanted to mention it here.

Cobra: Java HTML Renderer and Parser

License: LGPL 2.1
Major plus of this one is that it is capable of parsing js and CSS, too. The browser is a good start(my admiration for that project!) although it fails all ACID tests. But nevertheless, this hasn't to say anything about the parser's quality.
One con is that this library is really slow.

Mozilla Java HTML-Parser

License: Mozilla Public License 1.1 (MPL 1.1)
The setup is not really suitable for a multi-developer setup so it fell out of the test selection.

Test results

Task was to load a predefined, really errorneous HTML document and select all <a> tags.
I used JUnit tests for each parser/cleaner and the measurement was taken ten times, while the first one was skipped due to the compilation time.
RankNameTime/msDeviation/ms
1HTMLCleaner95±18
2HotSAX124±19
3JTidy158,3±17
4Jericho HTML150±59
5NekoHtml380±44
6TagSoup439±50,5
7Cobra675±100


Jtidy is listed before Jericho HTML because it had the better deviation.I first used HTMLCleaner, because its advance in time was really big. The problem was that it couln't handle some of the real input data. HotSAX was pre-alpha(although the results are very good), so JTidy was my next choice as I needed reliability. I had not a single problem with it, it works really fine.
Last point to say is that the results of the Cobra parser are very bad...

Jens is working on a website so I can provide you the testing source code, I will put a link to there when it is online.
If anyone is interested in more detailed statistics, just contact me and I'll put them here.

As someone recently has begun to work on JTidy again, I'll try the SVN version soon and tell you the results in another post, promise! I hope they improved the exception handling.
Have a look at this piece of code:
public Node parse(InputStream in, OutputStream out)
{
Node document = null;

try
{
document = parse(in, null, out);
}
catch (FileNotFoundException fnfe) {}
catch (IOException e) {}

return document;
}

That's gruesome, isn't it?

Sunday, February 28, 2010

A few words about myself

Hey!
My name is Tobias and I was born on 26 Oct 1989. I currently live in Dortmund and study physics, but my heart still is in Remscheid(Germany) where the discoverer of the X-rays, Wilhelm Conrad Röntgen, was born.
Physics is really fun to me, because all physicans are staying children and love to play(including me).
There's just another point to mention: I love programming, mainly Java and Visual Basic.net.
Most people think physics and informatics are unrelated to each other, but in my opinion that isn't really true. In both you have to solve problems in a strictly logical way. Because I code since I was in 2nd class of elementary school it really formed my way of thinking this way, to have a problem, split it into tiny pieces, reduce it to something simple and then just solve it. Same way as you do in physics, too.
The bad thing about physics is that in moste cases it is way to expensive as a hobby, but programming is not.
So I stick with programming. I currently work for a small, but really great software company called headissue which develops for a ticketing page for events in and around there using Java. The work there is very much fun to me, although the problems to solve sometimes could drive me nuts.

Privately my main interest is for Last.fm and its API, so I'll post here about that from time to time, too. My main projects are LastFmLib.net, a .net library for the API and LastFVS.
LastFVS is something similiar to Google Moderator, but way better. It was annoying that there were feature requests in the web services forum but no overview and no vote counter was available. LastFVS perfectly fills that gap, offering a good voting functionality, login via last.fm account and a comment functionality which supports some BB-codes, too.

Hope you will visit my blog from time to time, I promise that I'll try hard to present you an interesting mix of (mainly technology, programming and last.fm related) topics :)
If you'd like to, you can also subscribe to the atom feed of this blog. If you are using Firefox, the FeedSidebar add-on is a good point to start with.