Re: [Rhythmbox-devel] RB Mp3Tunes plugin

On Sun, 2007-06-17 at 20:20 +0200, Federico Benedetto wrote:
> i'm writing a plugin to integrate Mp3Tunes in Rhythmbox
> ( ). I'm inspiring
> myself to the "magnatune plugin", but i'm encountering many problems: 
> 1) Tracks are loaded always when the plugin is activated: how can i
> manage to let them load only when cliking on the Mp3Tunes source? And
> how can i create an "update" button?

rb.Source has an "impl_activate" vfunc which you can override in python
by using "def do_impl_activate ...". This can get called multiple times,
so you'll want to do something similar to the Magnatune plugin, viz:

def do_impl_activate (self):
    if not self.activated:
        self.activated = True
        # do your stuff here

    rb.BrowserSource.do_impl_activate (self)

> 2) While loading the tracks, RB freezes completely for some
> minutes...i've read that i must use asynchronous IO, but i don't know
> how..can someone explain me? 

With normal (synchronous) IO you call a method asking for some data, and
it blocks until the data arrives - which causes RB to freeze. With
asynchronous IO, you ask for the data but tell it to notify you when the
data is available, so the method returns immediately and doesn't freeze
the application.

How you should perform IO depends a bit on what the data is; you can
either wait until all the data is ready and get it handed you as one big
chunk, stream the data so little chunks get handed to you as it arrived,
or copy the data to a local file and then read it.

Is the data you're reading some kind of track catalogue? If so, it's
probably a reasonable size and is worth caching locally so it doesn't
have to be retrieved every time. What the magnatune plugin does is check
whether the remote version is newer than the local copy (if it exists),
and if we either don't have a copy or we have an out-of-date one
download it. Once downloaded it just parses it normally. The
__update_catalogue() method of MagnatuneSource will probably help, but
feel free to ask if you have more questions.

> 3) How can I integrate my plugin with I would like to have
> the tracks played in the Mp3Tunes source scrobbled!

They should automatically be scrobbled if the following conditions are

1) the entry type belongs to the "normal" category (entry_type.category
is rhythmdb.ENTRY_NORMAL), which they are by default, not something else
like a stream.

2) the artist and title properties are set

3) the DURATION property is at least 30 seconds

> 4) What format is "PROP_DATE" using? I can't manage to give it the
> right year 

It's a Julian date, if you just have a year use:

import datetime
date =, 1, 1).toordinal()

> 5) How can i create a simple configuration dialog where the user can
> specify his login informations?

Plugins can implement a method called "create_configure_dialog", which
has to return a GtkDialog. If you implement this, RB will enable the
configure button in the plugins dialog, and show your dialog when

The lyrics plugin in svn, Magnatune plugin and Jamendo plugin all
implement this.

I'll write these up onto the wiki page[0] too, for future reference.



"25 grams of wafers and 20 ml of wine undergo transubstantiation and
become the flesh and blood of our Lord. How many Joules of heat are
released by the transformation?" --Theological Physics exam, 1997

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