Skip to content

Commit

Permalink
fix ximi playlist only return 30 songs bug
Browse files Browse the repository at this point in the history
  • Loading branch information
listen1 committed Oct 31, 2020
1 parent 6692fff commit 4614d1b
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions src/api/provider/xiami.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class MyStorage {

return null;
};
static getData = async key => {
static getData = async (key) => {
try {
return await AsyncStorage.getItem(key);
} catch (error) {
// console.log(error);
return null;
}
};
static deleteData = async key => {
static deleteData = async (key) => {
try {
return await AsyncStorage.removeItem(key);
} catch (error) {
Expand Down Expand Up @@ -132,9 +132,7 @@ async function requestAPI(api, params) {

const response = await fetch(url, {
headers: {
cookie: `xm_sg_tk=${token.xm_sg_tk}; xm_sg_tk.sig=${
token['xm_sg_tk.sig']
}`,
cookie: `xm_sg_tk=${token.xm_sg_tk}; xm_sg_tk.sig=${token['xm_sg_tk.sig']}`,
},
});

Expand Down Expand Up @@ -194,8 +192,8 @@ function showPlaylist(offset) {
dataType: 'system',
};

return requestAPI(api, params).then(data => {
const playlists = data.result.data.collects.map(d => {
return requestAPI(api, params).then((data) => {
const playlists = data.result.data.collects.map((d) => {
const playlist = {
cover_img_url: '',
title: '',
Expand All @@ -217,27 +215,31 @@ function showPlaylist(offset) {

function getPlaylist(playlistId) {
const listId = playlistId.split('_').pop();
const api = '/api/collect/initialize';
const api = '/api/collect/getCollectStaticUrl';
const params = {
listId: parseInt(listId, 10),
};

return requestAPI(api, params).then(data => {
const collect = data.result.data.collectDetail;
const info = {
cover_img_url: xmGetLowQualityImgUrl(collect.collectLogo),
title: collect.collectName,
id: `xmplaylist_${listId}`,
source_url: `http://www.xiami.com/collect/${listId}`,
};
const tracks = data.result.data.collectSongs.map(item =>
xmConvertSong2(item, 'artist_name')
);

return {
tracks,
info,
};
return requestAPI(api, params).then((response) => {
const collect_url = response.result.data.data.data.url;

return fetch(collect_url)
.then((response) => response.json())
.then((collect_response) => {
let data = collect_response;
const info = {
cover_img_url: xmGetLowQualityImgUrl(data.resultObj.collectLogo),
title: data.resultObj.collectName,
id: `xmplaylist_${listId}`,
source_url: `http://www.xiami.com/collect/${listId}`,
};
const tracks = data.resultObj.songs.map((item) => xmConvertSong2(item));

return {
tracks,
info,
};
});
});
}
function search(keyword, curpage) {
Expand All @@ -258,9 +260,9 @@ function search(keyword, curpage) {
referer: 'http://h.xiami.com/',
},
})
.then(response => response.json())
.then(response => {
const tracks = response.data.songs.map(item =>
.then((response) => response.json())
.then((response) => {
const tracks = response.data.songs.map((item) =>
xmConvertSong(item, 'artist_name')
);

Expand All @@ -285,9 +287,9 @@ function search2(keyword, curpage) {

// console.log(api, params);

return requestAPI(api, params).then(data => {
return requestAPI(api, params).then((data) => {
// console.log(data);
const tracks = data.result.data.songs.map(item =>
const tracks = data.result.data.songs.map((item) =>
xmConvertSong2(item, 'artistName')
);

Expand All @@ -308,8 +310,8 @@ function bootstrapTrack(trackId) {
Referer: 'https://www.xiami.com',
},
})
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
// console.log(data);
if (data.data.trackList == null) {
return '';
Expand Down

0 comments on commit 4614d1b

Please sign in to comment.