Fix matching from share, add fix script
This commit is contained in:
parent
183d58a540
commit
62b7121301
7 changed files with 152 additions and 60 deletions
|
@ -7,6 +7,7 @@ services:
|
||||||
DEBUG: "combine.fm*"
|
DEBUG: "combine.fm*"
|
||||||
VUE_ENV: server
|
VUE_ENV: server
|
||||||
DATABASE_URL:
|
DATABASE_URL:
|
||||||
|
REDIS_URL:
|
||||||
GOOGLE_EMAIL:
|
GOOGLE_EMAIL:
|
||||||
GOOGLE_PASSWORD:
|
GOOGLE_PASSWORD:
|
||||||
XBOX_CLIENT_ID:
|
XBOX_CLIENT_ID:
|
||||||
|
@ -20,20 +21,8 @@ services:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
command: yarn run watch-server
|
command: yarn run watch-server
|
||||||
worker:
|
worker:
|
||||||
|
extends: app
|
||||||
build: ./
|
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
|
command: yarn run worker
|
||||||
ports:
|
ports:
|
||||||
- "3001:3000"
|
- "3001:3000"
|
||||||
|
|
87
fixmissing.js
Normal file
87
fixmissing.js
Normal 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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ body {
|
||||||
height: 64px;
|
height: 64px;
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
text-align: left;
|
text-align: center;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
}
|
}
|
||||||
h1 a {
|
h1 a {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import services from '../lib/services';
|
||||||
import render from '../lib/render';
|
import render from '../lib/render';
|
||||||
import models from '../models';
|
import models from '../models';
|
||||||
|
|
||||||
const debug = debuglog('combinefm:share');
|
const debug = debuglog('combine.fm:share');
|
||||||
|
|
||||||
const recentQuery = {
|
const recentQuery = {
|
||||||
include: [
|
include: [
|
||||||
|
|
|
@ -23,9 +23,14 @@ export default function* () {
|
||||||
if (!share) {
|
if (!share) {
|
||||||
share = yield create(music);
|
share = yield create(music);
|
||||||
|
|
||||||
const job = queue.create('search', share).save((err) => {
|
for (const service of services) {
|
||||||
if (!err) console.log(job.id);
|
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();
|
share = share.toJSON();
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
|
import kue from 'kue';
|
||||||
|
|
||||||
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, 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) {
|
export default function* (serviceId, type, itemId, format) {
|
||||||
this.assert(type === 'album' || type === 'track', 400, { error: 'Invalid type' });
|
this.assert(type === 'album' || type === 'track', 400, { error: 'Invalid type' });
|
||||||
|
@ -26,7 +32,15 @@ export default function* (serviceId, type, itemId, format) {
|
||||||
|
|
||||||
if (!share) {
|
if (!share) {
|
||||||
share = yield create(music);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
77
worker.js
77
worker.js
|
@ -4,7 +4,6 @@ import raven from 'raven';
|
||||||
|
|
||||||
import models from './models';
|
import models from './models';
|
||||||
import services from './lib/services';
|
import services from './lib/services';
|
||||||
import { find, create, findMatchesAsync } from './lib/share';
|
|
||||||
|
|
||||||
raven.config(process.env.SENTRY_DSN).install();
|
raven.config(process.env.SENTRY_DSN).install();
|
||||||
|
|
||||||
|
@ -12,46 +11,44 @@ const queue = kue.createQueue({
|
||||||
redis: process.env.REDIS_URL,
|
redis: process.env.REDIS_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
function search(share, done) {
|
function search(data, done) {
|
||||||
for (const service of services) {
|
const share = data.share;
|
||||||
if (service.id === share.service) {
|
const service = services.find(item => data.service.id === item.id);
|
||||||
continue; // eslint-disable-line no-continue
|
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
|
return done();
|
||||||
const match = yield service.search(share);
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
if (match.id) {
|
raven.captureException(err);
|
||||||
models.match.create({
|
return done();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.process('search', (job, done) => {
|
queue.process('search', (job, done) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue