Skip to content

Commit

Permalink
Code simplification as per @FabianLauer 's comment on commit bb3ef3f
Browse files Browse the repository at this point in the history
  • Loading branch information
trekiteasy committed Jan 28, 2019
1 parent bb3ef3f commit 52b82c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions app/plugins/MusicSources/JamendoPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class JamendoPlugin extends MusicSourcePlugin {
this.description = 'Allows Nuclear to find music streams on Jamendo';
}

search(query) {
search (query) {
return this.getSearchResults(query).then(responseJson => {
if (responseJson.results.length > 0) {
let track = responseJson.results[0].tracks[0];

return {
source: this.sourceName,
id: track.id,
stream: track.audio,
duration: track.duration,
title: track.name,
thumbnail: track.image
};
} else {
if (responseJson.results.length === 0) {
return null;
}

let track = responseJson.results[0].tracks[0];

return {
source: this.sourceName,
id: track.id,
stream: track.audio,
duration: track.duration,
title: track.name,
thumbnail: track.image
};
});
}

getSearchResults(query) {
getSearchResults (query) {
return Jamendo.search(query)
.then(response => response.json())
.catch(err => {
Expand All @@ -40,7 +40,7 @@ class JamendoPlugin extends MusicSourcePlugin {
});
}

getAlternateStream(query, currentStream) {
getAlternateStream (query, currentStream) {
return this.getSearchResults(query).then(results => {
let info = _.find(results, result => result && result.id !== currentStream.id);
return info ? this.resultToStream(info) : null;
Expand Down
24 changes: 12 additions & 12 deletions app/rest/Jamendo.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import globals from '../globals';

export function search(query) {
let limit = 10;
let url = encodeURI(
export function search (query) {
const limit = 10;
const url = encodeURI(
'https://api.jamendo.com/v3.0/artists/tracks/' +
'?client_id=' +
globals.jamendoClientId +
'&format=jsonpretty' +
'&limit=' +
limit +
'&name=' +
query.artist +
'&track_name=' +
query.track
'?client_id=' +
globals.jamendoClientId +
'&format=jsonpretty' +
'&limit=' +
limit +
'&name=' +
query.artist +
'&track_name=' +
query.track
);

return fetch(url);
Expand Down

0 comments on commit 52b82c4

Please sign in to comment.