Fix matching from share, add fix script

This commit is contained in:
Jonathan Cremin 2017-10-23 21:05:58 +01:00
parent 183d58a540
commit 62b7121301
7 changed files with 152 additions and 60 deletions

View file

@ -7,6 +7,7 @@ services:
DEBUG: "combine.fm*"
VUE_ENV: server
DATABASE_URL:
REDIS_URL:
GOOGLE_EMAIL:
GOOGLE_PASSWORD:
XBOX_CLIENT_ID:
@ -20,20 +21,8 @@ services:
- "3000:3000"
command: yarn run watch-server
worker:
extends: app
build: ./
environment:
DEBUG: "combine.fm*"
VUE_ENV: server
DATABASE_URL:
GOOGLE_EMAIL:
GOOGLE_PASSWORD:
XBOX_CLIENT_ID:
XBOX_CLIENT_SECRET:
YOUTUBE_KEY:
SPOTIFY_CLIENT_ID:
SPOTIFY_CLIENT_SECRET:
volumes:
- ./:/app:cached
command: yarn run worker
ports:
- "3001:3000"

87
fixmissing.js Normal file
View file

@ -0,0 +1,87 @@
import co from 'co';
import debuglog from 'debug';
import models from './models';
import services from './lib/services';
const debug = debuglog('combine.fm:fixmissing');
debug('Fixing missing');
const serviceIds = [];
for (const service of services) {
serviceIds.push(service.id);
}
const query = {
include: [
{ model: models.artist },
{ model: models.match },
],
order: [
['updatedAt', 'DESC'],
],
};
function* search(data, done) {
const share = data.share;
const service = services.find(item => data.service.id === item.id);
debug(`Matching ${share.name} on ${data.service.id}`)
const match = yield service.search(share);
debug(`Match found for ${share.name} on ${data.service.id}`);
if (match.id) {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: match.id.toString(),
service: match.service,
name: match.name,
streamUrl: match.streamUrl,
purchaseUrl: match.purchaseUrl,
artworkSmall: match.artwork.small,
artworkLarge: match.artwork.large,
});
} else {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: null,
service: match.service,
name: null,
streamUrl: null,
purchaseUrl: null,
artworkSmall: null,
artworkLarge: null,
});
}
}
co(function* () {
const albums = yield models.album.findAll(query);
for (const item of albums) {
const unmatched = serviceIds;
for (const match of item.matches) {
unmatched = unmatched.filter(id => match.service !== id);
}
if (unmatched.length > 0) {
debug(`Matching ${unmatched.join(', ')}`);
for (const toMatch of unmatched) {
yield search({ share: item, service: { id: toMatch } });
}
} else {
debug(`No broken matches for ${item.name}`)
}
}
}).catch(function (err) {
debug(err.stack);
});

View file

@ -41,7 +41,7 @@ body {
height: 64px;
}
h1 {
text-align: left;
text-align: center;
padding: 10px 0;
}
h1 a {

View file

@ -4,7 +4,7 @@ import services from '../lib/services';
import render from '../lib/render';
import models from '../models';
const debug = debuglog('combinefm:share');
const debug = debuglog('combine.fm:share');
const recentQuery = {
include: [

View file

@ -23,9 +23,14 @@ export default function* () {
if (!share) {
share = yield create(music);
const job = queue.create('search', share).save((err) => {
if (!err) console.log(job.id);
});
for (const service of services) {
if (service.id === share.service) {
continue; // eslint-disable-line no-continue
}
const job = queue.create('search', {share: share, service: service}).save((err) => {
if (!err) console.log(job.id);
});
}
}
share = share.toJSON();

View file

@ -1,7 +1,13 @@
import kue from 'kue';
import services from '../lib/services';
import render from '../lib/render';
import models from '../models';
import { find, create, findMatchesAsync } from '../lib/share';
import { find, create } from '../lib/share';
const queue = kue.createQueue({
redis: process.env.REDIS_URL,
});
export default function* (serviceId, type, itemId, format) {
this.assert(type === 'album' || type === 'track', 400, { error: 'Invalid type' });
@ -26,7 +32,15 @@ export default function* (serviceId, type, itemId, format) {
if (!share) {
share = yield create(music);
findMatchesAsync(share);
for (const service of services) {
if (service.id === share.service) {
continue; // eslint-disable-line no-continue
}
const job = queue.create('search', {share: share, service: service}).save((err) => {
if (!err) console.log(job.id);
});
}
}
}

View file

@ -4,7 +4,6 @@ import raven from 'raven';
import models from './models';
import services from './lib/services';
import { find, create, findMatchesAsync } from './lib/share';
raven.config(process.env.SENTRY_DSN).install();
@ -12,46 +11,44 @@ const queue = kue.createQueue({
redis: process.env.REDIS_URL,
});
function search(share, done) {
for (const service of services) {
if (service.id === share.service) {
continue; // eslint-disable-line no-continue
function search(data, done) {
const share = data.share;
const service = services.find(item => data.service.id === item.id);
console.log(service);
co(function* gen() { // eslint-disable-line no-loop-func
const match = yield service.search(share);
if (match.id) {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: match.id.toString(),
service: match.service,
name: match.name,
streamUrl: match.streamUrl,
purchaseUrl: match.purchaseUrl,
artworkSmall: match.artwork.small,
artworkLarge: match.artwork.large,
});
} else {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: null,
service: match.service,
name: null,
streamUrl: null,
purchaseUrl: null,
artworkSmall: null,
artworkLarge: null,
});
}
co(function* gen() { // eslint-disable-line no-loop-func
const match = yield service.search(share);
if (match.id) {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: match.id.toString(),
service: match.service,
name: match.name,
streamUrl: match.streamUrl,
purchaseUrl: match.purchaseUrl,
artworkSmall: match.artwork.small,
artworkLarge: match.artwork.large,
});
} else {
models.match.create({
trackId: share.type === 'track' ? share.id : null,
albumId: share.type === 'album' ? share.id : null,
externalId: null,
service: match.service,
name: null,
streamUrl: null,
purchaseUrl: null,
artworkSmall: null,
artworkLarge: null,
});
}
}).catch((err) => {
raven.captureException(err);
});
}
return done();
return done();
}).catch((err) => {
console.log(err);
raven.captureException(err);
return done();
});
}
queue.process('search', (job, done) => {