PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/share/spice/canistreamit/spice.js

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 67 lines | 49 code | 12 blank | 6 comment | 5 complexity | eb33d0341a0fcaad9d915fcdb0b1950f MD5 | raw file
Possible License(s): Apache-2.0
  1. function ddg_spice_canistreamit(movies) {
  2. // console.log(xk);
  3. var result,img,snippet,link,div;
  4. var items = new Array();
  5. for(var i = 0; i<movies.length; i++)
  6. {
  7. result = movies[i];
  8. // Make title for header
  9. var header = 'Watch ' + result.title + " ("+result.year+")";
  10. var item = new Array();
  11. var content = "<div><i>Starring:</i> "+result.actors+".</div>";
  12. var streamingStr = "";
  13. var rentalStr = "";
  14. var streamingCount = 0;
  15. var rentalCount = 0;
  16. for(var subtype in result.affiliates)
  17. {
  18. var service = result.affiliates[subtype];
  19. var price = parseFloat(service.price);
  20. if(price > 0)
  21. {
  22. rentalStr += service.friendlyName.replace("Rental","");
  23. rentalStr += "($"+service.price+")";
  24. rentalStr += ", ";
  25. rentalCount++;
  26. }
  27. else
  28. {
  29. streamingStr += service.friendlyName;
  30. streamingStr += ", ";
  31. streamingCount++;
  32. }
  33. }
  34. if(streamingCount > 0)
  35. {
  36. content += "<div><i>Streaming on</i> "+streamingStr.substring(0,streamingStr.length-2)+".</div>";
  37. }
  38. if(rentalCount > 0)
  39. {
  40. content += "<div><i>Rent from </i> "+rentalStr.substring(0,rentalStr.length-2)+".</div>";
  41. }
  42. item['a'] = content;
  43. item['h'] = header;
  44. // Source name and url for the More at X link.
  45. item['s'] = 'CanIStream.It';
  46. item['u'] = result.links.shortUrl;
  47. // Force no compression.
  48. item['f'] = 1;
  49. // Thumbnail url
  50. item['i'] = result.image;
  51. items.push(item);
  52. }
  53. // The rendering function is nra.
  54. nra(items);
  55. }