Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/actions/musicSearch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
'use strict';
const request = require('request-promise');
const fs = require("fs");
const isRadioOrLineIn = require('../helpers/is-radio-or-line-in');

function httpGet({ url, json, headers }) {
return fetch(url, { headers }).then((res) => {
if (!res.ok) {
return Promise.reject(new Error(`HTTP ${res.status} ${res.statusText} for ${url}`));
}
return json ? res.json() : res.text();
});
}

const appleDef = require('../music_services/appleDef');
const spotifyDef = require('../music_services/spotifyDef');
const deezerDef = require('../music_services/deezerDef');
Expand Down Expand Up @@ -41,7 +49,7 @@ function getAccountId(player, service)
accountId = '';

if (service != 'library') {
return request({url: player.baseUrl + '/status/accounts',json: false})
return httpGet({url: player.baseUrl + '/status/accounts',json: false})
.then((res) => {
var actLoc = res.indexOf(player.system.getServiceType(serviceNames[service]));

Expand Down Expand Up @@ -118,19 +126,19 @@ function doSearch(service, type, term)
return Promise.resolve(libraryDef.searchlib(type, newTerm));
} else
if ((serviceDef.country != '') && (country == '')) {
return request({url: 'http://ipinfo.io',
return httpGet({url: 'http://ipinfo.io',
json: true})
.then((res) => {
country = res.country;
url += serviceDef.country + country;
return authenticate().then(() => request(getRequestOptions(serviceDef, url)));
return authenticate().then(() => httpGet(getRequestOptions(serviceDef, url)));
});
} else {
if (serviceDef.country != '') {
url += serviceDef.country + country;
}
return authenticate().then(() => request(getRequestOptions(serviceDef, url)));

return authenticate().then(() => httpGet(getRequestOptions(serviceDef, url)));
}
}

Expand Down