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
|
@ -7,35 +7,47 @@ var googleplaymusic = require('../lib/googleplaymusic');
|
|||
var spotify = require('../lib/spotify');
|
||||
var rdio = require('../lib/rdio');
|
||||
|
||||
var cache = {googleplaymusic:{}, spotify:{},rdio:{}};
|
||||
|
||||
router.get('/:service/:type/:id', function(req, res) {
|
||||
var service = req.params.service;
|
||||
var type = req.params.type;
|
||||
var id = req.params.id;
|
||||
var items = [];
|
||||
|
||||
switch(service) {
|
||||
case "spotify":
|
||||
spotify.lookupId(id, type, function(spotifyAlbum) {
|
||||
googleplaymusic.search(spotifyAlbum.artist.name + " " + spotifyAlbum.name, type, function(googleAlbum) {
|
||||
rdio.search(googleAlbum.artist.name + " " + googleAlbum.name, type, function(rdioAlbum) {
|
||||
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||
spotify.lookupId(id, type, function(result) {
|
||||
items.push(result);
|
||||
googleplaymusic.search(result, function(item) {
|
||||
items.push(item);
|
||||
rdio.search(result, function(item) {
|
||||
items.push(item);
|
||||
res.render(result.type, {items: items});
|
||||
});
|
||||
});
|
||||
});
|
||||
break;
|
||||
case "google":
|
||||
googleplaymusic.lookupId(id, type, function(googleAlbum) {
|
||||
spotify.search(googleAlbum.artist.name + " " + googleAlbum.name, type, function(spotifyAlbum) {
|
||||
rdio.search(googleAlbum.artist.name + " " + googleAlbum.name, type, function(rdioAlbum) {
|
||||
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||
googleplaymusic.lookupId(id, type, function(result) {
|
||||
items.push(result);
|
||||
spotify.search(result, function(item) {
|
||||
items.push(item);
|
||||
rdio.search(result, function(item) {
|
||||
items.push(item);
|
||||
res.render(result.type, {items: items});
|
||||
});
|
||||
});
|
||||
});
|
||||
break;
|
||||
case "rdio":
|
||||
rdio.lookupId(id, function(rdioAlbum) {
|
||||
googleplaymusic.search(rdioAlbum.artist.name + " " + rdioAlbum.name, type, function(googleAlbum) {
|
||||
spotify.search(rdioAlbum.artist.name + " " + rdioAlbum.name, type, function(spotifyAlbum) {
|
||||
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||
rdio.lookupId(id, type, function(result) {
|
||||
items.push(result);
|
||||
googleplaymusic.search(result, function(item) {
|
||||
items.push(item);
|
||||
spotify.search(result, function(item) {
|
||||
items.push(item);
|
||||
res.render(result.type, {items: items});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -65,11 +77,12 @@ router.post('/search', function(req, res) {
|
|||
});
|
||||
} else if (url.host.match(/play\.google\.com$/)) {
|
||||
googleplaymusic.parseUrl(url.href, function(result) {
|
||||
if (!result.id) {
|
||||
if (!result) {
|
||||
req.flash('search-error', 'No match found for this link');
|
||||
res.redirect('/');
|
||||
} else {
|
||||
res.redirect("/google/" + result.type + "/" + result.id);
|
||||
}
|
||||
res.redirect("/google/" + result.type + "/" + result.id);
|
||||
});
|
||||
} else {
|
||||
req.flash('search-error', 'No match found for this link');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue