3
# Copyright (c) 2011 David Calle <davidc@framli.eu>
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from gi.repository import GLib, GObject, Gio
19
from gi.repository import Dee
20
_m = dir(Dee.SequenceModel)
21
from gi.repository import Unity
22
import socket, urllib, urllib2, simplejson
24
socket.setdefaulttimeout(5)
25
BUS_NAME = "net.launchpad.scope.music.score.songsterr"
29
self.scope = Unity.Scope.new ("/net/launchpad/scope/music/score/songsterr")
30
self.scope.search_in_global = False
31
self.scope.connect ("notify::active-search", self.on_search_changed)
32
self.scope.connect ("filters-changed", self.on_search_changed);
35
def get_search_string (self):
36
search = self.scope.props.active_search
37
return search.props.search_string if search else None
39
def on_search_changed (self, scope, param_spec=None):
40
search = self.get_search_string()
41
print "Search changed to: '%s'" % search
42
results = self.scope.props.results_model
44
self.update_results_model (search, results)
45
results.flush_revision_queue ()
47
def update_results_model(self, search, model):
48
for i in self.songsterr(search):
53
model.append (uri, icon_hint, 0,"text/html", title, comment, uri)
54
model.append (uri, icon_hint, 1,"text/html", title, comment, uri)
58
# <http://www.songsterr.com/a/wa/api>
60
def songsterr(self, search):
61
from xml.dom import minidom
64
url = ('http://www.songsterr.com/a/ra/songs.xml?pattern=%s' % search)
66
dom = minidom.parse(urllib2.urlopen(url))
69
for node in dom.getElementsByTagName('Song'):
71
song_id = node.getAttribute('id')
72
for node2 in node.getElementsByTagName('title'):
73
title = node2.firstChild.data
74
for node2 in node.getElementsByTagName('artist'):
75
if node2.getAttribute('type')=='Artist':
76
artist_id = node2.getAttribute('id')
77
for node3 in node2.getElementsByTagName('name'):
79
artist = node3.firstChild.data
81
artistDict[artist_id] = artist
82
artist = artistDict[artist_id]
84
item_list.append(title)
85
item_list.append(artist)
86
item_list.append('http://www.songsterr.com/a/wa/song?id=' + song_id)
87
item_list.append('sound')
88
data_list.append(item_list)
95
if __name__ == "__main__":
96
session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
97
session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
98
'org.freedesktop.DBus',
99
'/org/freedesktop/DBus',
100
'org.freedesktop.DBus', None)
101
result = session_bus.call_sync('RequestName',
102
GLib.Variant ("(su)", (BUS_NAME, 0x4)),
105
# Unpack variant response with signature "(u)". 1 means we got it.
106
result = result.unpack()[0]
109
print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
113
GObject.MainLoop().run()