Skip to content

Commit

Permalink
added support for searching by artist only
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkettner committed Mar 27, 2011
1 parent cc0e49a commit 73fabc9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions iresults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require.paths.unshift(require('path').join(__dirname,'./util'));

var Album = require('album').Album;
var Artist = require('artist').Artist;
var Track = require('track').Track;

//Track total and completed instances of the class for debugging purposes.
Expand Down Expand Up @@ -84,6 +85,24 @@ iResults.prototype.getAlbum = function() {
return album;
};


/*
Extracts a few items from the iTunes results for an artist search and returns them in an object.
*/
iResults.prototype.getArtist = function() {
var artist = '';
if (this.data.wrapperType == 'artist') {
var artist = new Artist(this.data.artistLinkUrl,
this.data.amgArtistId,
this.data.artistId,
this.data.artistName);
} else {
}
return artist;
};



/*
Extracts a few items from the iTunes results for an album search and returns them in an object.
*/
Expand Down
20 changes: 20 additions & 0 deletions itunes.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ iTunes.prototype.responseEnd = function(dataType, results, callback) {
error = 1;
} else {
data = results.getAlbum();
console.dir(results);
};
break;
case 'artist':
if (results.hits > 1) {
error = 1;
} else if ( results.hits == 0) {
error = 1;
} else {
data = results.getArtist();
};
break;
case 'track':
Expand Down Expand Up @@ -143,6 +153,16 @@ iTunes.prototype.lookupAlbum = function(params, callback) {
self.request('album',callback);
};

iTunes.prototype.lookupArtist = function(params, callback) {
var self = this;
var artist = params.artist;
self.params.media='music';
self.params.entity='musicArtist';
self.params.attribute='artistTerm';
self.params.term=artist;
self.request('artist',callback);
};

iTunes.prototype.lookupTrack = function(params, callback) {
var self = this;
var artist = params.artist;
Expand Down

0 comments on commit 73fabc9

Please sign in to comment.