This script allows you to retrieve an API key without having to create a resource. Be careful though, the site can change suddenly, so keep this in mind.
There are two versions of this script, one without dependencies and one using node-fetch
This script allows you to retrieve an API key without having to create a resource. Be careful though, the site can change suddenly, so keep this in mind.
There are two versions of this script, one without dependencies and one using node-fetch
// With external dependency ( node-fetch ) | |
// ██████ Dependency █████████████████████████████████████████████████████████ | |
// —— A light-weight module that brings Fetch API to Node.js. | |
const fetch = require( "node-fetch" ); | |
// ██████ | ███████████████████████████████████████████████████████████████████ | |
/** | |
* @returns {Promise<string>} | |
*/ | |
new Promise( async ( resolve, reject ) => { | |
const main = await fetch( "https://soundcloud.com/" ) | |
.then( ( res ) => res.text() ) | |
.catch( ( ) => reject( "Unable to fetch main page" ) ); | |
for ( const url of main.match( /src="(.*?).js/gmi ) ) { | |
const res = await fetch( url.substr( 5, url.length ) ) | |
.then( ( res ) => res.text() ) | |
.catch( ( ) => { "Do nothing, continue to next url" } ); | |
if ( res.match( /client_id/gmi ) ) { | |
const content = res.match( /client_id:"(\w+)"/ ); | |
content && resolve( content[ 1 ] ); | |
} | |
} | |
reject( "No API Key found" ); | |
}); |
// Without external dependence | |
/** | |
* @returns {Promise<string>} | |
*/ | |
new Promise( async ( resolve, reject ) => { | |
const { get : fetch } = require( "https" ); | |
let rawData = ""; | |
fetch( "https://soundcloud.com/", ( res ) => { | |
res.on( "data", ( chunk ) => { rawData += chunk; } ); | |
res.on( "end", () => { | |
for ( const url of rawData.match( /src="(.*?).js/gmi ) ) { | |
let subRawData = ""; | |
fetch( url.substr( 5, url.length ), ( subRes ) => { | |
subRes.on( "data", ( chunk ) => { subRawData += chunk; } ); | |
subRes.on( "end", () => { | |
const content = subRawData.match( /client_id:"(\w+)"/ ); | |
content && resolve( content[ 1 ] ); | |
}); | |
}); | |
} | |
}); | |
}); | |
}); |