[Rhythmbox-devel] Looking for the right attributes to write a plugin



Dear Rhythmbox developers

I want to write my own plugin to log extra data of my listening behavior but I'm having trouble to find the right attributes as I call them.
I can find a lot of examples but they don't seem to work on the new version of Rhythmbox (2.96).

Can someone tell me how to find basic attributes or functions that give me i.e. the title and artist of a specific song entry.
I can navigate through the rhythmbox 'tree' but it is huge and I can't find useful functions or I don't know what arguments they need.

Another question. If I type "dir()" in the Python Console, I get ['RB', '__builtins__', '__history__', 'shell'].
How can I address the attributes under 'RB' and 'shell' in my plugin?
Where do I find signals in this 'tree' of Rhythmbox like the signal that a song has changed whereto I can connect?

To support my questions, I have pasted my draft plugin below.
It may look messy. It is a collection of several snippets.
I'm not yet experienced with programming in Python but I'm working on that...

Thanks in advance
Kind Regards
Dimitri Van Dingenen

from datetime import datetime, date, time
from gi.repository import GObject, RB, Peas, Gtk
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop

class TopList (GObject.Object, Peas.Activatable):
    object = GObject.property(type=GObject.Object)

    def __init__(self):
        super(TopList, self).__init__()

    #Path of new menu item to create a playlist
    self.uiPlaylist = """
    <ui>
      <menubar name="MenuBar">
        <menu name="MusicMenu" action="">
            <menu name="PlaylistMenu" action="">
             <menuitem name="Top Hits Playlist" action=""/>
            </menu>
        </menu>
      </menubar>
    </ui>
    """
   
    def do_activate(self):
    shell = self.object
    self.psc_id = shell.props.shell_player.connect("playing_song_changed", self.playing_song_changed)

    # First lets see if we can add to the context menu
        ui = shell.props.ui_manager

        # Create Actions for the plugin
        action = "" ('CreateList', ('Create TopList Playlist'),(''),"")
        activate_id = action.connect ('activate', self.Create_List, shell)

        # Group and it's actions
        self.action_group = Gtk.ActionGroup ('CreateListActions')
        self.action_group.add_action (action)
        ui.insert_action_group(self.action_group, -1)

        # Add to the UI
        self.uid = ui.add_ui_from_string(self.uiPlaylist)
        ui.ensure_update()

    def do_deactivate(self):
    shell = self.object
    print 'Deactivate!'

    shell.props.shell_player.disconnect(self.psc_id)

    # Clean up UI
        ui = shell.props.ui_manager
        ui.remove_ui(self.uid)
        ui.remove_action_group(self.action_group)

    def Create_List(self, action, shell):

    shell = self.object   

    entry = shell.props.shell_player.get_playing_entry
    print 'Holy Smokes, not finished yet!'
   
    db = shell.props.db

    #Here I would like to do some math-magic on the 'database' to create a playlist.
    #next lines didn't work:
    #(artist, title) = get_artist_and_title(db, entry)
    #artist = entry.get_string(RB.RhythmDBPropType.ARTIST)
    #title = entry.get_string(RB.RhythmDBPropType.TITLE)
    #title = RB.RhythmDB.entry_get (self, entry, enum.RhythmDBPropType.TITLE)
    #title = entry.get_string(self, RB.RhythmDBPropType.TITLE)
        #artist = shell.props.db.entry_get(self, entry, RB.RhythmDBPropType.ARTIST)
        print "Listening to: %s by %s" % (title, artist)
   

    def    playing_song_changed(self, entry, user_data):
    self.Now=datetime.now()
    self.TimeCode=self.Now.strftime("%y.%m.%d.%H.%M.%S")
    print self.TimeCode   
    print 'song changed!'
    print entry
    #Here I would like to log all songs played longer than 50% in a 'database'
    #for now I'm playing to find useful attributes...
    #next line didn't work:
    #shell.props.shell_player.do_playing_uri_changed


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