diff --git a/README.md b/README.md index 0000515..b4f60a7 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,140 @@ # Deezer Public API wrapper -This is *Nodejs* wrapper for the [Deezer Public API](http://developers.deezer.com/api) that return promises. +This is **[Node.js](https://nodejs.org/en/download/)** wrapper for the [Deezer Public API](http://developers.deezer.com/api) that return promises. + +This is forked from https://github.com/zaosoula/deezer-public-api, but it has modifications and uses a much faster HTTP library, giving you the most immediate results. ## Installation - npm install deezer-public-api --save + + npm install @muhimur/deezer-public-api ## Usage example ```js -const DeezerPublicApi = require('deezer-public-api'); -let deezer = new DeezerPublicApi(); - -//Search an artist -deezer.search.artist('ILYSH').then(function(result) { - console.log(result); -}); - -//Get info for the given artist id -deezer.artist('58671252').then(function(result) { - console.log(result); -}); - -//Get album list for the given artist id -deezer.artist.albums('58671252').then(function(result) { - console.log(result); -}); +const DeezerPublicApi = require("@muhimur/deezer-public-api"); +const deezer = new DeezerPublicApi(); + +// Search a track +deezer.track("493894782").then(result => console.log(result)); + +// Search an artist +deezer.search.artist("ILYSH").then(result => console.log(result)); + +// Get info for the given artist id +deezer.artist("58671252").then(result => console.log(result)); + +// Get album list for the given artist id +deezer.artist.albums("58671252").then(result => console.log(result)); ``` + ## Available methods ##### Album -* album(`id`, `limit`, `index`) -* album.comments(`id`, `limit`, `index`) -* album.fans(`id`, `limit`, `index`) -* album.tracks(`id`, `limit`, `index`) + +- album(`id`, `limit`, `index`) +- album.comments(`id`, `limit`, `index`) +- album.fans(`id`, `limit`, `index`) +- album.tracks(`id`, `limit`, `index`) ##### Artist -* artist(`id`, `limit`, `index`) -* artist.top(`id`, `limit`, `index`) -* artist.albums(`id`, `limit`, `index`) -* artist.comments(`id`, `limit`, `index`) -* artist.fans(`id`, `limit`, `index`) -* artist.related(`id`, `limit`, `index`) -* artist.radio(`id`, `limit`, `index`) -* artist.playlists(`id`, `limit`, `index`) + +- artist(`id`, `limit`, `index`) +- artist.top(`id`, `limit`, `index`) +- artist.albums(`id`, `limit`, `index`) +- artist.comments(`id`, `limit`, `index`) +- artist.fans(`id`, `limit`, `index`) +- artist.related(`id`, `limit`, `index`) +- artist.radio(`id`, `limit`, `index`) +- artist.playlists(`id`, `limit`, `index`) ##### Chart -* chart(`limit`, `index`) -* chart.tracks(`limit`, `index`) -* chart.albums(`limit`, `index`) -* chart.artists(`limit`, `index`) -* chart.playlists(`limit`, `index`) -* chart.podcasts(`limit`, `index`) + +- chart(`limit`, `index`) +- chart.tracks(`limit`, `index`) +- chart.albums(`limit`, `index`) +- chart.artists(`limit`, `index`) +- chart.playlists(`limit`, `index`) +- chart.podcasts(`limit`, `index`) ##### Comment -* comment(`id`, `limit`, `index`) + +- comment(`id`, `limit`, `index`) ##### Editorial -* editorial(`id`, `limit`, `index`) -* editorial.selection(`id`, `limit`, `index`) -* editorial.charts(`id`, `limit`, `index`) -* editorial.releases(`id`, `limit`, `index`) + +- editorial(`id`, `limit`, `index`) +- editorial.selection(`id`, `limit`, `index`) +- editorial.charts(`id`, `limit`, `index`) +- editorial.releases(`id`, `limit`, `index`) ##### Episode -* episode(`id`, `limit`, `index`) + +- episode(`id`, `limit`, `index`) ##### Genre -* genre(`id`, `limit`, `index`) -* genre.artists(`id`, `limit`, `index`) -* genre.podcasts(`id`, `limit`, `index`) -* genre.radios(`id`, `limit`, `index`) + +- genre(`id`, `limit`, `index`) +- genre.artists(`id`, `limit`, `index`) +- genre.podcasts(`id`, `limit`, `index`) +- genre.radios(`id`, `limit`, `index`) ##### Infos -* infos() + +- infos() ##### Options -* options() + +- options() ##### Playlist -* playlist(`id`, `limit`, `index`) -* playlist.comments(`id`, `limit`, `index`) -* playlist.fans(`id`, `limit`, `index`) -* playlist.tracks(`id`, `limit`, `index`) -* playlist.radio(`id`, `limit`, `index`) + +- playlist(`id`, `limit`, `index`) +- playlist.comments(`id`, `limit`, `index`) +- playlist.fans(`id`, `limit`, `index`) +- playlist.tracks(`id`, `limit`, `index`) +- playlist.radio(`id`, `limit`, `index`) ##### Podcast -* podcast(`id`, `limit`, `index`) -* podcast.episodes(`id`, `limit`, `index`) + +- podcast(`id`, `limit`, `index`) +- podcast.episodes(`id`, `limit`, `index`) ##### Radio -* radio(`id`, `limit`, `index`) -* radio.genres(`limit`, `index`) -* radio.top(`limit`, `index`) -* radio.lists(`limit`, `index`) -* radio.tracks(`id`, `limit`, `index`) + +- radio(`id`, `limit`, `index`) +- radio.genres(`limit`, `index`) +- radio.top(`limit`, `index`) +- radio.lists(`limit`, `index`) +- radio.tracks(`id`, `limit`, `index`) ##### Track -* track(`id`, `limit`, `index`) + +- track(`id`, `limit`, `index`) ##### User -* user(`id`, `limit`, `index`) -* user.albums(`id`, `limit`, `index`) -* user.artists(`id`, `limit`, `index`) -* user.charts(`id`, `limit`, `index`) -* user.charts.tracks(`id`, `limit`, `index`) -* user.charts.albums(`id`, `limit`, `index`) -* user.charts.playlists(`id`, `limit`, `index`) -* user.charts.artists(`id`, `limit`, `index`) -* user.flow(`id`, `limit`, `index`) -* user.followings(`id`, `limit`, `index`) -* user.followers(`id`, `limit`, `index`) -* user.playlists(`id`, `limit`, `index`) -* user.podcasts(`id`, `limit`, `index`) -* user.radios(`id`, `limit`, `index`) -* user.tracks(`id`, `limit`, `index`) + +- user(`id`, `limit`, `index`) +- user.albums(`id`, `limit`, `index`) +- user.artists(`id`, `limit`, `index`) +- user.charts(`id`, `limit`, `index`) +- user.charts.tracks(`id`, `limit`, `index`) +- user.charts.albums(`id`, `limit`, `index`) +- user.charts.playlists(`id`, `limit`, `index`) +- user.charts.artists(`id`, `limit`, `index`) +- user.flow(`id`, `limit`, `index`) +- user.followings(`id`, `limit`, `index`) +- user.followers(`id`, `limit`, `index`) +- user.playlists(`id`, `limit`, `index`) +- user.podcasts(`id`, `limit`, `index`) +- user.radios(`id`, `limit`, `index`) +- user.tracks(`id`, `limit`, `index`) ##### Search -* search(`options`, `order`, `limit`, `index`) -* search.artist(`query`, `order`, `limit`, `index`, `strict`) -* search.playlist(`query`, `order`, `limit`, `index`, `strict`) -* search.podcast(`query`, `order`, `limit`, `index`, `strict`) -* search.radio(`query`, `order`, `limit`, `index`, `strict`) -* search.track(`query`, `order`, `limit`, `index`, `strict`) -* search.user(`query`, `order`, `limit`, `index`, `strict`) + +- search(`options`, `order`, `limit`, `index`) +- search.artist(`query`, `order`, `limit`, `index`, `strict`) +- search.playlist(`query`, `order`, `limit`, `index`, `strict`) +- search.podcast(`query`, `order`, `limit`, `index`, `strict`) +- search.radio(`query`, `order`, `limit`, `index`, `strict`) +- search.track(`query`, `order`, `limit`, `index`, `strict`) +- search.user(`query`, `order`, `limit`, `index`, `strict`) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index b02813c..9b581a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { - "name": "deezer-public-api", - "version": "1.0.4", + "name": "@muhimur/deezer-public-api", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { - "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + "petitio": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/petitio/-/petitio-1.3.2.tgz", + "integrity": "sha512-hbbT+rOvovz39ZneGW+C8B4YsKH20KLXYVDT/IzSUxaY8H7al/TO+vFCm+H5cnYe62gIqF9ak5p8OJktV/I0Ig==" } } } diff --git a/package.json b/package.json index 41fc1a3..1c5d926 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "deezer-public-api", - "version": "1.0.4", - "description": "This is Nodejs wrapper for the Deezer Public API that return promises.", + "name": "@muhimur/deezer-public-api", + "version": "1.0.23", + "description": "This is Nodejs wrapper for the Deezer Public API that return promises. Forked from deezer-public-api with a faster response time.", "keywords": [ "deezer-api", "deezer", @@ -19,15 +19,15 @@ "test": "node test/index.js" }, "dependencies": { - "node-fetch": "2.6.1" + "petitio": "^1.3.2" }, "devDependencies": {}, "repository": { "type": "git", - "url": "https://github.com/zaosoula/deezer-public-api.git" + "url": "git+https://github.com/muhimur9049/deezer-public-api.git" }, "bugs": { - "url": "https://github.com/zaosoula/deezer-public-api/issues" + "url": "https://github.com/muhimur9049/deezer-public-api/issues" }, - "homepage": "https://github.com/zaosoula/deezer-public-api" + "homepage": "https://github.com/muhimur9049/deezer-public-api" } diff --git a/src/index.js b/src/index.js index 3eb959c..c9ac476 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -const fetch = require('node-fetch'); -const apiUrl = 'https://api.deezer.com/' +const fetch = require("petitio"); +const apiUrl = "https://api.deezer.com/"; function DeezerPublicApi() { this.apiUrl = apiUrl; @@ -8,333 +8,333 @@ function DeezerPublicApi() { /* * ALBUM */ -DeezerPublicApi.prototype.album = function(id, limit, index) { - var url = 'album/' + id; +DeezerPublicApi.prototype.album = function (id, limit, index) { + let url = `album/${id}`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.album.comments = function(id, limit, index) { - var url = 'album/' + id + '/comments'; +DeezerPublicApi.prototype.album.comments = function (id, limit, index) { + let url = `album/${id}/comments`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.album.fans = function(id, limit, index) { - var url = 'album/' + id + '/fans'; +DeezerPublicApi.prototype.album.fans = function (id, limit, index) { + let url = `album/${id}/fans`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.album.tracks = function(id, limit, index) { - var url = 'album/' + id + '/tracks'; +DeezerPublicApi.prototype.album.tracks = function (id, limit, index) { + let url = `album/${id}/tracks`; return rq(url, index, limit); }; /* * ARTIST */ -DeezerPublicApi.prototype.artist = function(id, limit, index) { - var url = 'artist/' + id; +DeezerPublicApi.prototype.artist = function (id, limit, index) { + let url = `artist/${id}`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.top = function(id, limit, index) { - var url = 'artist/' + id + '/top'; +DeezerPublicApi.prototype.artist.top = function (id, limit, index) { + let url = `artist/${id}/top`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.albums = function(id, limit, index) { - var url = 'artist/' + id + '/albums'; +DeezerPublicApi.prototype.artist.albums = function (id, limit, index) { + let url = `artist/${id}/albums`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.comments = function(id, limit, index) { - var url = 'artist/' + id + '/comments'; +DeezerPublicApi.prototype.artist.comments = function (id, limit, index) { + let url = `artist/${id}/comments`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.fans = function(id, limit, index) { - var url = 'artist/' + id + '/fans'; +DeezerPublicApi.prototype.artist.fans = function (id, limit, index) { + let url = `artist/${id}/fans`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.related = function(id, limit, index) { - var url = 'artist/' + id + '/related'; +DeezerPublicApi.prototype.artist.related = function (id, limit, index) { + let url = `artist/${id}/related`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.radio = function(id, limit, index) { - var url = 'artist/' + id + '/radio'; +DeezerPublicApi.prototype.artist.radio = function (id, limit, index) { + let url = `artist/${id}/radio`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.artist.playlists = function(id, limit, index) { - var url = 'artist/' + id + '/playlists'; +DeezerPublicApi.prototype.artist.playlists = function (id, limit, index) { + let url = `artist/${id}/playlists`; return rq(url, index, limit); }; /* * CHART */ -DeezerPublicApi.prototype.chart = function(limit, index) { - var url = 'chart/'; +DeezerPublicApi.prototype.chart = function (limit, index) { + let url = "chart/"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.chart.tracks = function(limit, index) { - var url = 'chart/0/tracks'; +DeezerPublicApi.prototype.chart.tracks = function (limit, index) { + let url = "chart/0/tracks"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.chart.albums = function(limit, index) { - var url = 'chart/0/albums'; +DeezerPublicApi.prototype.chart.albums = function (limit, index) { + let url = "chart/0/albums"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.chart.artists = function(limit, index) { - var url = 'chart/0/artists'; +DeezerPublicApi.prototype.chart.artists = function (limit, index) { + let url = "chart/0/artists"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.chart.playlists = function(limit, index) { - var url = 'chart/0/playlists'; +DeezerPublicApi.prototype.chart.playlists = function (limit, index) { + let url = "chart/0/playlists"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.chart.podcasts = function(limit, index) { - var url = 'chart/0/podcasts'; +DeezerPublicApi.prototype.chart.podcasts = function (limit, index) { + let url = "chart/0/podcasts"; return rq(url, index, limit); }; /* * COMMENT */ -DeezerPublicApi.prototype.comment = function(id, limit, index) { - var url = 'comment/' + id; +DeezerPublicApi.prototype.comment = function (id, limit, index) { + let url = `comment/${id}`; return rq(url, index, limit); }; /* * EDITORIAL */ -DeezerPublicApi.prototype.editorial = function(id, limit, index) { - var url = 'editorial/' + ((id) ? id : ''); +DeezerPublicApi.prototype.editorial = function (id, limit, index) { + let url = "editorial/" + ((id) ? id : ""); return rq(url, index, limit); }; -DeezerPublicApi.prototype.editorial.selection = function(id, date, limit, index) { - var url = 'editorial/' + id + '/selection'; - if (date) url = url + '&date=' + date; +DeezerPublicApi.prototype.editorial.selection = function (id, date, limit, index) { + let url = `editorial/${id}/selection`; + if (date) url = url + "&date=" + date; return rq(url, index, limit); }; -DeezerPublicApi.prototype.editorial.charts = function(id, limit, index) { - var url = 'editorial/' + id + '/charts'; +DeezerPublicApi.prototype.editorial.charts = function (id, limit, index) { + let url = `editorial/${id}/charts`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.editorial.releases = function(id, limit, index) { - var url = 'editorial/' + id + '/releases'; +DeezerPublicApi.prototype.editorial.releases = function (id, limit, index) { + let url = `editorial/${id}/releases`; return rq(url, index, limit); }; /* * EPISODE */ -DeezerPublicApi.prototype.episode = function(id, limit, index) { - var url = 'episode/' + id; +DeezerPublicApi.prototype.episode = function (id, limit, index) { + let url = `episode/${id}`; return rq(url, index, limit); }; /* * GENRE */ -DeezerPublicApi.prototype.genre = function(id, limit, index) { - var url = 'genre/' + ((id) ? id : ''); +DeezerPublicApi.prototype.genre = function (id, limit, index) { + let url = "genre/" + ((id) ? id : ""); return rq(url, index, limit); }; -DeezerPublicApi.prototype.genre.artists = function(id, limit, index) { - var url = 'genre/' + id + '/artists'; +DeezerPublicApi.prototype.genre.artists = function (id, limit, index) { + let url = `genre/${id}/artists`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.genre.podcasts = function(id, limit, index) { - var url = 'genre/' + id + '/podcasts'; +DeezerPublicApi.prototype.genre.podcasts = function (id, limit, index) { + let url = `genre/${id}/podcasts`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.genre.radios = function(id, limit, index) { - var url = 'genre/' + id + '/radios'; +DeezerPublicApi.prototype.genre.radios = function (id, limit, index) { + let url = `genre/${id}/radios`; return rq(url, index, limit); }; /* * INFOS */ -DeezerPublicApi.prototype.infos = function() { - var url = 'infos'; +DeezerPublicApi.prototype.infos = function () { + let url = "infos"; return rq(url); }; /* * OPTIONS */ -DeezerPublicApi.prototype.options = function() { - var url = 'options'; +DeezerPublicApi.prototype.options = function () { + let url = "options"; return rq(url); }; /* * PLAYLIST */ -DeezerPublicApi.prototype.playlist = function(id, limit, index) { - var url = 'playlist/' + id; +DeezerPublicApi.prototype.playlist = function (id, limit, index) { + let url = `playlist/${id}`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.playlist.comments = function(id, limit, index) { - var url = 'playlist/' + id + '/comments'; +DeezerPublicApi.prototype.playlist.comments = function (id, limit, index) { + let url = `playlist/${id}/comments`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.playlist.fans = function(id, limit, index) { - var url = 'playlist/' + id + '/fans'; +DeezerPublicApi.prototype.playlist.fans = function (id, limit, index) { + let url = "playlist/" + id + "/fans"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.playlist.tracks = function(id, limit, index) { - var url = 'playlist/' + id + '/tracks'; +DeezerPublicApi.prototype.playlist.tracks = function (id, limit, index) { + let url = `playlist/${id}/tracks`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.playlist.radio = function(id, limit, index) { - var url = 'playlist/' + id + '/radio'; +DeezerPublicApi.prototype.playlist.radio = function (id, limit, index) { + let url = `playlist/${id}/radio`; return rq(url, index, limit); }; /* * PODCAST */ -DeezerPublicApi.prototype.podcast = function(id, limit, index) { - var url = 'podcast/' + ((id) ? id : ''); +DeezerPublicApi.prototype.podcast = function (id, limit, index) { + let url = "podcast/" + ((id) ? id : ""); return rq(url, index, limit); }; -DeezerPublicApi.prototype.podcast.episodes = function(id, limit, index) { - var url = 'podcast/' + id + '/episodes'; +DeezerPublicApi.prototype.podcast.episodes = function (id, limit, index) { + let url = "podcast/" + id + "/episodes"; return rq(url, index, limit); }; /* * RADIO */ -DeezerPublicApi.prototype.radio = function(id, limit, index) { - var url = 'radio/' + ((id) ? id : ''); +DeezerPublicApi.prototype.radio = function (id, limit, index) { + let url = "radio/" + ((id) ? id : ""); return rq(url, index, limit); }; -DeezerPublicApi.prototype.radio.genres = function(limit, index) { - var url = 'radio/genres'; +DeezerPublicApi.prototype.radio.genres = function (limit, index) { + let url = "radio/genres"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.radio.top = function(limit, index) { - var url = 'radio/top'; +DeezerPublicApi.prototype.radio.top = function (limit, index) { + let url = "radio/top"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.radio.lists = function(limit, index) { - var url = 'radio/lists'; +DeezerPublicApi.prototype.radio.lists = function (limit, index) { + let url = "radio/lists"; return rq(url, index, limit); }; -DeezerPublicApi.prototype.radio.tracks = function(id, limit, index) { - var url = 'radio/' + id + '/tracks'; +DeezerPublicApi.prototype.radio.tracks = function (id, limit, index) { + let url = `radio/${id}/tracks`; return rq(url, index, limit); }; /* * TRACK */ -DeezerPublicApi.prototype.track = function(id, limit, index) { - var url = 'track/' + id; +DeezerPublicApi.prototype.track = function (id, limit, index) { + let url = `track/${id}`; return rq(url, index, limit); }; /* * USER */ -DeezerPublicApi.prototype.user = function(id, limit, index) { - var url = 'user/' + id; +DeezerPublicApi.prototype.user = function (id, limit, index) { + let url = `user/${id}`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.albums = function(id, limit, index) { - var url = 'user/' + id + '/albums'; +DeezerPublicApi.prototype.user.albums = function (id, limit, index) { + let url = `user/${id}/albums` return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.artists = function(id, limit, index) { - var url = 'user/' + id + '/artists'; +DeezerPublicApi.prototype.user.artists = function (id, limit, index) { + let url = `user/${id}/artists`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.charts = function(id, limit, index) { - var url = 'user/' + id + '/charts'; +DeezerPublicApi.prototype.user.charts = function (id, limit, index) { + let url = `user/${id}/charts`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.charts.tracks = function(id, limit, index) { - var url = 'user/' + id + '/charts/tracks'; +DeezerPublicApi.prototype.user.charts.tracks = function (id, limit, index) { + let url = `user/${id}/charts/tracks`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.charts.albums = function(id, limit, index) { - var url = 'user/' + id + '/charts/albums'; +DeezerPublicApi.prototype.user.charts.albums = function (id, limit, index) { + let url = `user/${id}/charts/albums`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.charts.playlists = function(id, limit, index) { - var url = 'user/' + id + '/charts/playlists'; +DeezerPublicApi.prototype.user.charts.playlists = function (id, limit, index) { + let url = `user/${id}/charts/playlists`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.charts.artists = function(id, limit, index) { - var url = 'user/' + id + '/charts/artists'; +DeezerPublicApi.prototype.user.charts.artists = function (id, limit, index) { + let url = `user/${id}/charts/artists`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.flow = function(id, limit, index) { - var url = 'user/' + id + '/flow'; +DeezerPublicApi.prototype.user.flow = function (id, limit, index) { + let url = `user/${id}/flow`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.followings = function(id, limit, index) { - var url = 'user/' + id + '/followings'; +DeezerPublicApi.prototype.user.followings = function (id, limit, index) { + let url = `user/${id}/followings`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.followers = function(id, limit, index) { - var url = 'user/' + id + '/followers'; +DeezerPublicApi.prototype.user.followers = function (id, limit, index) { + let url = `user/${id}/followers`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.playlists = function(id, limit, index) { - var url = 'user/' + id + '/playlists'; +DeezerPublicApi.prototype.user.playlists = function (id, limit, index) { + let url = `user/${id}/playlists`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.podcasts = function(id, limit, index) { - var url = 'user/' + id + '/podcasts'; +DeezerPublicApi.prototype.user.podcasts = function (id, limit, index) { + let url = `user/${id}/podcasts`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.radios = function(id, limit, index) { - var url = 'user/' + id + '/radios'; +DeezerPublicApi.prototype.user.radios = function (id, limit, index) { + let url = `user/${id}/radios`; return rq(url, index, limit); }; -DeezerPublicApi.prototype.user.tracks = function(id, limit, index) { - var url = 'user/' + id + '/tracks'; +DeezerPublicApi.prototype.user.tracks = function (id, limit, index) { + let url = `user/${id}/tracks`; return rq(url, index, limit); }; @@ -343,12 +343,12 @@ DeezerPublicApi.prototype.user.tracks = function(id, limit, index) { /* * SEARCH */ -DeezerPublicApi.prototype.search = function(options, order, limit, index) { - var url = 'search?q='; - var query = ''; - if (typeof options === 'object') { - for (var key in options) { - query = query + key + ':"' + options[key] + '" '; +DeezerPublicApi.prototype.search = function (options, order, limit, index) { + let url = "search?q="; + let query = ""; + if (typeof options === "object") { + for (let key in options) { + query = query + key + ":'" + options[key] + '" '; } } else { query = options; @@ -358,52 +358,49 @@ DeezerPublicApi.prototype.search = function(options, order, limit, index) { return rq(url, index, limit, order); }; -DeezerPublicApi.prototype.search.artist = function(query, order, limit, index, strict) { - var url = 'search/artist?q=' + query; +DeezerPublicApi.prototype.search.artist = function (query, order, limit, index, strict) { + let url = "search/artist?q=" + query; return rq(url, index, limit, order, strict); }; -DeezerPublicApi.prototype.search.playlist = function(query, order, limit, index, strict) { - var url = 'search/playlist?q=' + query; +DeezerPublicApi.prototype.search.playlist = function (query, order, limit, index, strict) { + let url = "search/playlist?q=" + query; return rq(url, index, limit, order, strict); }; -DeezerPublicApi.prototype.search.podcast = function(query, order, limit, index, strict) { - var url = 'search/podcast?q=' + query; +DeezerPublicApi.prototype.search.podcast = function (query, order, limit, index, strict) { + let url = "search/podcast?q=" + query; return rq(url, index, limit, order, strict); }; -DeezerPublicApi.prototype.search.radio = function(query, order, limit, index, strict) { - var url = 'search/radio?q=' + query; +DeezerPublicApi.prototype.search.radio = function (query, order, limit, index, strict) { + let url = "search/radio?q=" + query; return rq(url, index, limit, order, strict); }; -DeezerPublicApi.prototype.search.track = function(query, order, limit, index, strict) { - var url = 'search/track?q=' + query; +DeezerPublicApi.prototype.search.track = function (query, order, limit, index, strict) { + let url = "search/track?q=" + query; return rq(url, index, limit, order, strict); }; -DeezerPublicApi.prototype.search.user = function(query, order, limit, index, strict) { - var url = 'search/user?q=' + query; +DeezerPublicApi.prototype.search.user = function (query, order, limit, index, strict) { + let url = "search/user?q=" + query; return rq(url, index, limit, order, strict); }; function rq(url, index, limit, order, strict) { - return new Promise((resolve, reject)=>{ - if (!url.includes("?")) url = url + '?'; - if (index && index !== 0) url = url + '&index=' + index; - if (limit && limit !== 0) url = url + '&limit=' + limit; - if (order) url = url + '&order=' + order; - if (strict) url = url + '&strict=on'; - if (url.endsWith('?')) url = url.slice(0, -1); - fetch(apiUrl + url, { - json: true - }).then(res => res.json()) + return new Promise((resolve, reject) => { + if (!url.includes("?")) url = url + "?"; + if (index && index !== 0) url = url + "&index=" + index; + if (limit && limit !== 0) url = url + "&limit=" + limit; + if (order) url = url + "&order=" + order; + if (strict) url = url + "&strict=on"; + if (url.endsWith("?")) url = url.slice(0, -1); + fetch(apiUrl + url).json() .then(json => { resolve(json) - // console.log(json) }).catch((err) => reject(err)); }); } -module.exports = DeezerPublicApi; +module.exports = DeezerPublicApi; \ No newline at end of file diff --git a/test/index.js b/test/index.js index 50fca04..c468ef7 100644 --- a/test/index.js +++ b/test/index.js @@ -1,9 +1,9 @@ -const DeezerPublicApi = require('..'); +const DeezerPublicApi = require(''); let deezer = new DeezerPublicApi(); let artistName = 'ILYSH'; -deezer.search.artist(artistName).then((artists)=>{ +deezer.search.artist(artistName).then((artists) => { - let artist = artists.data.find((artist)=> { + let artist = artists.data.find((artist) => { console.log(artist.name); return artist.name == artistName }); @@ -11,15 +11,15 @@ deezer.search.artist(artistName).then((artists)=>{ console.log(artist); return deezer.artist.albums(artist.id, 1000); -}).then((result)=>{ +}).then((result) => { - result.data.map((i)=>{ + result.data.map((i) => { console.log(i); }) return deezer.album(result.data[0].id) -}).then((album)=>{ - if(album.error){ +}).then((album) => { + if (album.error) { console.log(album.error); return; } @@ -42,19 +42,19 @@ deezer.search.artist(artistName).then((artists)=>{ name: album.artist.name, picture: album.artist.picture_xl, }, - contributors: album.contributors.map((e)=>{ + contributors: album.contributors.map((e) => { return { name: e.name, picture: e.picture_xl, } }), - genres: album.genres.data.map((o)=>{ + genres: album.genres.data.map((o) => { return { id: o.id, name: o.name } }), - tracks: album.tracks.data.map((o)=>{ + tracks: album.tracks.data.map((o) => { return { title: o.title, titleShort: o.title_short, @@ -67,6 +67,6 @@ deezer.search.artist(artistName).then((artists)=>{ console.log(albumData); -}).catch((err)=>{ +}).catch((err) => { console.log("has an error:", err); })