Merge lp:~submarine/ubuntu-scopes/soundcloud-previews into lp:~submarine/ubuntu-scopes/soundcloud

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 27
Merged at revision: 24
Proposed branch: lp:~submarine/ubuntu-scopes/soundcloud-previews
Merge into: lp:~submarine/ubuntu-scopes/soundcloud
Diff against target: 68 lines (+28/-14)
1 file modified
src/unity_soundcloud_daemon.py (+28/-14)
To merge this branch: bzr merge lp:~submarine/ubuntu-scopes/soundcloud-previews
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+155727@code.launchpad.net

Commit message

Initial previews (with music streaming).

Description of the change

- Initial previews (with music streaming).
- Sort results by "hotness"

To post a comment you must log in.
25. By David Callé

Order results by "hotness"

26. By David Callé

Limit to 30 results

27. By David Callé

"Artist" in previews, instead of "By Artist"

Revision history for this message
Michal Hruby (mhr3) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_soundcloud_daemon.py'
2--- src/unity_soundcloud_daemon.py 2013-03-14 12:29:11 +0000
3+++ src/unity_soundcloud_daemon.py 2013-03-28 16:12:20 +0000
4@@ -89,7 +89,7 @@
5 if not search:
6 return results
7 search = urllib.parse.quote(search)
8- uri = "%stracks.json?consumer_key=%s&q=%s" % (SEARCH_URI, API_KEY, search)
9+ uri = "%stracks.json?consumer_key=%s&q=%s&order=hotness&limit=30" % (SEARCH_URI, API_KEY, search)
10 print(uri)
11 data = []
12 try:
13@@ -160,22 +160,30 @@
14 i['comment'] = ''
15 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
16 i['dnd_uri'] = i['uri']
17- i['metadata'] = {}
18- if EXTRA_METADATA:
19- for e in i:
20- for m in EXTRA_METADATA:
21- if m['id'] == e:
22- i['metadata'][e] = i[e]
23- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
24- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
25- i['category'], i['result_type'],
26- str(i['mimetype']), str(i['title']),
27- str(i['comment']), str(i['dnd_uri']),
28- i['metadata'])
29- result_set.add_result(result)
30+ result_set.add_result(**i)
31 except Exception as error:
32 print (error)
33
34+class Preview (Unity.ResultPreviewer):
35+
36+ def do_run(self):
37+ title = self.result.title.strip()
38+ stream = self.result.metadata['stream'].get_string()
39+ duration = int(self.result.metadata['duration'].get_string())
40+ author = self.result.metadata['artist'].get_string()
41+ description = self.result.comment.strip()
42+ image = self.result.icon_hint.replace('large.jpg', 'original.jpg')
43+ preview = Unity.MusicPreview.new(title, description, None)
44+ if stream != '':
45+ t = Unity.TrackMetadata.full(stream, 1, title, author, '', duration / 1000)
46+ preview.add_track(t)
47+ preview.props.subtitle = author
48+ preview.props.image_source_uri = image
49+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
50+ view_action = Unity.PreviewAction.new("view", _("SoundCloud"), icon)
51+ preview.add_action(view_action)
52+ return preview
53+
54 class Scope (Unity.AbstractScope):
55 def __init__(self):
56 Unity.AbstractScope.__init__(self)
57@@ -227,5 +235,11 @@
58 se = MySearch (search_context)
59 return se
60
61+ def do_create_previewer(self, result, metadata):
62+ rp = Preview()
63+ rp.set_scope_result(result)
64+ rp.set_search_metadata(metadata)
65+ return rp
66+
67 def load_scope():
68 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: