[neurosetta] Re: More on Playlists

Stan Seibert volsung at mailsnare.net
Wed Jul 2 11:15:01 PDT 2003



On Wed, 2003-07-02 at 11:21, Joseph Martin wrote:
> myn = neuros.Neuros('/home/martinja')
> db = myn.open_db('audio')
> pldb = db.children[0]
> if len(sys.argv) > 1:
>     pldb.add_record([sys.argv[1]])
>     myn.close_db('audio')

<p>This will indeed add a record to the child database for playlists, but
it will create a playlist that has no tracks.  However, you should never
need to add records directly to child databases, because the db modules
will do that for you, and keep some other bookkeeping straight.  Instead
you should create records in the main database that have non-null values
for the playlist entry (which relates to your other question).

A good example of how to add records to the audio database is in
add_file.py:add_track():

record = (metadata["title"], None, metadata["artist"],
         metadata["album"],
        metadata["genre"], recording, metadata["length"],
        metadata["size"] // 1024,
        neuros.hostpath_to_neurospath(targetname))

# Add entry to database
neuros.db["audio"].add_record(record)

Ignore the weird variables I'm pulling the data from.  The basic idea is
that a record is a tuple with fields in the order shown above. 
(Incidentally, the positron developer's guide lists the fields and their
order)  The "None" is in the playlist slot.  All you have to do is
replace that with a string that corresponds to the name of your playlist
when you add a track, and you're all set. For example:

record = ("My Song", "playlist1", "My Artist", "Green Album", "Bad
Music", None, 312, 1068, "C:/music/foo.mp3")

You can be a member of multiple playlists at once:

record = ("My Song", ("bad music", "banjos"), "My Artist", "Green
Album", "Bad Music", None, 312, 1068, "C:/music/foo.mp3")

<p>However, I suspect that you will want to actually update existing
records to be in a playlist.  Currently, there is no way to update
entries in place, because this turns out to be non-trivial.  You can
locate the record you want to change, retrieve it, delete it from the
database, change the playlist field, and then re-add it.  Longer term,
when I add update support to the WOID module, I will basically do this
same thing, except for the cases where it is feasible to do the update
in place.  (As it happens, most playlist updates would fall under this
latter category.)


---
Stan Seibert

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Neurosetta homepage: http://www.neurosetta.org/
To unsubscribe from this list, send a message to 'neurosetta-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Neurosetta mailing list