Make Google searches only try stripping strings once
This commit is contained in:
parent
46142d12de
commit
2c7e4f9dee
4 changed files with 30 additions and 16 deletions
|
@ -4,7 +4,7 @@ import PlayMusic from 'playmusic';
|
||||||
import debuglog from 'debug';
|
import debuglog from 'debug';
|
||||||
import urlMatch from './url';
|
import urlMatch from './url';
|
||||||
|
|
||||||
const debug = debuglog('combine.fm');
|
const debug = debuglog('combine.fm:google');
|
||||||
|
|
||||||
const pm = bluebird.promisifyAll(new PlayMusic());
|
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({
|
yield pm.initAsync({
|
||||||
email: process.env.GOOGLE_EMAIL,
|
email: process.env.GOOGLE_EMAIL,
|
||||||
password: process.env.GOOGLE_PASSWORD })
|
password: process.env.GOOGLE_PASSWORD })
|
||||||
|
@ -111,6 +111,9 @@ export function* search(data, original = {}) {
|
||||||
const result = yield pm.searchAsync(query, 5);
|
const result = yield pm.searchAsync(query, 5);
|
||||||
|
|
||||||
if (!result.entries) {
|
if (!result.entries) {
|
||||||
|
if (cleaned) {
|
||||||
|
return { service: 'google' };
|
||||||
|
}
|
||||||
const matches = album.match(/^[^([]+/);
|
const matches = album.match(/^[^([]+/);
|
||||||
if (matches && matches[0]) {
|
if (matches && matches[0]) {
|
||||||
const cleanedData = JSON.parse(JSON.stringify(data));
|
const cleanedData = JSON.parse(JSON.stringify(data));
|
||||||
|
@ -120,9 +123,8 @@ export function* search(data, original = {}) {
|
||||||
cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim();
|
cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim();
|
||||||
cleanedData.name = data.name.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;
|
const name = original.name || data.name;
|
||||||
|
|
|
@ -29,9 +29,12 @@ export default function* () {
|
||||||
|
|
||||||
services.forEach((service) => {
|
services.forEach((service) => {
|
||||||
if (service.id !== share.service) {
|
if (service.id !== share.service) {
|
||||||
const job = queue.create('search', { share, service }).save((err) => {
|
const job = queue.create('search', { share, service })
|
||||||
debug(err || job.id);
|
.attempts(3)
|
||||||
});
|
.backoff({ type: 'exponential' })
|
||||||
|
.save((err) => {
|
||||||
|
debug(err || `JobID: ${job.id}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import kue from 'kue';
|
import kue from 'kue';
|
||||||
|
import debuglog from 'debug';
|
||||||
|
|
||||||
import services from '../lib/services';
|
import services from '../lib/services';
|
||||||
import render from '../lib/render';
|
import render from '../lib/render';
|
||||||
import models from '../models';
|
import models from '../models';
|
||||||
import { find, create } from '../lib/share';
|
import { find, create } from '../lib/share';
|
||||||
|
|
||||||
|
const debug = debuglog('combine.fm:share');
|
||||||
|
|
||||||
const queue = kue.createQueue({
|
const queue = kue.createQueue({
|
||||||
redis: process.env.REDIS_URL,
|
redis: process.env.REDIS_URL,
|
||||||
});
|
});
|
||||||
|
@ -33,14 +36,16 @@ export default function* (serviceId, type, itemId, format) {
|
||||||
if (!share) {
|
if (!share) {
|
||||||
share = yield create(music);
|
share = yield create(music);
|
||||||
|
|
||||||
for (const service of services) {
|
services.forEach((service) => {
|
||||||
if (service.id === share.service) {
|
if (service.id !== share.service) {
|
||||||
continue; // eslint-disable-line no-continue
|
const job = queue.create('search', { share, service })
|
||||||
|
.attempts(3)
|
||||||
|
.backoff({ type: 'exponential' })
|
||||||
|
.save((err) => {
|
||||||
|
debug(err || `JobID: ${job.id}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const job = queue.create('search', {share: share, service: service}).save((err) => {
|
});
|
||||||
if (!err) console.log(job.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const queue = kue.createQueue({
|
||||||
function search(data, done) {
|
function search(data, done) {
|
||||||
const share = data.share;
|
const share = data.share;
|
||||||
const service = services.find(item => data.service.id === item.id);
|
const service = services.find(item => data.service.id === item.id);
|
||||||
debug(`Searching on: ${service}`);
|
debug(`Searching on: ${service.id}`);
|
||||||
co(function* gen() { // eslint-disable-line no-loop-func
|
co(function* gen() { // eslint-disable-line no-loop-func
|
||||||
try {
|
try {
|
||||||
const match = yield service.search(share);
|
const match = yield service.search(share);
|
||||||
|
@ -49,10 +49,14 @@ function search(data, done) {
|
||||||
}
|
}
|
||||||
return done();
|
return done();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
debug(`Error searching on: ${service.id}`);
|
||||||
|
debug(share);
|
||||||
|
debug(err);
|
||||||
|
raven.captureException(err);
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
debug(`Error searching on: ${service}`);
|
debug(`Error searching on: ${service.id}`);
|
||||||
debug(share);
|
debug(share);
|
||||||
debug(err);
|
debug(err);
|
||||||
raven.captureException(err);
|
raven.captureException(err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue