~mikaelsahlstrom/onehundredscopes/spotify

« back to all changes in this revision

Viewing changes to src/unity-scope-spotify

  • Committer: Mikael Sahlström
  • Date: 2012-01-18 20:33:29 UTC
  • Revision ID: mick.sahlstrom@gmail.com-20120118203329-jnaye6bbtukag8rz
Results will be presented faster due to more cacheing. Genres works better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
                self.scope.connect("notify::active-search", self.on_search_changed)
38
38
                self.scope.connect("filters-changed", self.on_search_changed)
39
39
                self.scope.export()
 
40
                self._albumart = {}
40
41
 
41
42
        def get_search_string(self):
42
43
                search = self.scope.props.active_search
58
59
        def update_results_model(self, search, model):
59
60
                if search is None or search == "":
60
61
                        return
 
62
                
61
63
                filters = ""
62
64
                
63
65
                f = self.scope.get_filter("decade")
69
71
                        if option.props.active:
70
72
                                if option.props.id != "other":
71
73
                                        if i == 0:
72
 
                                                filters = filters + self._genre(option.props.id)
 
74
                                                filters = filters + "genre:" + self._genre(option.props.id)
73
75
                                                i = 1
74
76
                                        else:
75
 
                                                filters = filters + "%20OR%20" + self._genre(option.props.id)
 
77
                                                filters = filters + "," + self._genre(option.props.id)
76
78
                
77
79
                search = quote(search)
78
80
                search = search.replace("%20", "+")
109
111
 
110
112
                if self.scope.props.active_search:
111
113
                        self.scope.props.active_search.emit("finished")
 
114
                self._albumart = {}
112
115
 
113
116
        def _search_artist(self, query, page = 1):
114
117
                url = "http://ws.spotify.com/search/%s/artist.json?q=%s" % (page, query)
144
147
                        return None
145
148
 
146
149
        def _get_thumb_path(self, uri):
 
150
                if self._albumart.get(uri) is not None:
 
151
                        return self._albumart.get(uri)
147
152
                turi = uri
148
153
                try:
149
154
                        uri = uri.split(':')
151
156
                        thumb_start = url.find('<meta property="og:image" content="')
152
157
                        thumb_end = url.find('" />',thumb_start)
153
158
                        url = url[thumb_start+35:thumb_end]
 
159
                        self._albumart[turi] = url
154
160
                        return url
155
161
                except URLError, e:
156
162
                        print e.code
162
168
        def _genre(self, g):
163
169
                # Transform the genre filter to corresponding spotify filters.
164
170
                if g == "blues":
165
 
                        return "genre:blues"
 
171
                        return "blues"
166
172
                elif g == "country":
167
 
                        return "genre:country"
 
173
                        return "country"
168
174
                elif g == "disco":
169
 
                        return "genre:post-disco"
 
175
                        return "post-disco"
170
176
                elif g == "funk":
171
 
                        return "genre:funk"
 
177
                        return "funk"
172
178
                elif g == "rock":
173
 
                        return "genre:rock"
 
179
                        return "rock"
174
180
                elif g == "metal":
175
 
                        return "genre:metal"
 
181
                        return "metal"
176
182
                elif g == "hip-hop":
177
 
                        return "genre:hip-hop%20OR%20genre:rap"
 
183
                        return "hip-hop,rap"
178
184
                elif g == "house":
179
 
                        return "genre:house"
 
185
                        return "house"
180
186
                elif g == "new-wave":
181
 
                        return "genre:new-wave"
 
187
                        return "new-wave"
182
188
                elif g == "r-and-b":
183
 
                        return "genre:R%26amp%3BB"
 
189
                        return "R%26amp%3BB"
184
190
                elif g == "punk":
185
 
                        return "genre:punk"
 
191
                        return "punk"
186
192
                elif g == "jazz":
187
 
                        return "genre:jazz"
 
193
                        return "jazz"
188
194
                elif g == "pop":
189
 
                        return "genre:pop"
 
195
                        return "pop"
190
196
                elif g == "reggae":
191
 
                        return "genre:reggae"
 
197
                        return "reggae"
192
198
                elif g == "soul":
193
 
                        return "genre:soul"
 
199
                        return "soul"
194
200
                elif g == "techno":
195
 
                        return "genre:techno"
 
201
                        return "techno"
196
202
                elif g == "classic":
197
 
                        return "genre:classical"                
 
203
                        return "classical"              
198
204
        
199
205
if __name__ == "__main__":
200
206
        session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)