fix: spotify doesn't embed the payload anymore
This commit is contained in:
parent
96ac5a6f31
commit
c1ff3fe5a0
34
index.js
34
index.js
|
@ -15,18 +15,30 @@ require('dotenv').config();
|
|||
|
||||
|
||||
async function getSpotifyPlaylist(playListUrl){
|
||||
const spotifyPlaylistPageContent = await fetch(playListUrl)
|
||||
const spotifyPlaylistPageContent = await fetch(playListUrl, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
||||
}
|
||||
})
|
||||
.then(res => res.text())
|
||||
|
||||
const $ = Cheerio.load(spotifyPlaylistPageContent);
|
||||
|
||||
let playlist;
|
||||
$('script').each(function(i, elem){
|
||||
const content = $(this).html();
|
||||
if(/Spotify.Entity/.test(content)){
|
||||
playlist = vm.runInNewContext(content);
|
||||
}
|
||||
let config;
|
||||
$('script#config').each(function(i, elem){
|
||||
config = JSON.parse($(this).html());
|
||||
});
|
||||
debug('config=%O', config);
|
||||
|
||||
const playlistSpotifyId = /\/playlist\/([^\/]+)\/?$/.exec(playListUrl)[1];
|
||||
|
||||
const playlist = await fetch(`https://api.spotify.com/v1/playlists/${playlistSpotifyId}?type=track%2Cepisode`, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
|
||||
Authorization: `Bearer ${config.accessToken}`
|
||||
}
|
||||
}).then(res => res.json());
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
||||
|
@ -55,7 +67,7 @@ async function searchOnVkMusic(query){
|
|||
}
|
||||
|
||||
async function searchOnMyFreeMp3(query){
|
||||
const url = new URL('https://myfreemp3cc.com/api/search.php?callback=callback');
|
||||
const url = new URL('https://myfreemp3cc.com/api/search.php?callback=jQuery666');
|
||||
|
||||
return await fetch(url, {
|
||||
method: 'POST',
|
||||
|
@ -65,7 +77,11 @@ async function searchOnMyFreeMp3(query){
|
|||
}),
|
||||
})
|
||||
.then(res => res.text())
|
||||
.then(jsonp => vm.runInNewContext(jsonp, { callback: (payload) => payload.response }))
|
||||
.then(page => {
|
||||
debug('page=%O', page);
|
||||
return page;
|
||||
})
|
||||
.then(jsonp => vm.runInNewContext(jsonp, { jQuery666: (payload) => payload.response }))
|
||||
.then(items => _.filter(items, item => !_.isString(item)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user