Skip to content

Instantly share code, notes, and snippets.

@Asgarrrr
Created September 13, 2021 00:20
Show Gist options
  • Save Asgarrrr/0ff194befa5415de7752a950b4fb5c45 to your computer and use it in GitHub Desktop.
Save Asgarrrr/0ff194befa5415de7752a950b4fb5c45 to your computer and use it in GitHub Desktop.
Fetch a SoundCloud API key without owning an application

Fetch a SoundCloud API key without owning an application

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 ] );
});
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment