Add rdio support
This commit is contained in:
parent
aca2eea4dd
commit
493482386e
7 changed files with 129 additions and 25 deletions
|
@ -37,26 +37,22 @@ module.exports.search = function(query, type, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.parseUrl = function(url, next) {
|
module.exports.parseUrl = function(url, next) {
|
||||||
// https://play.google.com/music/listen#/album/B3lxthejqxjxja2bhzchcw5qaci
|
|
||||||
// https://play.google.com/music/listen#/album//Underworld/Everything%2C+Everything+(Live)
|
|
||||||
var parsed = parse(url.replace(/\+/g, "%20"));
|
var parsed = parse(url.replace(/\+/g, "%20"));
|
||||||
var path = parsed.path;
|
var path = parsed.path;
|
||||||
var hash = parsed.hash;
|
var hash = parsed.hash;
|
||||||
console.log(path)
|
|
||||||
if (hash) {
|
if (hash) {
|
||||||
var matches = hash.match(/\/album[\/]+([^\/]+)\/([^\/]+)/);
|
var parts = hash.split("/");
|
||||||
|
var type = parts[1];
|
||||||
|
var id = parts[2];
|
||||||
|
var artist = decodeURIComponent(parts[3]);
|
||||||
|
var album = decodeURIComponent(parts[4]);
|
||||||
|
|
||||||
if (matches && matches[2]) {
|
if (id.length > 0) {
|
||||||
var artist = decodeURIComponent(matches[1]);
|
return next({id: id, type: type});
|
||||||
var album = decodeURIComponent(matches[2]);
|
} else {
|
||||||
module.exports.search(artist + " " + album, "album", function(googleAlbum) {
|
module.exports.search(artist + " " + album, "album", function(googleAlbum) {
|
||||||
next(googleAlbum);
|
next(googleAlbum);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
var matches = hash.match(/\/album[\/]+([\w]+)/);
|
|
||||||
if (matches && matches[1]) {
|
|
||||||
return next({id:matches[1], type: "album"});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if(path) {
|
} else if(path) {
|
||||||
var matches = path.match(/\/music\/m\/([\w]+)/);
|
var matches = path.match(/\/music\/m\/([\w]+)/);
|
||||||
|
|
90
lib/rdio.js
Normal file
90
lib/rdio.js
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
var parse = require('url').parse;
|
||||||
|
|
||||||
|
if (!process.env.RDIO_API_KEY || !process.env.RDIO_API_SHARED) {
|
||||||
|
throw new Error("You need to set GOOGLE_EMAIL and GOOGLE_PASSWORD environment variables");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var rdio = require('rdio')({
|
||||||
|
rdio_api_key: process.env.RDIO_API_KEY,
|
||||||
|
rdio_api_shared: process.env.RDIO_API_SHARED,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports.lookupId = function(id, next) {
|
||||||
|
rdio.api("", "", {
|
||||||
|
method: 'getObjectFromShortCode',
|
||||||
|
short_code: id,
|
||||||
|
}, function(err, results) {
|
||||||
|
var result = JSON.parse(results).result;
|
||||||
|
var parsed = parse(result.shortUrl)
|
||||||
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
|
next({
|
||||||
|
id: id,
|
||||||
|
name: result.name,
|
||||||
|
url: result.shortUrl,
|
||||||
|
artwork: result.icon.replace("http:", ""),
|
||||||
|
artist: {
|
||||||
|
name: result.artist
|
||||||
|
},
|
||||||
|
type: "album"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.lookupUrl = function(url, next) {
|
||||||
|
var parsed = parse(url);
|
||||||
|
|
||||||
|
var data;
|
||||||
|
|
||||||
|
if (parsed.host == "rd.io") {
|
||||||
|
data = {
|
||||||
|
method: 'getObjectFromShortCode',
|
||||||
|
short_code: parsed.path.replace("/x/", "").replace("/", ""),
|
||||||
|
};
|
||||||
|
} else if (parsed.host.match(/rdio\.com$/)) {
|
||||||
|
data = {
|
||||||
|
method: 'getObjectFromUrl',
|
||||||
|
url: parsed.path,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rdio.api("", "", data, function(err, results) {
|
||||||
|
var result = JSON.parse(results).result;
|
||||||
|
var parsed = parse(result.shortUrl)
|
||||||
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
|
next({
|
||||||
|
id: id,
|
||||||
|
name: result.name,
|
||||||
|
url: result.shortUrl,
|
||||||
|
artwork: result.icon.replace("http:", ""),
|
||||||
|
artist: {
|
||||||
|
name: result.artist
|
||||||
|
},
|
||||||
|
type: "album"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.search = function(query, type, next) {
|
||||||
|
rdio.api("", "", {
|
||||||
|
query: query,
|
||||||
|
method: 'search',
|
||||||
|
types: type,
|
||||||
|
}, function(err, results) {
|
||||||
|
var result = JSON.parse(results).result.results[0];
|
||||||
|
var parsed = parse(result.shortUrl)
|
||||||
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
|
next({
|
||||||
|
id: id,
|
||||||
|
name: result.name,
|
||||||
|
url: result.shortUrl,
|
||||||
|
artwork: result.icon.replace("http:", ""),
|
||||||
|
artist: {
|
||||||
|
name: result.artist
|
||||||
|
},
|
||||||
|
type: "album"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
|
@ -36,11 +36,6 @@ module.exports.search = function(query, type, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.parseUrl = function(url, next) {
|
module.exports.parseUrl = function(url, next) {
|
||||||
// https://play.spotify.com/album/3W3ENDBQMJ9bD2qmxWI2f0
|
|
||||||
// https://play.spotify.com/track/3W3ENDBQMJ9bD2qmxWI2f0
|
|
||||||
// https://open.spotify.com/album/3W3ENDBQMJ9bD2qmxWI2f0
|
|
||||||
// https://open.spotify.com/track/3W3ENDBQMJ9bD2qmxWI2f0
|
|
||||||
|
|
||||||
var matches = parse(url).path.match(/\/album[\/]+([^\/]+)/);
|
var matches = parse(url).path.match(/\/album[\/]+([^\/]+)/);
|
||||||
|
|
||||||
if (matches && matches[1]) {
|
if (matches && matches[1]) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"express-session": "^1.9.2",
|
"express-session": "^1.9.2",
|
||||||
"morgan": "~1.3.0",
|
"morgan": "~1.3.0",
|
||||||
"playmusic": "^1.1.0",
|
"playmusic": "^1.1.0",
|
||||||
|
"rdio": "^1.5.2",
|
||||||
"serve-favicon": "~2.1.3",
|
"serve-favicon": "~2.1.3",
|
||||||
"spotify": "^0.3.0"
|
"spotify": "^0.3.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@ var router = express.Router();
|
||||||
|
|
||||||
var googleplaymusic = require('../lib/googleplaymusic');
|
var googleplaymusic = require('../lib/googleplaymusic');
|
||||||
var spotify = require('../lib/spotify');
|
var spotify = require('../lib/spotify');
|
||||||
|
var rdio = require('../lib/rdio');
|
||||||
//https://play.spotify.com/album/3W3ENDBQMJ9bD2qmxWI2f0
|
|
||||||
//https://play.google.com/music/listen#/album/B3lxthejqxjxja2bhzchcw5qaci
|
|
||||||
|
|
||||||
router.get('/:service/:type/:id', function(req, res) {
|
router.get('/:service/:type/:id', function(req, res) {
|
||||||
var service = req.params.service;
|
var service = req.params.service;
|
||||||
|
@ -16,14 +14,27 @@ router.get('/:service/:type/:id', function(req, res) {
|
||||||
case "spotify":
|
case "spotify":
|
||||||
spotify.lookupId(id, type, function(spotifyAlbum) {
|
spotify.lookupId(id, type, function(spotifyAlbum) {
|
||||||
googleplaymusic.search(spotifyAlbum.artist.name + " " + spotifyAlbum.name, "album", function(googleAlbum) {
|
googleplaymusic.search(spotifyAlbum.artist.name + " " + spotifyAlbum.name, "album", function(googleAlbum) {
|
||||||
res.render('album', {googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
rdio.search(googleAlbum.artist.name + " " + googleAlbum.name, "album", function(rdioAlbum) {
|
||||||
|
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "google":
|
case "google":
|
||||||
googleplaymusic.lookupId(id, type, function(googleAlbum) {
|
googleplaymusic.lookupId(id, type, function(googleAlbum) {
|
||||||
spotify.search(googleAlbum.artist.name + " " + googleAlbum.name, "album", function(spotifyAlbum) {
|
spotify.search(googleAlbum.artist.name + " " + googleAlbum.name, "album", function(spotifyAlbum) {
|
||||||
res.render('album', {googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
rdio.search(googleAlbum.artist.name + " " + googleAlbum.name, "album", function(rdioAlbum) {
|
||||||
|
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "rdio":
|
||||||
|
rdio.lookupId(id, function(rdioAlbum) {
|
||||||
|
googleplaymusic.search(rdioAlbum.artist.name + " " + rdioAlbum.name, "album", function(googleAlbum) {
|
||||||
|
spotify.search(rdioAlbum.artist.name + " " + rdioAlbum.name, "album", function(spotifyAlbum) {
|
||||||
|
res.render('album', {rdioAlbum: rdioAlbum, googleAlbum: googleAlbum, spotifyAlbum: spotifyAlbum});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -34,7 +45,15 @@ router.post('/search', function(req, res) {
|
||||||
// determine spotify or google music
|
// determine spotify or google music
|
||||||
var url = req.body.url;
|
var url = req.body.url;
|
||||||
|
|
||||||
if (url.match(/spotify\.com/)) {
|
if (url.match(/rd\.io/) || url.match(/rdio\.com/)) {
|
||||||
|
rdio.lookupUrl(url, function(result) {
|
||||||
|
if (!result.id) {
|
||||||
|
req.flash('search-error', 'No match found for this link');
|
||||||
|
res.redirect('/');
|
||||||
|
}
|
||||||
|
res.redirect("/rdio/" + result.type + "/" + result.id);
|
||||||
|
});
|
||||||
|
} else if (url.match(/spotify\.com/)) {
|
||||||
spotify.parseUrl(url, function(result) {
|
spotify.parseUrl(url, function(result) {
|
||||||
if (!result.id) {
|
if (!result.id) {
|
||||||
req.flash('search-error', 'No match found for this link');
|
req.flash('search-error', 'No match found for this link');
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<img src="<%= googleAlbum.artwork %>" height=200 class="img-rounded" /> <%= googleAlbum.id %> <a href="<%= googleAlbum.url %>">Play on Google Music</a>
|
<img src="<%= googleAlbum.artwork %>" height=200 class="img-rounded" /> <%= googleAlbum.id %> <a href="<%= googleAlbum.url %>">Play on Google Music</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<img src="<%= rdioAlbum.artwork %>" height=200 class="img-rounded" /> <%= rdioAlbum.id %> <a href="<%= rdioAlbum.url %>">Play on Rdio</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
<form role="form" method="post" action="/search" class="form-inline">
|
<form role="form" method="post" action="/search" class="form-inline">
|
||||||
<div class="form-group form-group-lg">
|
<div class="form-group form-group-lg">
|
||||||
<input type="text" name="url" placeholder="Paste link here" class="form-control">
|
<input type="text" name="url" placeholder="Paste link here" class="form-control">
|
||||||
<input type="submit" class="btn btn-default btn-lg" value="Find Matches">
|
<input type="submit" class="btn btn-default btn-lg" value="Share Music">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 col-sm-offset-3">
|
<div class="col-sm-6 col-sm-offset-3">
|
||||||
<p>Make sharing music from subscription services better. Give us one link and we'll match it with other services and give you back a link with all of them. <a href="/google/album/B3qrtsvk5s3piwyla76sk6qyxny">Here's an example</a>.</p>
|
<p>Make sharing music from subscription services better. Give us one link (Rdio, Spotify or Google Music) and we'll match it with other services and give you back a link with all of them. <a href="/google/album/B3qrtsvk5s3piwyla76sk6qyxny">Here's an example</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue