Code review comment for lp:~martijn/udstream/gdata

Revision history for this message
Paul Hummer (rockstar) wrote :

Here's the diff for this branch:

=== modified file 'lifestream.html'
--- lifestream.html 2008-12-12 00:16:45 +0000
+++ lifestream.html 2008-12-27 19:16:42 +0000
@@ -14,12 +14,16 @@ td.time, td.source {
   color: #aaa;
   background: white;
 }
-tr.flickr td.data { color: white; background: #0c0; }
-tr.twitter td.data { color: white; background: #933; }
-tr.identica td.data { color: white; background: #339; }
-tr.flickr:hover td { color: white; background: #0d0; }
-tr.twitter:hover td { color: white; background: #a33; }
+tr.flickr td.data { color: white; background: #0c0; }
+tr.twitter td.data { color: white; background: #933; }
+tr.identica td.data { color: white; background: #339; }
+tr.picasa td.data { color: white; background: #8c8; }
+tr.youtube td.data { color: white; background: #c00; }
+tr.flickr:hover td { color: white; background: #0d0; }
+tr.twitter:hover td { color: white; background: #a33; }
 tr.identica:hover td { color: white; background: #33a; }
+tr.picasa:hover td { color: white; background: #8d8; }
+tr.youtube:hover td { color: white; background: #d00; }
 </style>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
 <script>
@@ -136,13 +140,13 @@ Date.prototype.format = function (mask,
  return dateFormat(this, mask, utc);
 };

-
-
 ls = {
   tag_api: [
     ["http://search.twitter.com/search.json?callback=?&q=%23$TAG", "twittersearch"],
     ["http://api.flickr.com/services/feeds/photos_public.gne?tags=$TAG&lang=en-us&format=json&jsoncallback=?", "flickr"],
- ["http://pipes.yahoo.com/pipes/pipe.run?_id=qGysIErH3RGVW2OJBRNMsA&_render=json&tag=$TAG&_callback=?", "identicasearch"]
+ ["http://pipes.yahoo.com/pipes/pipe.run?_id=qGysIErH3RGVW2OJBRNMsA&_render=json&tag=$TAG&_callback=?", "identicasearch"],
+ ["http://gdata.youtube.com/feeds/videos?alt=json-in-script&vq=$TAG&callback=?", "gdata"],
+ ["http://picasaweb.google.com/data/feed/api/all?alt=json-in-script&q=$TAG&callback=?", "gdata"],
   ],
   init: function(tag, element) {
     if (element && element.nodeName.toLowerCase() == "table") {
@@ -158,7 +162,7 @@ ls = {
       }
     }
   },
- addItem: function(td, time, src, link) {
+ addItem: function(td, time, src, link, thumbnail) {
     // time should be in ISO 2008-12-11T02:30:43-08:00 format
     var tr = document.createElement("tr");
     $(tr).click(function(){ location.href = link; });
@@ -168,6 +172,19 @@ ls = {
     timetd.className = "time";
     tr.appendChild(timetd);
     td.className = "data";
+ if(thumbnail) {
+ td.img = document.createElement('img');
+ td.img.src = thumbnail ;
+
+ $(td).hover(function(){
+ this.img.style.position = "absolute";
+ this.img.style.top = (this.offsetTop + this.offsetHeight) + "px";
+ this.img.style.left = this.offsetLeft + "px";
+ document.body.appendChild(this.img);
+ }, function(){
+ document.body.removeChild(this.img);
+ });
+ }
     tr.appendChild(td);
     var srctd = document.createElement("td");
     srctd.appendChild(document.createTextNode(src));
@@ -184,6 +201,7 @@ ls = {
     });
     if (!found) ls.element.appendChild(tr);
   },
+
   twittersearch: function(data) {
     $.each(data.results, function() {
       var td = document.createElement("td");
@@ -205,18 +223,44 @@ ls = {
     $.each(data.items, function() {
       var td = document.createElement("td");
       td.appendChild(document.createTextNode(this.author + " - " + this.title));
- td.img = document.createElement("img");
- td.img.src = this.media.m;
- $(td).hover(function(){
- this.img.style.position = "absolute";
- this.img.style.top = (this.offsetTop + this.offsetHeight) + "px";
- this.img.style.left = this.offsetLeft + "px";
- document.body.appendChild(this.img);
- }, function(){
- document.body.removeChild(this.img);
+
+ ls.addItem(td, this.date_taken, "flickr", this.link, this.media.m);
+ });
+ },
+ gdata: function(data) {
+ $.each(data.feed.entry, function() {
+ var td = document.createElement('td');
+
+ title = this['author'][0]['name']['$t'] + ': ' +
+ this['media$group']['media$title']['$t'];
+ td.appendChild(document.createTextNode(title));
+
+ var links = $.grep(this['link'], function(e) {
+ return (e['type'] == 'text/html' && e['rel'] == 'alternate');
       });
- var time = this.date_taken;
- ls.addItem(td, time, "flickr", this.link);
+ var link = links[0]['href'];
+
+ var nr_thumbnails = this['media$group']['media$thumbnail'].length;
+ var thumbnail = this['media$group']['media$thumbnail'][nr_thumbnails-1]['url'];
+
+ var time = this['published']['$t'];
+
+ var kind = $.grep(this['category'], function(e) {
+ return e['scheme'] == 'http://schemas.google.com/g/2005#kind';
+ });
+ var data_source;
+ switch(kind[0]['term']) {
+ case 'http://gdata.youtube.com/schemas/2007#video':
+ data_source = 'youtube';
+ break;
+ case 'http://schemas.google.com/photos/2007#photo':
+ data_source = 'picasa';
+ break;
+ default:
+ data_source = 'unknown';
+ }
+
+ ls.addItem(td, time, data_source, link, thumbnail);
     });
   },
 };
@@ -224,7 +268,7 @@ ls = {
 ///////////////////////////////////////////////////////
 // Change this tag here to get a lifestream for the tag
 // vvvvvvvvv
-$(document).ready(function(){ls.init("UDSJaunty", $("#t")[0])});
+$(document).ready(function(){ls.init("UDS Jaunty", $("#t")[0])});
 </script>
 </head>
 <body>

« Back to merge proposal