From 5d5bd605eaa3090af2a0f6cc22520987d89a1e1f Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sat, 11 Nov 2017 21:02:42 +0000 Subject: [PATCH] Restore old Google auth behaviour --- lib/services/google/index.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/services/google/index.js b/lib/services/google/index.js index 57fd534..8eaee91 100644 --- a/lib/services/google/index.js +++ b/lib/services/google/index.js @@ -12,14 +12,12 @@ if (!process.env.GOOGLE_EMAIL || !process.env.GOOGLE_PASSWORD) { debug('GOOGLE_EMAIL or GOOGLE_PASSWORD environment variables not found, deactivating Google Play Music.'); } +let ready = pm.initAsync({email: process.env.GOOGLE_EMAIL, password: process.env.GOOGLE_PASSWORD}).catch(function(err) { + debug(err); +}); export function* lookupId(id, type) { - yield pm.initAsync({ - email: process.env.GOOGLE_EMAIL, - password: process.env.GOOGLE_PASSWORD }) - .catch((err) => { - debug(err); - }); + yield ready; if (type === 'album') { const album = yield pm.getAlbumAsync(id, false); return { @@ -62,7 +60,7 @@ export function* lookupId(id, type) { } function exactMatch(needle, haystack, type) { - // try to find exact match + // try to find exact match return haystack.find((entry) => { if (!entry[type]) { return false; @@ -76,7 +74,7 @@ function exactMatch(needle, haystack, type) { } function looseMatch(needle, haystack, type) { - // try to find exact match + // try to find exact match return haystack.find((entry) => { if (!entry[type]) { return false; @@ -90,12 +88,7 @@ function looseMatch(needle, haystack, type) { } export function* search(data, original = {}, cleaned = false) { - yield pm.initAsync({ - email: process.env.GOOGLE_EMAIL, - password: process.env.GOOGLE_PASSWORD }) - .catch((err) => { - debug(err); - }); + yield ready; let query; let album; const type = data.type; @@ -146,12 +139,7 @@ export function* search(data, original = {}, cleaned = false) { } export function* parseUrl(url) { - yield pm.initAsync({ - email: process.env.GOOGLE_EMAIL, - password: process.env.GOOGLE_PASSWORD }) - .catch((err) => { - debug(err); - }); + yield ready; const parsed = parse(url.replace(/\+/g, '%20')); const path = parsed.path; const hash = parsed.hash;