Authenticate with Google on each API call
This commit is contained in:
parent
f66f4eaf33
commit
b0b2c452bd
1 changed files with 18 additions and 9 deletions
|
@ -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.');
|
debug('GOOGLE_EMAIL or GOOGLE_PASSWORD environment variables not found, deactivating Google Play Music.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const ready = pm.initAsync({
|
|
||||||
email: process.env.GOOGLE_EMAIL,
|
|
||||||
password: process.env.GOOGLE_PASSWORD })
|
|
||||||
.catch((err) => {
|
|
||||||
debug(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
export function* lookupId(id, type) {
|
export function* lookupId(id, type) {
|
||||||
yield ready;
|
yield pm.initAsync({
|
||||||
|
email: process.env.GOOGLE_EMAIL,
|
||||||
|
password: process.env.GOOGLE_PASSWORD })
|
||||||
|
.catch((err) => {
|
||||||
|
debug(err);
|
||||||
|
});
|
||||||
if (type === 'album') {
|
if (type === 'album') {
|
||||||
const album = yield pm.getAlbumAsync(id, false);
|
const album = yield pm.getAlbumAsync(id, false);
|
||||||
return {
|
return {
|
||||||
|
@ -91,7 +90,12 @@ function looseMatch(needle, haystack, type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* search(data, original = {}) {
|
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 query;
|
||||||
let album;
|
let album;
|
||||||
const type = data.type;
|
const type = data.type;
|
||||||
|
@ -140,7 +144,12 @@ export function* search(data, original = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* parseUrl(url) {
|
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 parsed = parse(url.replace(/\+/g, '%20'));
|
||||||
const path = parsed.path;
|
const path = parsed.path;
|
||||||
const hash = parsed.hash;
|
const hash = parsed.hash;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue