Merge lp:~unity-team/unity-lens-video/split-online-results into lp:unity-lens-video/remote-videos-scope-trunk

Proposed by Michal Hruby
Status: Merged
Approved by: Jim Hodapp
Approved revision: 59
Merged at revision: 58
Proposed branch: lp:~unity-team/unity-lens-video/split-online-results
Merge into: lp:unity-lens-video/remote-videos-scope-trunk
Diff against target: 150 lines (+61/-35)
1 file modified
src/unity-scope-video-remote (+61/-35)
To merge this branch: bzr merge lp:~unity-team/unity-lens-video/split-online-results
Reviewer Review Type Date Requested Status
Jim Hodapp (community) code Approve
Review via email: mp+124371@code.launchpad.net

This proposal supersedes a proposal from 2012-09-14.

Commit message

Add 'split' parameter to the query

Description of the change

Update to match latest designs - the scope now adds the 'split' parameter to the query to distinguish "online" and "suggestion" results.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Line 83: Add a comment describing what the "True" is there for. This will be convenient for those reading the code who are not familiar with the scope's source structure.

It is not obvious to me how the online vs. suggestion results differ and why they need to be "split." A comment above line 89 explaining the split and how it gets used would be very helpful.

Otherwise looks great, nice work.

review: Needs Fixing (code)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Since this did operate correctly and only needed comment improvements (and since Michal is on vacation), I'm setting this to be approved.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-scope-video-remote'
2--- src/unity-scope-video-remote 2012-08-30 13:18:47 +0000
3+++ src/unity-scope-video-remote 2012-09-14 10:44:17 +0000
4@@ -52,6 +52,9 @@
5 _ = gettext.gettext
6 n_ = gettext.ngettext
7
8+CAT_INDEX_ONLINE = 1
9+CAT_INDEX_MORE = 2
10+
11 BUS_NAME = "net.launchpad.scope.RemoteVideos"
12 SERVER = "http://videosearch.ubuntu.com/v0"
13
14@@ -199,7 +202,22 @@
15 if search and not working:
16 search.finished()
17
18- def update_results_model(self, search, model, results):
19+ def update_results_model(self, search, model, results, is_treat_yourself=False):
20+ """Run the search method and check if a list of sources is present.
21+ This is useful when coming out of a network issue."""
22+ if isinstance(results, dict):
23+ self.process_result_array(results['other'], model, CAT_INDEX_ONLINE)
24+ self.process_result_array(results['treats'], model, CAT_INDEX_MORE)
25+ else:
26+ category = CAT_INDEX_MORE if is_treat_yourself else CAT_INDEX_ONLINE
27+ self.process_result_array(results, model, category)
28+
29+ if search:
30+ search.finished()
31+ if self.sources_list == []:
32+ self.query_list_of_sources()
33+
34+ def process_result_array(self, results, model, category):
35 """Run the search method and check if a list of sources is present.
36 This is useful when coming out of a network issue."""
37 for i in results:
38@@ -207,33 +225,43 @@
39 uri = i['url'].encode('utf-8')
40 title = i['title'].encode('utf-8')
41 icon = i['img'].encode('utf-8')
42+ result_icon = icon
43 comment = i['source'].encode('utf-8')
44 details_url = ""
45 if "details" in i:
46 details_url = i['details'].encode('utf-8')
47+ if category == CAT_INDEX_MORE:
48+ price = None
49+ price_key = 'formatted_price'
50+ if price_key in i:
51+ price = i[price_key]
52+ if not price or price is 'free':
53+ price = _('Free')
54+ anno_icon = Unity.AnnotatedIcon.new(Gio.FileIcon.new(Gio.File.new_for_uri(result_icon)))
55+ anno_icon.props.category = Unity.CategoryType.MOVIE
56+ anno_icon.props.ribbon = price
57+ result_icon = anno_icon.to_string()
58
59 if uri.startswith('http'):
60 # Instead of an uri, we pass a string of uri + metadata
61- model.append(uri+'lens-meta://'+title+'lens-meta://'+icon+'lens-meta://'+details_url,
62- icon, 2, "text/html", str(title), str(comment), str(uri))
63- except (KeyError, TypeError, AttributeError):
64- print "Malformed result, skipping."
65-
66- model.flush_revision_queue()
67- if search:
68- search.finished()
69- if self.sources_list == []:
70- self.query_list_of_sources()
71+ fake_uri = "%slens-meta://%slens-meta://%slens-meta://%s"
72+ fake_uri = fake_uri % (uri, title, icon, details_url)
73+ model.append(fake_uri,
74+ result_icon, category, "text/html",
75+ str(title), str(comment), str(uri))
76+ except (KeyError, TypeError, AttributeError) as detail:
77+ print "Malformed result, skipping.", detail
78
79 def get_results(self, search_string, search, model, sources):
80 """Query the server with the search string and the list of sources."""
81 if not search_string and not sources and self.recommendations:
82- self.update_results_model(search, model, self.recommendations)
83+ self.update_results_model(search, model, self.recommendations, True)
84 return
85 if self._pending is not None:
86 self.session.cancel_message(self._pending,
87 Soup.KnownStatusCode.CANCELLED)
88 query = dict(q=search_string)
89+ query['split'] = 'true'
90 if sources:
91 query['sources'] = sources.encode("utf-8")
92 query = urlencode(query)
93@@ -263,7 +291,7 @@
94 results = json.loads(msg.response_body.data)
95 except ValueError:
96 print "Error: got garbage json from the server"
97- if isinstance(results, dict):
98+ if isinstance(results, dict) and 'results' in results:
99 results = results.get('results', [])
100 return results
101
102@@ -335,29 +363,27 @@
103 preview.set_rating(-1, 0)
104
105 # TODO: For details of future source types, factor out common detail key/value pairs
106- if source == "Amazon":
107- if "directors" in details:
108- directors = details["directors"]
109- preview.add_info(Unity.InfoHint.new("directors",
110- n_("Director", "Directors", len(directors)), None, ', '.join(directors)))
111- if "starring" in details:
112- cast = details["starring"]
113- if cast:
114- preview.add_info(Unity.InfoHint.new("cast",
115- n_("Cast", "Cast", len(cast)), None, ', '.join(cast)))
116- if "genres" in details:
117- genres = details["genres"]
118- if genres:
119- preview.add_info(Unity.InfoHint.new("genres",
120- n_("Genre", "Genres", len(genres)), None, ', '.join(genres)))
121+ if "directors" in details:
122+ directors = details["directors"]
123+ preview.add_info(Unity.InfoHint.new("directors",
124+ n_("Director", "Directors", len(directors)), None, ', '.join(directors)))
125+ if "starring" in details:
126+ cast = details["starring"]
127+ if cast:
128+ preview.add_info(Unity.InfoHint.new("cast",
129+ n_("Cast", "Cast", len(cast)), None, ', '.join(cast)))
130+ if "genres" in details:
131+ genres = details["genres"]
132+ if genres:
133+ preview.add_info(Unity.InfoHint.new("genres",
134+ n_("Genre", "Genres", len(genres)), None, ', '.join(genres)))
135 # TODO: Add Vimeo & YouTube details for v1 of JSON API
136- else:
137- if "uploaded_by" in details:
138- preview.add_info(Unity.InfoHint.new("uploaded-by", _("Uploaded by"),
139- None, details["uploaded_by"]))
140- if "date_uploaded" in details:
141- preview.add_info(Unity.InfoHint.new("uploaded-on", _("Uploaded on"),
142- None, details["date_uploaded"]))
143+ if "uploaded_by" in details:
144+ preview.add_info(Unity.InfoHint.new("uploaded-by", _("Uploaded by"),
145+ None, details["uploaded_by"]))
146+ if "date_uploaded" in details:
147+ preview.add_info(Unity.InfoHint.new("uploaded-on", _("Uploaded on"),
148+ None, details["date_uploaded"]))
149
150 return preview
151

Subscribers

People subscribed via source and target branches

to all changes: