Flickr.js
Go to the documentation of this file.
1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
3 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
4 
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cr = Components.results;
8 
9 const DESCRIPTION = "mashTape Provider: Flickr Provider";
10 const CID = "{a86cc290-6990-11dd-ad8b-0800200c9a66}";
11 const CONTRACTID = "@songbirdnest.com/mashTape/provider/photo/Flickr;1";
12 
13 // XPCOM constructor for our Flickr mashTape provider
14 function Flickr() {
15  this.wrappedJSObject = this;
16  Components.utils.import("resource://mashtape/mtUtils.jsm");
17 }
18 
19 Flickr.prototype.constructor = Flickr;
20 Flickr.prototype = {
22  classID: Components.ID(CID),
24  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMashTapePhotoProvider,
25  Ci.sbIMashTapeProvider]),
26 
27  providerName: "Flickr",
28  providerType: "photo",
29  providerIcon: "chrome://mashTape/content/tabs/flickr.png",
30  limit: 100,
31  sort: "&sort=relevance",
32  searchType: "&text=",
33  searchURL: "https://api.flickr.com/services/rest/?" +
34  "method=flickr.photos.search&api_key=461354d3cdcc5425055670cbd3b8e16e" +
35  "&extras=owner_name,date_taken,o_dims,original_format",
36 
37  query: function(searchTerms, updateFn) {
38  var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
39  .createInstance(Ci.nsIXMLHttpRequest);
40 
41  var prefBranch = Cc["@mozilla.org/preferences-service;1"]
42  .getService(Ci.nsIPrefService).getBranch("extensions.mashTape.");
43  var keywords = prefBranch.getCharPref("photo.keywords");
44  if (keywords != "")
45  searchTerms += "%20" + escape(keywords);
46 
47  var query = "&per_page=" + this.limit + this.sort + this.searchType +
48  '"' + searchTerms + '"';
49  /*
50  if (this.searchType.substr(1,3) == "tex")
51  query += "%20concert";
52  else
53  query += ",concert";
54  */
55  var url = this.searchURL + query;
56 
57  var songbirdmode = false;
58  if (searchTerms == "Songbird") {
59  songbirdmode = true;
60  // all photos tagged 'mashtape'
61  //url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=33a6c9b21ada1e5b7d85f5cde788e6c7&extras=owner_name,date_taken,o_dims,original_format&user_id=11878025@N03&tags=mashtape";
62  // all photos in the mashTape set
63  url = "https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=33a6c9b21ada1e5b7d85f5cde788e6c7&photoset_id=72157607854460548&extras=owner_name,date_taken,o_dims,original_format";
64  }
65 
66  mtUtils.log("Flickr", "URL:" + url);
67 
68  req.open("GET", url, true);
69  req.provider = this;
70  req.updateFn = updateFn;
71  req.onreadystatechange = function() {
72  if (this.readyState != 4)
73  return;
74  if (this.status == 200) {
75  var x = new XML(this.responseText.replace(
76  '<?xml version="1.0" encoding="utf-8" ?>', ""));
77  var results = new Array();
78  var set;
79  if (songbirdmode)
80  set = x..photoset.photo;
81  else
82  set = x..photos.photo;
83  for each (var entry in set) {
84  var origFormat = entry.@originalformat.toString();
85  //if (origFormat == "")
86  // continue;
87 
88  var width = entry.@o_width.toString();
89  var height = entry.@o_height.toString();
90 
91  var imgUrl = "https://farm" + entry.@farm +
92  ".static.flickr.com/" + entry.@server + "/" +
93  entry.@id + "_" + entry.@secret; // + ".jpg";
94  var url = "https://www.flickr.com/photos/" +
95  entry.@owner + "/" + entry.@id;
96  var timestamp = entry.@datetaken;
97  var year = timestamp.substr(0,4);
98  var mon = timestamp.substr(5,2) - 1;
99  var date = timestamp.substr(8,2);
100  var hour = timestamp.substr(11,2);
101  var min = timestamp.substr(14,2);
102  var sec = timestamp.substr(17,2);
103  timestamp = Date.UTC(year,mon,date,hour,min,sec);
104  var item = {
105  title: entry.@title.toString(),
106  url: url,
107  small: imgUrl + "_m.jpg",
108  medium: imgUrl + ".jpg",
109  large: imgUrl + "_b.jpg",
110  owner: entry.@ownername.toString(),
111  ownerUrl: "https://flickr.com/photos/" +
112  escape(entry.@ownername.toString()),
113  time: timestamp,
114  width: width,
115  height: height,
116  }
117  results.push(item);
118  }
119  mtUtils.log("Flickr", x..photos.photo.length()+" photos found");
120 
121  results.wrappedJSObject = results;
122  this.updateFn.wrappedJSObject.update(CONTRACTID, results);
123  }
124  }
125  req.send(null);
126  },
127 }
128 
129 var components = [Flickr];
130 function NSGetModule(compMgr, fileSpec) {
131  return XPCOMUtils.generateModule([Flickr]);
132 }
133 
134 
classDescription entry
Definition: FeedWriter.js:1427
_setDateDatepicker date
menuItem id
Definition: FeedWriter.js:971
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
const Ci
Definition: Flickr.js:6
populateBox limit
Definition: tuner2.js:877
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function server(port, basePath)
Definition: httpd.js:4758
function width(ele) rect(ele).width
const CONTRACTID
Definition: Flickr.js:11
function NSGetModule(compMgr, fileSpec)
Definition: Flickr.js:130
function Flickr()
Definition: Flickr.js:14
return null
Definition: FeedWriter.js:1143
_updateDatepicker height
BogusChannel prototype owner
function url(spec)
sbDeviceFirmwareAutoCheckForUpdate prototype classID
const Cc
Definition: Flickr.js:5
#define min(a, b)
const DESCRIPTION
Definition: Flickr.js:9
const CID
Definition: Flickr.js:10
const Cr
Definition: Flickr.js:7