Friday, September 07, 2007

Playlist language

This code has been sitting in my homedir for quite a while, finally got around to clean it up enough to publish it. There still is way too many rough edges, but the implementation isn't very interesting anyway.

I wanted a readable language for custom playlist formatting, instead of some hard to read string like: $if(%album artist%,%album%,%artist%)|$if(%album artist%,$num(%tracknumber%,2) - %title%,%album%)|$if($not(%album artist%),$num(%tracknumber%,2) - %title%)

Playlists are pretty much rows of data, which should be processed one by one, doing different things depending on what they contain. So lets have a language that has the form list(predicate + list(actions)), a bit like awk. There is no need to have multiple levels of nesting, so making use of indentation should be simple, a bit like python.

So, without further delay, here is an example in the playlist language where awk meets python:

:title && :artist == lastartist
pad(lastartist)
emit(" + ")
emit(:title)
emit(CR)
done()

:title && :artist
emit()
emit(:artist)
emit(" - ")
emit(:title)
set(lastartist, :artist)
emit(CR)
done()

"always"
set(lastartist, "")
emit(:url)
emit(CR)


...and here is the (crappy) implementation. There is no loops and things to avoid the halting problem.



BTW. I put the cunit-wrapper in git aswell, and added an example that is a 1:1 conversion of the cunit example.

Labels: , ,

0 Comments:

Post a Comment

<< Home