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);
});
app.use(errorHandler());
app.use(errorHandler(raven));
app.use(bodyparser());
app.use(cors());

View file

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

View file

@ -68,12 +68,12 @@ export function* parseUrl(url) {
const parsed = parse(url);
const parts = parsed.path.split('/');
const type = parts[1];
const idMatches = parts[4].match(/[\w\-]+/);
const id = idMatches[0];
const idMatches = parts[4].match(/bz.[\w\-]+/);
const id = idMatches[0].replace('bz.', 'music.');
if (!id) {
return false;
}
return yield lookupId('music.' + id, type);
return yield lookupId(id, type);
}
export function* lookupId(id, type) {
@ -106,22 +106,23 @@ export function* search(data) {
}
const name = data.name;
const path = '/music/search?q=' + encodeURIComponent(query.trim()) + '&filters=' + type + 's';
try {
const result = yield apiCall(path);
const path = '/music/search?q=' + encodeURIComponent(query) + '&filters=' + type + 's';
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';
let match = exactMatch(name, data.artist.name, result.body[apiType].Items, type);
if (!match) {
match = looseMatch(name, data.artist.name, result.body[apiType].Items, type);
}
let match = exactMatch(name, data.artist.name, result.body[apiType].Items, type);
if (!match) {
match = looseMatch(name, data.artist.name, result.body[apiType].Items, type);
if (match) {
return formatResponse(match);
}
} catch (err) {
return {service: 'xbox'};
}
if (match) {
return formatResponse(match);
}
return {service: 'xbox'};
};
function exactMatch(item, artist, haystack, type) {
@ -136,7 +137,6 @@ function exactMatch(item, artist, haystack, type) {
function looseMatch(item, artist, haystack, type) {
// try to find exact match
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) {
return entry;
}

View file

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

View file

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

View file

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

View file

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