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

Proposed by Welton Rodrigo Torres Nascimento
Status: Merged
Merge reported by: David Callé
Merged at revision: not available
Proposed branch: lp:~motoster/onehundredscopes/grooveshark-precise-simple_preview
Merge into: lp:~davidc3/onehundredscopes/grooveshark-precise
Diff against target: 153 lines (+84/-26)
1 file modified
src/unity-scope-grooveshark (+84/-26)
To merge this branch: bzr merge lp:~motoster/onehundredscopes/grooveshark-precise-simple_preview
Reviewer Review Type Date Requested Status
David Callé Pending
Review via email: mp+132007@code.launchpad.net

Commit message

A simple preview implementation

Description of the change

This branch implements a simple preview for unity-scope-grooveshark.

The way grooveshark API works makes impossible to recover item details from SongID or AlbumID. That forced me to use a form of data storage.

The first parameter of model.append was used to store the entire item in a serialized form.

This is probably not the best approach. The best alternative may be apply for Grooveshark Public API access.

A good preview would show all tracks from an album, even if user previewed a track.

Feel free to refuse this merge if you don't agree with anything.

To post a comment you must log in.
Revision history for this message
Welton Rodrigo Torres Nascimento (motoster) wrote :

Hello,

I would like to continue working in this Grooveshark scope. Could you give me some hint or advice on what kind of preview it should have?

It would be possible to build a much better preview having access to the public API Grooveshark.

You ever requested such access?

Revision history for this message
David Callé (davidc3) wrote :

Hello!

I didn't had the time this week to review and eventually merge your
proposals (because I'm in Copenhagen for the UDS), so I'm probably going to
do that on monday.
I've requested access to the Grooveshark API, and it wasn't granted, a year
ago and 6 months ago, but I think I will try again next week. About
previews, I don't remember exactly but I think that the Grooveshark API
could provide actual song previews; the idea would be to get as close as
the current local music previews, as a first step, then maybe work on a
better design. I also know that the Unity Design team wants it to be
installed by default, so music previews will have to be quite consistent
between scopes.

Nevertheless, there is a new policy that won't allow Python scopes/lenses
installed by default (for obvious ram reasons, since Ubuntu wants to target
the mobile/tablet market), so it will be ported to Vala, or (hopefully) Go,
this cycle. But that's another story, and it still needs input from the
Ubuntu Desktop team...

On more thing on the Grooveshark API, if we get access, we will be able to
provide an Online Accounts plugin, to integrate Grooveshark favorites,
uploaded songs from the user account, etc. Which is quite exciting.

Thanks *a lot* for collaborating on this!

On Fri, Nov 2, 2012 at 4:19 PM, Welton Rodrigo Torres Nascimento <
<email address hidden>> wrote:

> Hello,
>
> I would like to continue working in this Grooveshark scope. Could you give
> me some hint or advice on what kind of preview it should have?
>
> It would be possible to build a much better preview having access to the
> public API Grooveshark.
>
> You ever requested such access?
>
> --
>
> https://code.launchpad.net/~motoster/onehundredscopes/grooveshark-precise-simple_preview/+merge/132007
> You are requested to review the proposed merge of
> lp:~motoster/onehundredscopes/grooveshark-precise-simple_preview into
> lp:~davidc3/onehundredscopes/grooveshark-precise.
>

Revision history for this message
David Callé (davidc3) wrote :

Oh, I've answered by mail and it wasn't supposed to land directly on this page but to be a personnal mail. Oh, well.

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-10-29 06:42:03 +0000
3+++ src/unity-scope-grooveshark 2012-10-30 03:42:18 +0000
4@@ -31,6 +31,8 @@
5 self.scope.search_in_global = False
6 self.scope.connect ("search-changed", self.on_search_changed)
7 self.scope.connect ("filters-changed", lambda scope : self.scope.queue_search_changed(Unity.SearchType.DEFAULT))
8+ self.scope.connect ("activate_uri", self.on_activate)
9+ self.scope.connect ("preview_uri", self.on_preview)
10 # self.preferences = Unity.PreferencesManager.get_default()
11 # self.preferences.connect("notify::remote-content-search", self._on_preference_changed)
12 self.scope.export()
13@@ -54,28 +56,26 @@
14 search.finished()
15
16 def update_results_model(self, search, model):
17+ import simplejson
18+
19 data_list = self.grooveshark(search)
20 if data_list:
21 for i in data_list:
22+ serialized = simplejson.dumps(i)
23+
24+ if i['type'] == 'track':
25+ category = 0
26+ else: # album
27+ category = 1
28+
29 model.append (
30- str(i['uri']),
31- str(i['icon_hint']),
32- 0,
33- "text/html",
34- i['title'],
35- i['artistName'] + "\n" + i['album'], #comment
36- i['uri'])
37-
38- #Show this title's album on the album section
39- if 'album_uri' in i:
40- model.append (
41- i['album_uri'],
42- i['icon_hint'],
43- 1,
44- "text/html",
45- i['album'],
46- i['artistName'] + i['album'], #comment
47- i['album_uri'])
48+ serialized,
49+ str(i['icon_hint']),
50+ category,
51+ "text/html",
52+ i['title'],
53+ i['artistName'] + "\n" + i['album'], #comment
54+ i['uri'])
55
56 def grooveshark_search(self, q, key):
57 import urllib, urllib2, simplejson
58@@ -113,22 +113,39 @@
59 for i in data_grooveshark:
60 item_list = {}
61
62+ item_list['type'] = 'track'
63 item_list['uri'] = str(i['Url'])
64 item_list['title'] = i['SongName']
65 item_list['artistName'] = i['ArtistName']
66- item_list['comment'] = i['ArtistName']+'\n'+i['AlbumName']
67+ item_list['comment'] = i['ArtistName']+"\n"+i['AlbumName']
68 item_list['icon_hint'] = 'http://beta.grooveshark.com/static/amazonart/m'+ str(i['AlbumID']) +'.jpg'
69 item_list['albumID'] = i['AlbumID']
70 item_list['album'] = i['AlbumName']
71
72+ # URI for complete album
73+ uri = urllib.quote(item_list['album'].encode('utf-8'))
74+ item_list['album_uri'] = "http://grooveshark.com/#/album/%s/%s" % (uri, item_list['albumID'])
75+
76+ # Append to the list.
77+ data_list.append(item_list)
78+
79+ # Create an entry on list for album too, but only first time we see it.
80 if i['AlbumID'] not in albums_seen:
81- album_for_uri = urllib.quote(item_list['album'].encode('utf-8'))
82- print album_for_uri
83- item_list['album_uri'] = "http://grooveshark.com/#/album/"+ album_for_uri +"/"+ str(item_list['albumID'])
84- albums_seen[ item_list['albumID'] ] = 1
85-
86-
87- data_list.append(item_list)
88+
89+ # Clone the item
90+ album_item_list = item_list.copy()
91+
92+ # Adjust fields
93+ album_item_list['type'] = 'album'
94+ album_item_list['title'] = album_item_list['album']
95+ album_item_list['uri'] = album_item_list['album_uri']
96+
97+ # Mark as seen
98+ albums_seen[ album_item_list['albumID'] ] = 1
99+
100+ # Append an entry for this album.
101+ data_list.append(album_item_list)
102+
103 return data_list
104 else:
105 return []
106@@ -136,6 +153,47 @@
107 return []
108
109
110+ def _deserialize(self, stream):
111+ import urllib2, simplejson
112+
113+ # De-serialize the item.
114+ return simplejson.loads(stream)
115+
116+ def on_activate(self, scope, stream):
117+ item = self._deserialize(stream)
118+ print "Stream is %s" % stream
119+
120+ uri = ''
121+ if item['type'] == 'track':
122+ uri = item['uri']
123+ else:
124+ uri = item['album_uri']
125+
126+ print "Type is %s" % item['type']
127+ print "URI is %s" % uri
128+
129+ Gio.AppInfo.launch_default_for_uri(uri, None)
130+
131+ return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH)
132+
133+ def on_preview(self, scope, stream):
134+ item = self._deserialize(stream)
135+ preview = Unity.MusicPreview.new(
136+ item['title'], item['artistName'],
137+ Gio.FileIcon.new_for_string(item['icon_hint']))
138+
139+ play_action = Unity.PreviewAction.new("play_action", "Play on Grooveshark", None)
140+ play_action.connect("activated", self.play_action)
141+ preview.add_action(play_action)
142+
143+ return preview
144+
145+ def play_action(self, scope, stream):
146+ print "Clicked URI is %s" % self._deserialize(stream)['uri']
147+ return self.on_activate(scope, stream)
148+
149+
150+
151 if __name__ == "__main__":
152 session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
153 session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,

Subscribers

People subscribed via source and target branches