[Rhythmbox-devel] A new pythonic rhythmdb module



Hello everyone,

I picked up this book from the library called 'Python Essential
Reference' by David M. Beazly today which is really helpful if you
want to learn about Python.  It's a useful reference to have at your
side.

Anyways.  I wrote up a pythonic rhythmdb replacement called
RhythmDB.py

It has two classes RhythmDB and Song.  I'm pretty happy with it and
have no idea if you can already do something like this in the current
framework, if you can then the documentation should be improved, but I
know it's something that not many people like to do except for the
folks over at Django.

I assume a lot about the structure of the file, but it works.  I could
spend some time to make it more robust, but it was fun implementing
all of this, so here you go.

from RhythmDB import *

#open db it assumes you it's in ~/.local/share/rhythmbox/rhythmdb.xml
db = RhythmDB()

rocksongs = db.get('genre', 'rock')

#Get number of songs in rocksongs
len(rocksongs)

#get duration of all of the rocksongs
sum([ len(song) for song in rocksongs ])

#get 10 random rocksongs
import random
random.sample(rocksongs,10)

#Get songs by Mos Def

mosdefsongs = [ song for song in db.find('artist', 'mos def') ]

========

So that's about it it.  I hope people like this.  I was thinking of
trying to wrap the db.query_model in an interface like this but I
thought I'd try it with this implementaiton because.

I'll have to try it out on 0.13 which I haven't compiled.

-Neskie


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]