diff --git a/.gitignore b/.gitignore
index 8cc5347..af762e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/.meteor/versions b/.meteor/versions
index 1225541..f84ccea 100644
--- a/.meteor/versions
+++ b/.meteor/versions
@@ -32,14 +32,14 @@ http@1.0.8
ian:accounts-ui-bootstrap-3@1.1.23
id-map@1.0.1
insecure@1.0.1
-iron:controller@1.0.2
-iron:core@1.0.2
-iron:dynamic-template@1.0.2
-iron:layout@1.0.2
-iron:location@1.0.2
-iron:middleware-stack@1.0.2
-iron:router@1.0.2
-iron:url@1.0.2
+iron:controller@1.0.3
+iron:core@1.0.3
+iron:dynamic-template@1.0.3
+iron:layout@1.0.3
+iron:location@1.0.3
+iron:middleware-stack@1.0.3
+iron:router@1.0.3
+iron:url@1.0.3
jquery@1.0.1
json@1.0.1
launch-screen@1.0.0
diff --git a/client/components/suggestions/suggestions.html b/client/components/suggestions/suggestions.html
index fd4e6e6..65fdbdd 100644
--- a/client/components/suggestions/suggestions.html
+++ b/client/components/suggestions/suggestions.html
@@ -20,6 +20,7 @@
Jazz
Soul
Hip Hop
+ HypeMachine Popular
diff --git a/client/components/suggestions/suggestions.js b/client/components/suggestions/suggestions.js
index b462ab8..04df7ba 100644
--- a/client/components/suggestions/suggestions.js
+++ b/client/components/suggestions/suggestions.js
@@ -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;
@@ -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
@@ -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);
+
},
-}
+};
diff --git a/server/echonest.js b/server/apis.js
similarity index 55%
rename from server/echonest.js
rename to server/apis.js
index 3d65d21..cf4425c 100644
--- a/server/echonest.js
+++ b/server/apis.js
@@ -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;
@@ -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;
@@ -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;
+ }
+
}
+
});