Authenticate with Google on each API call

This commit is contained in:
Jonathan Cremin 2017-10-24 19:45:16 +01:00
parent f66f4eaf33
commit b0b2c452bd

View file

@ -12,15 +12,14 @@ if (!process.env.GOOGLE_EMAIL || !process.env.GOOGLE_PASSWORD) {
debug('GOOGLE_EMAIL or GOOGLE_PASSWORD environment variables not found, deactivating Google Play Music.');
}
const ready = pm.initAsync({
export function* lookupId(id, type) {
yield pm.initAsync({
email: process.env.GOOGLE_EMAIL,
password: process.env.GOOGLE_PASSWORD })
.catch((err) => {
debug(err);
});
export function* lookupId(id, type) {
yield ready;
if (type === 'album') {
const album = yield pm.getAlbumAsync(id, false);
return {
@ -91,7 +90,12 @@ function looseMatch(needle, haystack, type) {
}
export function* search(data, original = {}) {
yield ready;
yield pm.initAsync({
email: process.env.GOOGLE_EMAIL,
password: process.env.GOOGLE_PASSWORD })
.catch((err) => {
debug(err);
});
let query;
let album;
const type = data.type;
@ -140,7 +144,12 @@ export function* search(data, original = {}) {
}
export function* parseUrl(url) {
yield ready;
yield pm.initAsync({
email: process.env.GOOGLE_EMAIL,
password: process.env.GOOGLE_PASSWORD })
.catch((err) => {
debug(err);
});
const parsed = parse(url.replace(/\+/g, '%20'));
const path = parsed.path;
const hash = parsed.hash;