Skip to content

Commit

Permalink
Ко всем get-запросам из SpotifyRequest добавляется локаль
Browse files Browse the repository at this point in the history
  • Loading branch information
Chimildic committed Jul 18, 2021
1 parent 9fe3c17 commit 1337850
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ const RecentTracks = (function () {
}

function getSpotifyRecentTracks() {
let url = `${API_BASE_URL}/me/player/recently-played?limit=50&locale=${KeyValue.LOCALE || "RU"}`;
let url = `${API_BASE_URL}/me/player/recently-played?limit=50`;
return Source.extractTracks(SpotifyRequest.get(url).items);
}

Expand Down Expand Up @@ -1669,7 +1669,7 @@ const Playlist = (function () {
const LIMIT_TRACKS = 11000;
const LIMIT_DESCRIPTION = 300;
const SIZE = ['500', '600', '700', '800', '900', '1000'];
const ARGS = `?limit=50&locale=${KeyValue.LOCALE || "RU"}`;
const ARGS = `?limit=50`;

const getPlaylistArray = (function () {
let playlistsOfUsers = {};
Expand Down Expand Up @@ -2666,7 +2666,7 @@ const Search = (function () {
method: 'post',
payload: { 'entry.802476445': data.item.artist ? data.item.artist['#text'] : data.keyword }
}
if (data.type == 'track') {
if (data.type == 'track') {
request.payload['entry.2097460120'] = data.item.name ? data.item.name : data.keyword;
request.payload['entry.840314673'] = data.item.album ? data.item.album['#text'] : '';
}
Expand Down Expand Up @@ -3063,21 +3063,25 @@ const SpotifyRequest = (function () {
}

function get(url) {
return extractContent(fetch(url));
return extractContent(fetch(appendLocale(url)));
}

function getAll(urls) {
let requests = [];
urls.forEach((url) =>
urls.forEach((url) => {
requests.push({
url: url,
url: appendLocale(url),
headers: getHeaders(),
method: 'get',
})
);
});
});
return CustomUrlFetchApp.fetchAll(requests).map((response) => extractContent(response));
}

function appendLocale(url) {
return url + `${url.includes('?') ? '&' : '?'}locale=${KeyValue.LOCALE || "RU"}`;
}

function extractContent(response) {
if (!response) return;
let keys = Object.keys(response);
Expand Down

0 comments on commit 1337850

Please sign in to comment.