Add suppport for tracks, basic design, minor refactor
This commit is contained in:
parent
e20b3b86c4
commit
acb129899d
13 changed files with 267 additions and 77 deletions
|
@ -14,33 +14,47 @@ module.exports.lookupId = function(id, type, next) {
|
|||
if (type == "album") {
|
||||
pm.getAlbum(id, true, function(album) {
|
||||
next({
|
||||
service: "googleplaymusic",
|
||||
type: "album",
|
||||
id: album.albumId,
|
||||
name: album.name,
|
||||
url: "https://play.google.com/music/listen#/album/" + album.albumId,
|
||||
artwork: album.albumArtRef.replace("http:", ""),
|
||||
artist: {
|
||||
name: album.artist
|
||||
},
|
||||
type: type
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (type == "track") {
|
||||
pm.getAllAccessTrack(id, function(track) {
|
||||
next({
|
||||
service: "googleplaymusic",
|
||||
type: "track",
|
||||
id: track.nid,
|
||||
name: track.title,
|
||||
url: "https://play.google.com/music/listen#/track/" + track.nid + "/" + track.albumId,
|
||||
artwork: track.albumArtRef[0].url.replace("http:", ""),
|
||||
album: {
|
||||
name: track.album
|
||||
},
|
||||
artist: {
|
||||
name: track.artist
|
||||
},
|
||||
type: type
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.search = function(query, type, next) {
|
||||
module.exports.search = function(data, next) {
|
||||
var query = "";
|
||||
var type = data.type;
|
||||
|
||||
if (type == "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
} else if (type == "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
}
|
||||
|
||||
pm.search(query, 5, function(data) { // max 5 results
|
||||
var result = data.entries.filter(function(result) {
|
||||
return result[type];
|
||||
|
@ -49,9 +63,9 @@ module.exports.search = function(query, type, next) {
|
|||
}).shift();
|
||||
|
||||
var id;
|
||||
if (result.album) {
|
||||
if (type == "album") {
|
||||
id = result.album.albumId;
|
||||
} else if (result.track) {
|
||||
} else if (type == "track") {
|
||||
id = result.track.nid;
|
||||
}
|
||||
|
||||
|
@ -73,9 +87,7 @@ module.exports.parseUrl = function(url, next) {
|
|||
if (id.length > 0) {
|
||||
return next({id: id, type: type});
|
||||
} else {
|
||||
module.exports.search(artist + " " + album, "album", function(googleAlbum) {
|
||||
next(googleAlbum);
|
||||
});
|
||||
module.exports.search({type: type, name:album, artist: {name: artist}}, next);
|
||||
}
|
||||
} else if(path) {
|
||||
var matches = path.match(/\/music\/m\/([\w]+)/);
|
||||
|
|
32
lib/rdio.js
32
lib/rdio.js
|
@ -21,14 +21,15 @@ module.exports.lookupId = function(id, next) {
|
|||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||
var type = result.album ? "track" : "album";
|
||||
next({
|
||||
service: "rdio",
|
||||
type: type,
|
||||
id: id,
|
||||
name: result.name,
|
||||
url: result.shortUrl,
|
||||
artwork: result.icon.replace("http:", ""),
|
||||
artwork: result.icon.replace("http:", "").replace("square-200", "square-500"),
|
||||
artist: {
|
||||
name: result.artist
|
||||
},
|
||||
type: type
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -58,19 +59,29 @@ module.exports.lookupUrl = function(url, next) {
|
|||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||
var type = result.album ? "track" : "album";
|
||||
next({
|
||||
service: "rdio",
|
||||
type: type,
|
||||
id: id,
|
||||
name: result.name,
|
||||
url: result.shortUrl,
|
||||
artwork: result.icon.replace("http:", ""),
|
||||
artwork: result.icon.replace("http:", "").replace("square-200", "square-500"),
|
||||
artist: {
|
||||
name: result.artist
|
||||
},
|
||||
type: type
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.search = function(query, type, next) {
|
||||
module.exports.search = function(data, next) {
|
||||
var query;
|
||||
var type = data.type;
|
||||
|
||||
if (type == "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
} else if (type == "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
}
|
||||
console.log(query)
|
||||
rdio.api("", "", {
|
||||
query: query,
|
||||
method: 'search',
|
||||
|
@ -83,14 +94,15 @@ module.exports.search = function(query, type, next) {
|
|||
var parsed = parse(result.shortUrl)
|
||||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||
next({
|
||||
service: "rdio",
|
||||
type: type,
|
||||
id: id,
|
||||
name: result.name,
|
||||
url: result.shortUrl,
|
||||
artwork: result.icon.replace("http:", ""),
|
||||
artwork: result.icon.replace("http:", "").replace("square-200", "square-500"),
|
||||
artist: {
|
||||
name: result.artist
|
||||
},
|
||||
type: type
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -11,19 +11,49 @@ module.exports.lookupId = function(id, type, next) {
|
|||
|
||||
var artist = data.artists[0];
|
||||
|
||||
next({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
url: "https://play.spotify.com/" + type + "/" + data.id,
|
||||
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
|
||||
artist: {
|
||||
name: artist.name
|
||||
}
|
||||
})
|
||||
if (type == "album") {
|
||||
next({
|
||||
service: "spotify",
|
||||
type: type,
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
url: "https://play.spotify.com/" + type + "/" + data.id,
|
||||
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
|
||||
artist: {
|
||||
name: artist.name
|
||||
}
|
||||
});
|
||||
} else if (type == "track") {
|
||||
next({
|
||||
service: "spotify",
|
||||
type: type,
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
url: "https://play.spotify.com/" + type + "/" + data.id,
|
||||
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
|
||||
artist: {
|
||||
name: artist.name
|
||||
},
|
||||
album: {
|
||||
name: data.album.name
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.search = function(query, type, next) {
|
||||
module.exports.search = function(data, next) {
|
||||
var query = "";
|
||||
var type = data.type;
|
||||
|
||||
if (type == "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
} else if (type == "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
}
|
||||
|
||||
query = query.replace(":", "");
|
||||
|
||||
spotify.search({query: query, type: type}, function(err, data) {
|
||||
if ( err ) {
|
||||
console.log('Error occurred: ' + err);
|
||||
|
@ -40,6 +70,6 @@ module.exports.parseUrl = function(url, next) {
|
|||
var matches = parse(url).path.match(/\/(album|track)[\/]+([^\/]+)/);
|
||||
|
||||
if (matches && matches[2]) {
|
||||
next({id:matches[2], type: matches[1]})
|
||||
module.exports.lookupId(matches[2], matches[1], next);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue