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

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;
}