Make Google searches only try stripping strings once

This commit is contained in:
Jonathan Cremin 2017-11-11 20:33:47 +00:00
parent 46142d12de
commit 2c7e4f9dee
4 changed files with 30 additions and 16 deletions

View file

@ -4,7 +4,7 @@ import PlayMusic from 'playmusic';
import debuglog from 'debug';
import urlMatch from './url';
const debug = debuglog('combine.fm');
const debug = debuglog('combine.fm:google');
const pm = bluebird.promisifyAll(new PlayMusic());
@ -89,7 +89,7 @@ function looseMatch(needle, haystack, type) {
});
}
export function* search(data, original = {}) {
export function* search(data, original = {}, cleaned = false) {
yield pm.initAsync({
email: process.env.GOOGLE_EMAIL,
password: process.env.GOOGLE_PASSWORD })
@ -111,6 +111,9 @@ export function* search(data, original = {}) {
const result = yield pm.searchAsync(query, 5);
if (!result.entries) {
if (cleaned) {
return { service: 'google' };
}
const matches = album.match(/^[^([]+/);
if (matches && matches[0]) {
const cleanedData = JSON.parse(JSON.stringify(data));
@ -120,9 +123,8 @@ export function* search(data, original = {}) {
cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim();
cleanedData.name = data.name.match(/^[^([]+/)[0].trim();
}
return yield search(cleanedData, data);
return yield search(cleanedData, data, true);
}
return { service: 'google' };
}
const name = original.name || data.name;