Re: [Rhythmbox-devel] Magnatune catalog/purchasing plugin



On Wed, Jun 14, 2006 at 11:26:06PM -0700, Adam Zimmerman wrote:
> Brilliant, thank you! Looking at the ipod source definitely helped me
> better understand what I need to do.
> 
> On Thu, 2006-15-06 at 14:13 +1000, Jonathan Matthew wrote: 
> > On Wed, Jun 14, 2006 at 02:40:13PM -0700, Adam Zimmerman wrote:
> > > 
> > > - How do I add songs to my source? generic-player seems to get its own
> > > rhythmdb instance or something, and then call db.add_uri on the song
> > > (directory in that case). I tried this in the python console, and
> > > succeeded in adding a song to the library, so it seems right, just that
> > > I need a separate db (or do I?).
> > 
> > You don't need a separate db - there can only be one instance of the
> > database at the moment.  What everything does at the moment is retrieve
> > a reference to the db object from the shell object.  It looks like
> > you're already doing this correctly.
> > 
> 
> OK, good to know. So does rhythmbox decide what source to show an entry
> in by its entry-type?

Sources display entries using an RBEntryView instance (or rb.EntryView
in python).  The RBEntryView is a tree view backed by a
RhythmDBQueryModel, which is a GtkTreeModel that contains a set of
entries matching particular criteria.  So, an entry is shown in any
source for which it matches the query.


> > > - Is there a way to manually set the metadata for a track, so rhythmbox
> > > doesn't have to hit every mp3 file on magnatune?
> > 
> > Basically, look at how the ipod source works (add_ipod_song_to_db() in
> > rb-ipod-source.c).  It registers an entry type, then for each entry in
> > the ipod's database, it creates an entry (rhythmdb_entry_new), sets
> > various properties (rhythmdb_entry_set), then commits the changes
> > (rhythmdb_commit).  You may have some problems trying to do this in
> > python, though, since I don't think anyone has tried it before.
> > 
> > I'll have a look at this and the entry type data thing later on and post
> > more information.  I don't think we'll be making any changes until we
> > release 0.9.5, which should be fairly soon.
> > 
> 
> OK, this is the part I still need some help on. From what you're saying,
> I gather that my source needs to create its own entry type, right? Right
> now I'm doing this:
> 
> def activate(self, shell):
> 	db = shell.get_property("db")
> 	model = db.query_model_new_empty()
> 	entry_type = rhythmdb.rhythmdb_entry_register_type("")

It's not actually important (yet?) but it's a good idea to specify a
name for your entry type.  You also need to keep hold of the entry type,
so that should probably be 'self.entry_type = ...'.

> 	self.source = gobject.new (MagnatuneSource, shell=shell,
> name=_("Magnatune"), query_model=model)
> 	shell.register_entry_type_for_source(self.source, entry_type)
> 	shell.append_source(self.source, None)
> 		
> Do I also need to do something when creating self.source?

You should be creating a query model like this:

query = db.query_parse(rhythmdb.QUERY_PROP_EQUALS, 
		         rhythmdb.PROP_TYPE, self.entry_type)
model = db.query_model_new(query)

except query_parse doesn't seem to be available in python (codegen says vararg
functions are not supported), so .. ignore this part for now.

Instead, what you can do is model.add_entry(entry, -1) for each entry
after the db.commit() call, which will manually insert each entry at the
end of the model.  We'll need to make query_parse available in
python so you can implement searching or browsing, sooner or later.

> And then in the endElement method of the xml handler, I have:
> 
> def endElement(self, name):
> 	if name == "Track":
> 		print "Adding: %s - %s" % (self._track['artist'],
> self._track['trackname'])
> 		# add the track to the source
> 		entry = self._db.entry_new(entry_type, self._track['url']) # how do we
> get the entry type for the source?
> 		
> 		self._db.entry_set_uninserted(entry, rhythmdb.PROP_ARTIST,
> self._track['artist'])
> 		self._db.entry_set_uninserted(entry, rhythmdb.PROP_ALBUM,
> self._track['albumname'])
> 		self._db.entry_set_uninserted(entry, rhythmdb.PROP_TITLE,
> self._track['trackname'])
> 		# etc., etc.
> 			
> 		self._db.commit()
> 		self._track = {}
> 	elif name == "AllSongs":
> 		pass # end of the file
> 	else:
> 		self._track[name] = self._text
> 
> The problem is, I'm not sure how to get the entry_type argument for the
> call to entry_new. I've tried various things, and it keeps saying:
> TypeError: type should be a RhythmDBEntryType_

This should just be self.entry_type, I think.  Otherwise, it looks like
you're on the right track.





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