[PATCH 04/17] python: Cloned JavaScript test



Added a python test which, using gobject introspection, tries
to replicate JavaScript's functionality:

 * Initializes the framework
 * Gets the default registry
 * Loads the available plugins
 * Registers to "add/remove" events
 * Does a search using the plugins
---
 tools/python/testGrilo.py |   56 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 tools/python/testGrilo.py

diff --git a/tools/python/testGrilo.py b/tools/python/testGrilo.py
new file mode 100644
index 0000000..026d7da
--- /dev/null
+++ b/tools/python/testGrilo.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+
+import sys
+import gobject
+from gi.repository import Grl
+
+class SimplePlayList(object):
+
+    def __init__(self):
+        Grl.init([])
+        self.registry = Grl.PluginRegistry.get_default()
+        self.sources = []
+
+        self.registry.connect('source_added', self._source_added_cb)
+        self.registry.connect('source_removed', self._source_removed_cb)
+
+        if not self.registry.load_all():
+            print 'Failed to load plugins'
+
+    def search(self, search_term):
+        keyId = self.registry.lookup_metadata_key('id')
+        for source in self.sources:
+            print '%(name)s - %(term)s' % {'name':source.get_name(),
+                                           'term':search_term}
+            source.search(search_term, [keyId], 0, 10, 
+                          (Grl.MetadataResolutionFlags) (Grl.MetadataResolutionFlags.FULL |
+                                                         Grl.MetadataResolutionFlags.IDLE_RELAY),
+                          self._search_cb, source)
+
+    def _search_cb(self, source, op_id, media, remaining, data, error):
+        if media:
+            print '%(artist)s - %(album)s' % {'artist':media.get_artist(),
+                                              'album':media.get_album()}
+        else:
+            print 'No media to display'
+
+    def _source_added_cb(self, plugin_registry, media_source):
+        operations = media_source.supported_operations()
+        if operations & Grl.SupportedOps.SEARCH:
+            print ('Detected new source available %(name)s and it supports search'
+                   % {'name':media_source.get_name()})
+            self.sources.append(media_source)
+
+    def _source_removed_cb(self, plugin_registry, media_source):
+        print 'Source removed'
+
+if __name__ == '__main__':
+    play_list = SimplePlayList()
+    loop = gobject.MainLoop()
+    gobject.threads_init()
+
+    if len(sys.argv) > 1:
+        play_list.search(sys.argv[1])
+        loop.run()
+    else:
+        print 'Query parameter missing'
-- 
1.7.0.4



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