Skip to content

Commit

Permalink
Merge pull request #98 from pepf/master
Browse files Browse the repository at this point in the history
Closes #98
  • Loading branch information
Rayman committed Nov 29, 2014
2 parents ed7af89 + 00940f0 commit 3697449
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ pids
*.pid
*.seed

#osx
*.DS_Store

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
build

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
1 change: 1 addition & 0 deletions client/components/suggestions/suggestions.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h3 class="panel-title">
<li><a href="#">Jazz</a></li>
<li><a href="#">Soul</a></li>
<li><a href="#">Hip Hop</a></li>
<li><a href="#" data-genre="hypemPopular">HypeMachine Popular</a></li>
</ul>
</div>
</h3>
Expand Down
85 changes: 47 additions & 38 deletions client/components/suggestions/suggestions.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
var refreshSuggestions = function() {
Meteor.call('hotRightNow', Session.get("suggestion-genre"), function(error,result) {
//hack to make calls to Hypemachine API when selecting this "genre"
var apiCall = (Session.get("suggestion-genre") === "hypemPopular") ? Session.get("suggestion-genre") : "hotRightNow";
Meteor.call(apiCall, Session.get("suggestion-genre"), function(error,result) {
if(error) { console.log(error); return; }
Session.set("suggestions", result);
});
}
};

Template.suggestions.created = function() {
Session.set("suggestion-genre","alternative rock");
refreshSuggestions();
}

Template.suggestions.songs = function() {
return Session.get('suggestions');
}

Template.suggestions.events = {
'click button#refreshSuggestions' : refreshSuggestions,

'click .suggestion-genres li' : function(e) {
var genre = e.target.text.toLowerCase();
Session.set("suggestion-genre",genre);
console.log(e);
$(".suggestion-genres li").removeClass("active");
$(e.currentTarget).addClass("active");
refreshSuggestions();
},

'click #addSong': function (e,template) {
var playlistId = Router.current().params._id;

//prepare query for Youtube
var options = {
part: 'id',
type: 'video',
videoEmbeddable: 'true',
q: this.artist_name + " " + this.title
}
//perform Youtube search using artist and song information
Meteor.call('youtube_search', options, function(error, data) {
if (error) { return false; }
var addSongfromQuery = function(query, playlistId) {
//prepare query for Youtube
var options = {
part: 'id',
type: 'video',
videoEmbeddable: 'true',
q: query
};
//perform Youtube search using artist and song information
Meteor.call('youtube_search', options, function(error, data) {
if (error) { return false; }

//Id from first search result
var videoId = data.items[0].id.videoId;
Expand All @@ -47,7 +26,7 @@ Template.suggestions.events = {
var options = {
'part': 'snippet,contentDetails,statistics',
'id': videoId,
}
};
Meteor.call('youtube_videos_list', options);

//Put it in current playlist
Expand All @@ -62,6 +41,36 @@ Template.suggestions.events = {
{ $push: { songs: songObject} }
);
});
};


Template.suggestions.created = function() {
Session.set("suggestion-genre","alternative rock");
refreshSuggestions();
};

Template.suggestions.helpers({
"songs" : function() {
return Session.get("suggestions");
}
});

Template.suggestions.events = {
'click button#refreshSuggestions' : refreshSuggestions,

'click .suggestion-genres li' : function(e) {
var genre = (e.target.getAttribute("data-genre") !== null) ? e.target.getAttribute("data-genre") : e.target.text.toLowerCase();
Session.set("suggestion-genre",genre);
console.log(e);
$(".suggestion-genres li").removeClass("active");
$(e.currentTarget).addClass("active");
refreshSuggestions();
},

'click #addSong': function (e,template) {
var playlistId = Router.current().params._id;
addSongfromQuery( this.artist_name + " " + this.title, playlistId);


},
}
};
40 changes: 34 additions & 6 deletions server/echonest.js → server/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var ECHONEST_KEY = 'Z9TLXHBRUB49YXCNR';

Meteor.methods({
getArtistInfo: function(artist) {
var artist = encodeURIComponent(artist);
var url = "http://developer.echonest.com/api/v4/artist/profile?api_key="+ECHONEST_KEY+"&name="+artist+"&bucket=hotttnesss&bucket=terms&bucket=images&bucket=songs"

artist = encodeURIComponent(artist);
var url = "http://developer.echonest.com/api/v4/artist/profile?api_key="+ECHONEST_KEY+"&name="+artist+"&bucket=hotttnesss&bucket=terms&bucket=images&bucket=songs";
var result;
try {
var result = HTTP.get(url);
result = HTTP.get(url);
} catch(e) {
console.log(e.toString());
return false;
Expand All @@ -22,8 +22,9 @@ Meteor.methods({
//default genre
genre = typeof genre !== 'undefined' ? genre : 'alternative rock';
var url = "http://developer.echonest.com/api/v4/playlist/static?api_key="+ECHONEST_KEY+"&type=genre-radio&genre="+genre+"&results=10&bucket=song_hotttnesss";
var result;
try {
var result = HTTP.get(url);
result = HTTP.get(url);
} catch(e) {
console.log(e.toString());
return false;
Expand All @@ -34,8 +35,35 @@ Meteor.methods({
});
return result.data.response.songs;
} else {
//console.log(result.content);
return false;
}
},

//Hypem related methods
//Should return data more or less in the same way as the echnonest does, so these
//two methods can be exchanged
hypemPopular: function() {
var url = "http://hypem.com/playlist/popular/3day/json/1/data.js";
var result;
try {
result = HTTP.get(url);
} catch(e) {
console.log(e.toString());
return false;
}
if (result.data) {
var nrs = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
var songs = nrs.map(function(nr) {
var song = result.data[nr];
return { artist_name:song.artist,
title:song.title
};
});
return songs;
} else {
return false;
}

}

});

0 comments on commit 3697449

Please sign in to comment.