Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for search by artist #1

Merged
merged 2 commits into from
Mar 28, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the Artist class definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed.

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