Unvendor playmusic, move to eslint
This commit is contained in:
parent
c7bfb3edf6
commit
23e8ee2405
8 changed files with 39 additions and 529 deletions
|
@ -1,21 +1,21 @@
|
|||
"use strict";
|
||||
|
||||
var parse = require("url").parse;
|
||||
var Promise = require('bluebird');
|
||||
var PlayMusic = require('../../playmusic');
|
||||
var Promise = require("bluebird");
|
||||
var PlayMusic = require("playmusic");
|
||||
var pm = Promise.promisifyAll(new PlayMusic());
|
||||
|
||||
module.exports.id = "google";
|
||||
|
||||
if (!process.env.GOOGLE_EMAIL || !process.env.GOOGLE_PASSWORD) {
|
||||
console.warn("GOOGLE_EMAIL or GOOGLE_PASSWORD environment variables not found, deactivating Google Play Music.");
|
||||
return;
|
||||
}
|
||||
|
||||
var ready = pm.initAsync({email: process.env.GOOGLE_EMAIL, password: process.env.GOOGLE_PASSWORD}).catch(function(err) {
|
||||
console.log(err)
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
module.exports.match = require('./url').match;
|
||||
module.exports.match = require("./url").match;
|
||||
|
||||
module.exports.parseUrl = function(url) {
|
||||
return ready.then(function() {
|
||||
|
@ -28,28 +28,28 @@ module.exports.parseUrl = function(url) {
|
|||
var id = parts[2];
|
||||
var artist = decodeURIComponent(parts[3]);
|
||||
var album = decodeURIComponent(parts[4]);
|
||||
|
||||
if (type != "album" && type != "track") {
|
||||
|
||||
if (type !== "album" && type !== "track") {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (id.length > 0) {
|
||||
return {id: id, type: type};
|
||||
} else {
|
||||
return module.exports.search({type: type, name:album, artist: {name: artist}});
|
||||
return module.exports.search({type: type, name: album, artist: {name: artist}});
|
||||
}
|
||||
} else if(path) {
|
||||
var matches = path.match(/\/music\/m\/([\w]+)/);
|
||||
var type = matches[1][0] == "T" ? "track" : "album";
|
||||
type = matches[1][0] === "T" ? "track" : "album";
|
||||
return module.exports.lookupId(matches[1], type);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.lookupId = function(id, type) {
|
||||
return ready.then(function() {
|
||||
if (type == "album") {
|
||||
if (type === "album") {
|
||||
return pm.getAlbumAsync(id, false).then(function(album) {
|
||||
return {
|
||||
service: "google",
|
||||
|
@ -69,8 +69,8 @@ module.exports.lookupId = function(id, type) {
|
|||
}, function(error) {
|
||||
throw error;
|
||||
});
|
||||
} else if (type == "track") {
|
||||
return pm.getTrackAsync(id).then(function(track) {
|
||||
} else if (type === "track") {
|
||||
return pm.getAllAccessTrackAsync(id).then(function(track) {
|
||||
return {
|
||||
service: "google",
|
||||
type: "track",
|
||||
|
@ -94,30 +94,30 @@ module.exports.lookupId = function(id, type) {
|
|||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.search = function(data) {
|
||||
return ready.then(function() {
|
||||
var query, album;
|
||||
var type = data.type;
|
||||
|
||||
if (type == "album") {
|
||||
if (type === "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
album = data.name;
|
||||
} else if (type == "track") {
|
||||
} else if (type === "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
album = data.album.name;
|
||||
}
|
||||
|
||||
return pm.searchAsync(query, 5).then(function(result) {
|
||||
|
||||
|
||||
if (!result.entries) {
|
||||
var matches = album.match(/^[^\(\[]+/);
|
||||
if (matches && matches[0] && matches[0] != album) {
|
||||
if (matches && matches[0] && matches[0] !== album) {
|
||||
var cleanedData = JSON.parse(JSON.stringify(data));
|
||||
if (type == "album") {
|
||||
if (type === "album") {
|
||||
cleanedData.name = matches[0].trim();
|
||||
} else if (type == "track") {
|
||||
} else if (type === "track") {
|
||||
cleanedData.album.name = matches[0].trim();
|
||||
}
|
||||
return module.exports.search(cleanedData);
|
||||
|
@ -125,8 +125,8 @@ module.exports.search = function(data) {
|
|||
return {service: "google"};
|
||||
}
|
||||
}
|
||||
var result = result.entries.filter(function(result) {
|
||||
return result[type];
|
||||
result = result.entries.filter(function(entry) {
|
||||
return entry[type];
|
||||
}).sort(function(a, b) { // sort by match score
|
||||
return a.score < b.score;
|
||||
}).shift();
|
||||
|
@ -135,9 +135,9 @@ module.exports.search = function(data) {
|
|||
return {service: "google"};
|
||||
} else {
|
||||
var id;
|
||||
if (type == "album") {
|
||||
if (type === "album") {
|
||||
id = result.album.albumId;
|
||||
} else if (type == "track") {
|
||||
} else if (type === "track") {
|
||||
id = result.track.nid;
|
||||
}
|
||||
|
||||
|
@ -145,4 +145,4 @@ module.exports.search = function(data) {
|
|||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue