daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 465 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From f82bd10b4456f5ab4a1b0f03439096806e17bdc7 Mon Sep 17 00:00:00 2001
  2. From: Michal Hruby <michal.mhr@gmail.com>
  3. Date: Thu, 10 Feb 2011 18:26:27 +0100
  4. Subject: [PATCH] Update the Zeitgeist plugin
  5.  
  6. ---
  7.  plugins/rbzeitgeist/rbzeitgeist/__init__.py |   53 +++++++++++++++------------
  8.  1 files changed, 30 insertions(+), 23 deletions(-)
  9.  
  10. diff --git a/plugins/rbzeitgeist/rbzeitgeist/__init__.py b/plugins/rbzeitgeist/rbzeitgeist/__init__.py
  11. index afc70ef..36383b3 100644
  12. --- a/plugins/rbzeitgeist/rbzeitgeist/__init__.py
  13. +++ b/plugins/rbzeitgeist/rbzeitgeist/__init__.py
  14. @@ -2,6 +2,7 @@
  15.  
  16.  # Copyright © 2009 Markus Korn <thekorn@gmx.de>
  17.  # Copyright © 2010 Laszlo Pandy <laszlok2@gmail.com>
  18. +# Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
  19.  #
  20.  # This program is free software; you can redistribute it and/or modify
  21.  # it under the terms of the GNU General Public License as published by
  22. @@ -25,10 +26,9 @@
  23.  # along with this program; if not, write to the Free Software
  24.  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
  25.  
  26. -import gobject
  27.  import time
  28.  
  29. -from gi.repository import RB
  30. +from gi.repository import GObject, Gio, RB
  31.  
  32.  from zeitgeist.client import ZeitgeistClient
  33.  from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
  34. @@ -58,18 +58,19 @@ class ZeitgeistPlugin(RB.Plugin):
  35.              self._shell = shell
  36.  
  37.              if IFACE.get_version() >= [0, 3, 2, 999]:
  38. -                IFACE.register_data_source("5463", "Rhythmbox", "Play and organize your music collection",
  39. +                IFACE.register_data_source("org.gnome.Rhythmbox,dataprovider", "Rhythmbox", "Play and organize your music collection",
  40.                                              [Event.new_for_values(actor="application://rhythmbox.desktop")]
  41.                                              )
  42.  
  43.      @staticmethod
  44.      def get_song_info(db, entry):
  45. +        # we don't want the PROP_MIMETYPE, as it doesn't contain mimetype
  46. +        # of the audio file itself
  47.          song = {
  48.              "album": entry.get_string(RB.RhythmDBPropType.PROP_ALBUM),
  49.              "artist": entry.get_string(RB.RhythmDBPropType.PROP_ARTIST),
  50.              "title":  entry.get_string(RB.RhythmDBPropType.PROP_TITLE),
  51.              "location": entry.get_string(RB.RhythmDBPropType.PROP_LOCATION),
  52. -            "mimetype": entry.get_string(RB.RhythmDBPropType.PROP_MIMETYPE),
  53.          }
  54.          return song
  55.  
  56. @@ -87,7 +88,7 @@ class ZeitgeistPlugin(RB.Plugin):
  57.              self.send_to_zeitgeist_async(entry, Interpretation.ACCESS_EVENT)
  58.  
  59.          self.__current_song = entry
  60. -        gobject.idle_add(self.reset_manual_switch)
  61. +        GObject.idle_add(self.reset_manual_switch)
  62.  
  63.      def reset_manual_switch(self):
  64.          """
  65. @@ -106,7 +107,7 @@ class ZeitgeistPlugin(RB.Plugin):
  66.          will have already received the eos if it was coming.
  67.          """
  68.          db = self._shell.get_property("db")
  69. -        gobject.idle_add(self.send_to_zeitgeist, db, entry, event_type)
  70. +        GObject.idle_add(self.send_to_zeitgeist, db, entry, event_type)
  71.  
  72.      def send_to_zeitgeist(self, db, entry, event_type):
  73.          song = self.get_song_info(db, entry)
  74. @@ -116,23 +117,29 @@ class ZeitgeistPlugin(RB.Plugin):
  75.          else:
  76.              manifest = Manifestation.SCHEDULED_ACTIVITY
  77.  
  78. -        subject = Subject.new_for_values(
  79. -            uri=song["location"],
  80. -            interpretation=unicode(Interpretation.AUDIO),
  81. -            manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
  82. -            #~ origin="", #TBD
  83. -            mimetype=song["mimetype"],
  84. -            text=" - ".join([song["title"], song["artist"], song["album"]])
  85. -        )
  86. -        event = Event.new_for_values(
  87. -            timestamp=int(time.time()*1000),
  88. -            interpretation=unicode(event_type),
  89. -            manifestation=unicode(manifest),
  90. -            actor="application://rhythmbox.desktop",
  91. -            subjects=[subject,]
  92. -        )
  93. -        #print event
  94. -        IFACE.insert_event(event)
  95. +        def file_info_complete(obj, res, user_data = None):
  96. +            fi = obj.query_info_finish(res)
  97. +            uri_mimetype = fi.get_content_type()
  98. +
  99. +            subject = Subject.new_for_values(
  100. +                uri=song["location"],
  101. +                interpretation=unicode(Interpretation.AUDIO),
  102. +                manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
  103. +                origin=song["location"].rpartition("/")[0],
  104. +                mimetype=uri_mimetype,
  105. +                text=" - ".join([song["title"], song["artist"], song["album"]])
  106. +            )
  107. +            event = Event.new_for_values(
  108. +                timestamp=int(time.time()*1000),
  109. +                interpretation=unicode(event_type),
  110. +                manifestation=unicode(manifest),
  111. +                actor="application://rhythmbox.desktop",
  112. +                subjects=[subject,]
  113. +            )
  114. +            IFACE.insert_event(event)
  115. +
  116. +        f = Gio.file_new_for_uri(song["location"])
  117. +        f.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, 0, None, file_info_complete)
  118.  
  119.      def deactivate(self, shell):
  120.          print "UNLOADING Zeitgeist plugin ......."
  121. --
  122. 1.7.0.4
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top