Skip to content

Commit 529a06d

Browse files
add support for last.fm
1 parent f96f45a commit 529a06d

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

example.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@
6161
color: #e9e9e9;
6262
}
6363
#lifestream_css_v2 .lifestream-delicious { background-image: url("images/delicious_color.gif"); }
64+
#lifestream_css_v2 .lifestream-github { background-image: url("images/github_text_color.png"); }
6465
#lifestream_css_v2 .lifestream-googlereader { background-image: url("images/googlereader_color.png"); }
66+
#lifestream_css_v2 .lifestream-lastfm { background-image: url("images/lastfm_color.png"); }
6567
#lifestream_css_v2 .lifestream-stackoverflow { background-image: url("images/stackoverflow_color.png"); }
6668
#lifestream_css_v2 .lifestream-twitter { background-image: url("images/twitter_text.png"); }
67-
#lifestream_css_v2 .lifestream-github { background-image: url("images/github_text_color.png"); }
6869
#lifestream_css_v2 .lifestream-youtube { background-image: url("images/youtube_text.png"); }
6970
</style>
7071

@@ -99,6 +100,10 @@ <h2>Lifestream - formatted with CSS</h2>
99100
"service": "github",
100101
"user": "christianv"
101102
},
103+
{
104+
"service": "lastfm",
105+
"user": "denbuzze"
106+
},
102107
{
103108
"service": "stackoverflow",
104109
"user": "117193"

images/lastfm_color.png

689 Bytes
Loading

jquery.lifestream-compiled.js

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.lifestream.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,50 @@
272272

273273
};
274274

275+
$.fn.lifestream.feeds.lastfm = function(obj, callback){
276+
277+
var parseLastfmEntry = function(entry){
278+
var output = "";
279+
280+
output +='loved <a href="'+ entry.url + '">'
281+
+ entry.name + '</a> by <a href="' + entry.artist.url + '">'
282+
+ entry.artist.name + "</a>";
283+
284+
return output;
285+
}
286+
287+
var parseLastfm = function(input){
288+
var output = [];
289+
290+
if(input.query && input.query.count && input.query.count > 0
291+
&& input.query.results.lovedtracks
292+
&& input.query.results.lovedtracks.track){
293+
var list = input.query.results.lovedtracks.track;
294+
for(var i=0, j=list.length; i<j; i++){
295+
var entry = list[i];
296+
output.push({
297+
"date": new Date(parseInt((entry.date.uts * 1000), 10)),
298+
"service": obj.service,
299+
"html": parseLastfmEntry(entry)
300+
});
301+
}
302+
}
303+
return output;
304+
};
305+
306+
$.ajax({
307+
"url": createYqlUrl('select * from xml where url='
308+
+ '"http://ws.audioscrobbler.com/2.0/user/'
309+
+ obj.user + '/lovedtracks.xml"')
310+
}).success(function(data){
311+
if(typeof data === "string"){
312+
data = $.parseJSON(data);
313+
}
314+
callback(parseLastfm(data));
315+
});
316+
317+
};
318+
275319
$.fn.lifestream.feeds.stackoverflow = function(obj, callback){
276320

277321
var parseStackoverflowItem = function(item){

0 commit comments

Comments
 (0)