Merge lp:~motoster/onehundredscopes/grooveshark-precise-double_queries into lp:~davidc3/onehundredscopes/grooveshark-precise

Proposed by Welton Rodrigo Torres Nascimento on 2012-10-26
Status: Merged
Approved by: David Callé on 2012-10-26
Approved revision: 18
Merged at revision: 18
Proposed branch: lp:~motoster/onehundredscopes/grooveshark-precise-double_queries
Merge into: lp:~davidc3/onehundredscopes/grooveshark-precise
Diff against target: 139 lines (+42/-68)
1 file modified
src/unity-scope-grooveshark (+42/-68)
To merge this branch: bzr merge lp:~motoster/onehundredscopes/grooveshark-precise-double_queries
Reviewer Review Type Date Requested Status
David Callé 2012-10-26 Approve on 2012-10-26
Review via email: mp+131513@code.launchpad.net

Commit message

Get both track and album results from one API call.

Description of the change

This change get track and album information from only one API call.

To post a comment you must log in.
David Callé (davidc3) wrote :

That looks good, thanks!

Please mark with an Approve Review.

David Callé (davidc3) wrote :

Approving.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-scope-grooveshark'
2--- src/unity-scope-grooveshark 2012-01-30 12:24:47 +0000
3+++ src/unity-scope-grooveshark 2012-10-26 04:52:19 +0000
4@@ -48,20 +48,28 @@
5 search.finished()
6
7 def update_results_model(self, search, model):
8- album_list = []
9- for i in self.grooveshark(search):
10- title = i[0]
11- comment = i[1]
12- uri = i[2]
13- icon_hint = i[3]
14- model.append (uri, icon_hint, 0,"text/html", title, comment, uri)
15-
16- for i in self.grooveshark_album(search):
17- title = i[0]
18- comment = i[1]
19- uri = i[2]
20- icon_hint = i[3]
21- model.append (uri, icon_hint, 1,"text/html", title, comment, uri)
22+ data_list = self.grooveshark(search)
23+ if data_list:
24+ for i in data_list:
25+ model.append (
26+ str(i['uri']),
27+ str(i['icon_hint']),
28+ 0,
29+ "text/html",
30+ i['title'],
31+ i['artistName'] + "\n" + i['album'], #comment
32+ i['uri'])
33+
34+ #Show this title's album on the album section
35+ if 'album_uri' in i:
36+ model.append (
37+ i['album_uri'],
38+ i['icon_hint'],
39+ 1,
40+ "text/html",
41+ i['album'],
42+ i['artistName'] + i['album'], #comment
43+ i['album_uri'])
44
45 def grooveshark_search(self, q, key):
46 import urllib, urllib2, simplejson
47@@ -89,26 +97,31 @@
48 return
49
50 def grooveshark(self, search):
51+ import urllib
52 if search:
53 data_grooveshark = self.grooveshark_search("%s" % search, 1)
54 data_list = []
55+ albums_seen = {}
56+
57 if data_grooveshark:
58 for i in data_grooveshark:
59- item_list = []
60-
61- uri = str(i['Url'])
62- title = i['SongName']
63- comment = i['ArtistName']+'\n'+i['AlbumName']
64- icon_hint = 'http://beta.grooveshark.com/static/amazonart/m'+ str(i['AlbumID']) +'.jpg'
65- albumID = i['AlbumID']
66- album = i['AlbumName']
67-
68- item_list.append(title)
69- item_list.append(comment)
70- item_list.append(uri)
71- item_list.append(icon_hint)
72- item_list.append(album)
73- item_list.append(albumID)
74+ item_list = {}
75+
76+ item_list['uri'] = str(i['Url'])
77+ item_list['title'] = i['SongName']
78+ item_list['artistName'] = i['ArtistName']
79+ item_list['comment'] = i['ArtistName']+'\n'+i['AlbumName']
80+ item_list['icon_hint'] = 'http://beta.grooveshark.com/static/amazonart/m'+ str(i['AlbumID']) +'.jpg'
81+ item_list['albumID'] = i['AlbumID']
82+ item_list['album'] = i['AlbumName']
83+
84+ if i['AlbumID'] not in albums_seen:
85+ album_for_uri = urllib.quote(item_list['album'].encode('utf-8'))
86+ print album_for_uri
87+ item_list['album_uri'] = "http://grooveshark.com/#/album/"+ album_for_uri +"/"+ str(item_list['albumID'])
88+ albums_seen[ item_list['albumID'] ] = 1
89+
90+
91 data_list.append(item_list)
92 return data_list
93 else:
94@@ -116,45 +129,6 @@
95 else:
96 return []
97
98- def grooveshark_album(self, search):
99- if search:
100- data_grooveshark = self.grooveshark_search("%s" % search, 2)
101- data_list = []
102- album_list = []
103- if data_grooveshark:
104- for i in data_grooveshark:
105- item_list = []
106-
107- title = i['AlbumName']
108- icon_hint = 'http://beta.grooveshark.com/static/amazonart/m'+ str(i['AlbumID']) +'.jpg'
109- comment = i['ArtistName']
110- albumID = i['AlbumID']
111- import urllib
112- album_for_uri = urllib.quote(title.encode('utf-8'))
113- uri = "http://grooveshark.com/#/album/"+ album_for_uri +"/"+ str(albumID)
114-
115- item_list.append(title)
116- item_list.append(comment)
117- item_list.append(uri)
118- item_list.append(icon_hint)
119- data_list.append(item_list)
120- album_list.append(comment+title)
121-
122- album_dedup_list = []
123- dedup_list = []
124- item = 0
125- for i in data_list:
126- if album_list[item] not in album_dedup_list:
127- album_dedup_list.append(album_list[item])
128- dedup_list.append(i)
129- item = item + 1
130- return dedup_list
131- else:
132- return []
133- else:
134- return []
135-
136-
137
138 if __name__ == "__main__":
139 session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)

Subscribers

People subscribed via source and target branches