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) {
|
||||
// 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 path = parsed.path;
|
||||
var hash = parsed.hash;
|
||||
console.log(path)
|
||||
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]) {
|
||||
var artist = decodeURIComponent(matches[1]);
|
||||
var album = decodeURIComponent(matches[2]);
|
||||
if (id.length > 0) {
|
||||
return next({id: id, type: type});
|
||||
} else {
|
||||
module.exports.search(artist + " " + album, "album", function(googleAlbum) {
|
||||
next(googleAlbum);
|
||||
});
|
||||
} else {
|
||||
var matches = hash.match(/\/album[\/]+([\w]+)/);
|
||||
if (matches && matches[1]) {
|
||||
return next({id:matches[1], type: "album"});
|
||||
}
|
||||
}
|
||||
} else if(path) {
|
||||
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) {
|
||||
// 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[\/]+([^\/]+)/);
|
||||
|
||||
if (matches && matches[1]) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue