Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From f82bd10b4456f5ab4a1b0f03439096806e17bdc7 Mon Sep 17 00:00:00 2001
- From: Michal Hruby <michal.mhr@gmail.com>
- Date: Thu, 10 Feb 2011 18:26:27 +0100
- Subject: [PATCH] Update the Zeitgeist plugin
- ---
- plugins/rbzeitgeist/rbzeitgeist/__init__.py | 53 +++++++++++++++------------
- 1 files changed, 30 insertions(+), 23 deletions(-)
- diff --git a/plugins/rbzeitgeist/rbzeitgeist/__init__.py b/plugins/rbzeitgeist/rbzeitgeist/__init__.py
- index afc70ef..36383b3 100644
- --- a/plugins/rbzeitgeist/rbzeitgeist/__init__.py
- +++ b/plugins/rbzeitgeist/rbzeitgeist/__init__.py
- @@ -2,6 +2,7 @@
- # Copyright © 2009 Markus Korn <thekorn@gmx.de>
- # Copyright © 2010 Laszlo Pandy <laszlok2@gmail.com>
- +# Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- @@ -25,10 +26,9 @@
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- -import gobject
- import time
- -from gi.repository import RB
- +from gi.repository import GObject, Gio, RB
- from zeitgeist.client import ZeitgeistClient
- from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
- @@ -58,18 +58,19 @@ class ZeitgeistPlugin(RB.Plugin):
- self._shell = shell
- if IFACE.get_version() >= [0, 3, 2, 999]:
- - IFACE.register_data_source("5463", "Rhythmbox", "Play and organize your music collection",
- + IFACE.register_data_source("org.gnome.Rhythmbox,dataprovider", "Rhythmbox", "Play and organize your music collection",
- [Event.new_for_values(actor="application://rhythmbox.desktop")]
- )
- @staticmethod
- def get_song_info(db, entry):
- + # we don't want the PROP_MIMETYPE, as it doesn't contain mimetype
- + # of the audio file itself
- song = {
- "album": entry.get_string(RB.RhythmDBPropType.PROP_ALBUM),
- "artist": entry.get_string(RB.RhythmDBPropType.PROP_ARTIST),
- "title": entry.get_string(RB.RhythmDBPropType.PROP_TITLE),
- "location": entry.get_string(RB.RhythmDBPropType.PROP_LOCATION),
- - "mimetype": entry.get_string(RB.RhythmDBPropType.PROP_MIMETYPE),
- }
- return song
- @@ -87,7 +88,7 @@ class ZeitgeistPlugin(RB.Plugin):
- self.send_to_zeitgeist_async(entry, Interpretation.ACCESS_EVENT)
- self.__current_song = entry
- - gobject.idle_add(self.reset_manual_switch)
- + GObject.idle_add(self.reset_manual_switch)
- def reset_manual_switch(self):
- """
- @@ -106,7 +107,7 @@ class ZeitgeistPlugin(RB.Plugin):
- will have already received the eos if it was coming.
- """
- db = self._shell.get_property("db")
- - gobject.idle_add(self.send_to_zeitgeist, db, entry, event_type)
- + GObject.idle_add(self.send_to_zeitgeist, db, entry, event_type)
- def send_to_zeitgeist(self, db, entry, event_type):
- song = self.get_song_info(db, entry)
- @@ -116,23 +117,29 @@ class ZeitgeistPlugin(RB.Plugin):
- else:
- manifest = Manifestation.SCHEDULED_ACTIVITY
- - subject = Subject.new_for_values(
- - uri=song["location"],
- - interpretation=unicode(Interpretation.AUDIO),
- - manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
- - #~ origin="", #TBD
- - mimetype=song["mimetype"],
- - text=" - ".join([song["title"], song["artist"], song["album"]])
- - )
- - event = Event.new_for_values(
- - timestamp=int(time.time()*1000),
- - interpretation=unicode(event_type),
- - manifestation=unicode(manifest),
- - actor="application://rhythmbox.desktop",
- - subjects=[subject,]
- - )
- - #print event
- - IFACE.insert_event(event)
- + def file_info_complete(obj, res, user_data = None):
- + fi = obj.query_info_finish(res)
- + uri_mimetype = fi.get_content_type()
- +
- + subject = Subject.new_for_values(
- + uri=song["location"],
- + interpretation=unicode(Interpretation.AUDIO),
- + manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
- + origin=song["location"].rpartition("/")[0],
- + mimetype=uri_mimetype,
- + text=" - ".join([song["title"], song["artist"], song["album"]])
- + )
- + event = Event.new_for_values(
- + timestamp=int(time.time()*1000),
- + interpretation=unicode(event_type),
- + manifestation=unicode(manifest),
- + actor="application://rhythmbox.desktop",
- + subjects=[subject,]
- + )
- + IFACE.insert_event(event)
- +
- + f = Gio.file_new_for_uri(song["location"])
- + f.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, 0, None, file_info_complete)
- def deactivate(self, shell):
- print "UNLOADING Zeitgeist plugin ......."
- --
- 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement