Merge lp:~saviq/unity-lens-video/remote-videos-scope-plurals into lp:~jhodapp/unity-lens-video/remote-videos-scope-trunk

Proposed by Michał Sawicz
Status: Merged
Approved by: Jim Hodapp
Approved revision: 65
Merged at revision: 59
Proposed branch: lp:~saviq/unity-lens-video/remote-videos-scope-plurals
Merge into: lp:~jhodapp/unity-lens-video/remote-videos-scope-trunk
Diff against target: 112 lines (+24/-35)
1 file modified
src/unity-scope-video-remote (+24/-35)
To merge this branch: bzr merge lp:~saviq/unity-lens-video/remote-videos-scope-plurals
Reviewer Review Type Date Requested Status
Jim Hodapp code Approve
Review via email: mp+121609@code.launchpad.net
To post a comment you must log in.
59. By Michał Sawicz

Use ngettext and str.join in details retrieval

Use ngettext in multivalued details for plural handling
Use str.join to join multivalued details

60. By Michał Sawicz

Don't differentiate between sources

Display all data in the preview, if available, regardless of the source.

61. By Michał Sawicz

Don't use list.get when unnecessary

62. By Michał Sawicz

Only import datetime from datetime

63. By Michał Sawicz

Another dict.get vs dict[]

64. By Michał Sawicz

And another one

Revision history for this message
Jim Hodapp (jhodapp) wrote :

This looks good, but revision 60 needs to be undone since we do need to differentiate between sources given that not every video preview looks the same according to the design mockups.

review: Needs Fixing (code)
65. By Michał Sawicz

Revert r60

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity-scope-video-remote'
--- src/unity-scope-video-remote 2012-08-27 15:56:53 +0000
+++ src/unity-scope-video-remote 2012-08-28 14:58:23 +0000
@@ -22,7 +22,7 @@
22import sys22import sys
23from urllib import urlencode23from urllib import urlencode
24import time24import time
25import datetime25from datetime import datetime
26import gettext26import gettext
2727
28#pylint: disable=E061128#pylint: disable=E0611
@@ -50,6 +50,7 @@
50gettext.bindtextdomain(APP_NAME, LOCAL_PATH)50gettext.bindtextdomain(APP_NAME, LOCAL_PATH)
51gettext.textdomain(APP_NAME)51gettext.textdomain(APP_NAME)
52_ = gettext.gettext52_ = gettext.gettext
53n_ = gettext.ngettext
5354
54BUS_NAME = "net.launchpad.scope.RemoteVideos"55BUS_NAME = "net.launchpad.scope.RemoteVideos"
55#SERVER = "http://videosearch.ubuntu.com/v0"56#SERVER = "http://videosearch.ubuntu.com/v0"
@@ -294,11 +295,11 @@
294 desc = ''295 desc = ''
295 source = ''296 source = ''
296 if isinstance(details, dict):297 if isinstance(details, dict):
297 uri = details.get('browser_url', '')298 uri = details['browser_url']
298 title = details.get('title', '')299 title = details['title']
299 thumbnail_uri = details.get('image', '')300 thumbnail_uri = details['image']
300 desc = details.get('description', '')301 desc = details['description']
301 source = details.get('source', '')302 source = details['source']
302303
303 try:304 try:
304 thumbnail_file = Gio.File.new_for_uri (thumbnail_uri)305 thumbnail_file = Gio.File.new_for_uri (thumbnail_uri)
@@ -312,38 +313,38 @@
312313
313 # TODO: For details of future source types, factor out common detail key/value pairs314 # TODO: For details of future source types, factor out common detail key/value pairs
314 if source == "Amazon":315 if source == "Amazon":
315 directors = self.get_list_values("directors", details)316 if "directors" in details:
316 if len(directors) > 0:317 directors = details["directors"]
317 preview.add_info(Unity.InfoHint.new("directors", _("Directors"),318 preview.add_info(Unity.InfoHint.new("directors",
318 None, directors))319 n_("Director", "Directors", len(directors)), None, ', '.join(directors)))
319 if "starring" in details:320 if "starring" in details:
320 cast = self.get_list_values("starring", details)321 cast = details["starring"]
321 if len(cast) > 0:322 if cast:
322 preview.add_info(Unity.InfoHint.new("cast", _("Cast"),323 preview.add_info(Unity.InfoHint.new("cast",
323 None, cast))324 n_("Cast", "Cast", len(cast)), None, ', '.join(cast)))
324 if "genres" in details:325 if "genres" in details:
325 genres = self.get_list_values("genres", details)326 genres = details["genres"]
326 if len(genres) > 0:327 if genres:
327 preview.add_info(Unity.InfoHint.new("genres", _("Genres"),328 preview.add_info(Unity.InfoHint.new("genres",
328 None, genres))329 n_("Genre", "Genres", len(genres)), None, ', '.join(genres)))
329 if "release_date" in details:330 if "release_date" in details:
330 try:331 try:
331 # v1 spec states release_date will be YYYY-MM-DD332 # v1 spec states release_date will be YYYY-MM-DD
332 release_date = datetime.datetime.strptime(details.get("release_date", ""), "%Y-%m-%d")333 release_date = datetime.strptime(details["release_date"], "%Y-%m-%d")
333 preview.year = release_date.strftime("%Y")334 preview.year = release_date.strftime("%Y")
334 except:335 except:
335 print "Failed to parse release_date since it was not in format: YYYY-MM-DD"336 print "Failed to parse release_date since it was not in format: YYYY-MM-DD"
336 if "duration" in details:337 if "duration" in details:
337 duration = int(details.get("duration")) / 60338 duration = int(details["duration"]) / 60
338 # TODO: Extend VideoPreview class and set property for showing video length339 # TODO: Extend VideoPreview class and set property for showing video length
339 # TODO: Add Vimeo & YouTube details for v1 of JSON API340 # TODO: Add Vimeo & YouTube details for v1 of JSON API
340 else:341 else:
341 if "uploaded_by" in details:342 if "uploaded_by" in details:
342 preview.add_info(Unity.InfoHint.new("uploaded-by", _("Uploaded by"),343 preview.add_info(Unity.InfoHint.new("uploaded-by", _("Uploaded by"),
343 None, details.get("uploaded_by", "")))344 None, details["uploaded_by"]))
344 if "date_uploaded" in details:345 if "date_uploaded" in details:
345 preview.add_info(Unity.InfoHint.new("uploaded-on", _("Uploaded on"),346 preview.add_info(Unity.InfoHint.new("uploaded-on", _("Uploaded on"),
346 None, details.get("date_uploaded", "")))347 None, details["date_uploaded"]))
347348
348 return preview349 return preview
349350
@@ -368,18 +369,6 @@
368369
369 return details370 return details
370371
371 def get_list_values(self, key, details):
372 """Given a JSON list (i.e. "starring": ["Robert Downey Jr.", "Terrence Howard"])
373 extract the values and put them into a comma separated string."""
374 values = ""
375 if key in details:
376 for value in details.get(key, ""):
377 values += str(value) + ", "
378 # Remove the final ", "
379 values = values[0:len(values)-2]
380
381 return values
382
383 def play_video (self, action, uri):372 def play_video (self, action, uri):
384 """Preview request - Play action handler"""373 """Preview request - Play action handler"""
385 return self.on_activate_uri (action, uri)374 return self.on_activate_uri (action, uri)

Subscribers

People subscribed via source and target branches

to all changes: