Minor bugfixes for groove and deezer

This commit is contained in:
Jonathan Cremin 2017-05-26 19:47:17 +01:00
parent cfaef8be94
commit 2693afb2bd
7 changed files with 27 additions and 23 deletions

2
app.js
View file

@ -31,7 +31,7 @@ app.on('error', (err) => {
raven.captureException(err); raven.captureException(err);
}); });
app.use(errorHandler()); app.use(errorHandler(raven));
app.use(bodyparser()); app.use(bodyparser());
app.use(cors()); app.use(cors());

View file

@ -2,7 +2,7 @@ import debuglog from 'debug';
const debug = debuglog('match.audio'); const debug = debuglog('match.audio');
export default function () { export default function (raven) {
return function* error(next) { return function* error(next) {
this.set('Server', 'Nintendo 64'); this.set('Server', 'Nintendo 64');
try { try {
@ -15,6 +15,7 @@ export default function () {
this.body = err.error; this.body = err.error;
} else { } else {
debug('Error: %o', err); debug('Error: %o', err);
raven.captureException(err);
throw err; throw err;
} }
} }

View file

@ -68,12 +68,12 @@ export function* parseUrl(url) {
const parsed = parse(url); const parsed = parse(url);
const parts = parsed.path.split('/'); const parts = parsed.path.split('/');
const type = parts[1]; const type = parts[1];
const idMatches = parts[4].match(/[\w\-]+/); const idMatches = parts[4].match(/bz.[\w\-]+/);
const id = idMatches[0]; const id = idMatches[0].replace('bz.', 'music.');
if (!id) { if (!id) {
return false; return false;
} }
return yield lookupId('music.' + id, type); return yield lookupId(id, type);
} }
export function* lookupId(id, type) { export function* lookupId(id, type) {
@ -106,8 +106,8 @@ export function* search(data) {
} }
const name = data.name; const name = data.name;
const path = '/music/search?q=' + encodeURIComponent(query.trim()) + '&filters=' + type + 's';
const path = '/music/search?q=' + encodeURIComponent(query) + '&filters=' + type + 's'; try {
const result = yield apiCall(path); const result = yield apiCall(path);
const apiType = type.charAt(0).toUpperCase() + type.substr(1) + 's'; const apiType = type.charAt(0).toUpperCase() + type.substr(1) + 's';
@ -120,8 +120,9 @@ export function* search(data) {
if (match) { if (match) {
return formatResponse(match); return formatResponse(match);
} }
} catch (err) {
return {service: 'xbox'}; return {service: 'xbox'};
}
}; };
function exactMatch(item, artist, haystack, type) { function exactMatch(item, artist, haystack, type) {
@ -136,7 +137,6 @@ function exactMatch(item, artist, haystack, type) {
function looseMatch(item, artist, haystack, type) { function looseMatch(item, artist, haystack, type) {
// try to find exact match // try to find exact match
return haystack.find(function(entry) { return haystack.find(function(entry) {
console.log(entry.Name, entry.Artists[0].Artist.Name)
if (entry.Name.indexOf(item) >= 0 && entry.Artists[0].Artist.Name.indexOf(artist) >= 0) { if (entry.Name.indexOf(item) >= 0 && entry.Artists[0].Artist.Name.indexOf(artist) >= 0) {
return entry; return entry;
} }

View file

@ -2,7 +2,7 @@ import { parse } from 'url';
export function* match(url, type) { export function* match(url, type) {
const parsed = parse(url); const parsed = parse(url);
if (!parsed.host.match(/music.xbox.com$/)) { if (!parsed.host.match(/music.microsoft.com$/)) {
return false; return false;
} }

View file

@ -9,7 +9,7 @@ const debug = debuglog('match.audio:share');
export function find(music) { export function find(music) {
return models[music.type].findOne({ return models[music.type].findOne({
where: { where: {
externalId: music.id, externalId: music.id.toString(),
}, },
include: [ include: [
{ model: models.artist }, { model: models.artist },
@ -20,7 +20,7 @@ export function find(music) {
export function create(music) { export function create(music) {
return models[music.type].create({ return models[music.type].create({
externalId: music.id, externalId: music.id.toString(),
service: music.service, service: music.service,
name: music.name, name: music.name,
albumName: music.type === 'track' ? music.album.name : null, albumName: music.type === 'track' ? music.album.name : null,
@ -31,7 +31,7 @@ export function create(music) {
}, },
matches: [ matches: [
{ {
externalId: music.id, externalId: music.id.toString(),
service: music.service, service: music.service,
name: music.name, name: music.name,
streamUrl: music.streamUrl, streamUrl: music.streamUrl,
@ -62,7 +62,7 @@ export function findMatchesAsync(share) {
models.match.create({ models.match.create({
trackId: share.$modelOptions.name.singular == 'track' ? share.id : null, trackId: share.$modelOptions.name.singular == 'track' ? share.id : null,
albumId: share.$modelOptions.name.singular == 'album' ? share.id : null, albumId: share.$modelOptions.name.singular == 'album' ? share.id : null,
externalId: match.id, externalId: match.id.toString(),
service: match.service, service: match.service,
name: match.name, name: match.name,
streamUrl: match.streamUrl, streamUrl: match.streamUrl,

View file

@ -9,6 +9,7 @@ const debug = debugname('match.audio:models');
const config = { const config = {
dialect: 'postgres', dialect: 'postgres',
protocol: 'postgres', protocol: 'postgres',
quoteIdentifiers: true,
logging: debug, logging: debug,
}; };

View file

@ -39,6 +39,8 @@ export default function* () {
share: false, share: false,
}; };
this.set('Cache-Control', 'no-cache');
yield this.render('index', { yield this.render('index', {
initialState, initialState,
head, head,