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]+)/);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue