-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added startpos and loop to sounds make sound setup better added newgrounds sounds via CUSTOM with sound ids (this took a month) removed herobrine
- Loading branch information
Showing
6 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
export default async function getNGSong(id: string): Promise<ArrayBuffer> { | ||
async function getPage(url: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open("GET", url, true); | ||
xhr.responseType = "text"; | ||
xhr.onload = () => { | ||
if (xhr.status === 200) { | ||
resolve(xhr.response); | ||
} else { | ||
reject(xhr.status); | ||
} | ||
}; | ||
xhr.send(); | ||
}); | ||
} | ||
|
||
if (!id) { | ||
return Promise.reject("Song ID is empty!"); | ||
} | ||
|
||
try { | ||
const response = await getPage( | ||
`https://api.allorigins.win/get?url=https%3A%2F%2Fwww.newgrounds.com%2Faudio%2Flisten%2F${id}` | ||
); | ||
const data = JSON.parse(response).contents; | ||
const code = JSON.parse(response).status.http_code; | ||
|
||
if (code !== 200) { | ||
if (code === 404) { | ||
return Promise.reject( | ||
"The song could not be found! Please check the song id and try again! (error 404)" | ||
); | ||
} | ||
return Promise.reject( | ||
`Something went wrong! Please check your internet connection and try again! Error Code: ${code}` | ||
); | ||
} | ||
|
||
let url = data.substring(data.indexOf("<![CDATA[") + 9); | ||
url = url.substring(url.indexOf("embedController([") + 17); | ||
url = url.substring(0, url.indexOf('","')); | ||
url = url.substring(0, url.indexOf("?")); | ||
url = url.substring(url.indexOf("url") + 3); | ||
url = url.substring(url.indexOf(':"') + 2); | ||
url = url.replace(/\\\//g, "/"); | ||
|
||
let songUrl = `https://cors.niceeli.workers.dev/?${encodeURI(url)}`; | ||
|
||
let songArray: ArrayBuffer; | ||
songArray = await (await (await fetch(songUrl)).blob()).arrayBuffer(); | ||
return songArray; | ||
} catch (error) { | ||
if (error === 404) { | ||
return Promise.reject( | ||
"The song could not be found! Please check the song id and try again! (error 404)" | ||
); | ||
} | ||
return Promise.reject( | ||
`Something went wrong! Please check your internet connection and try again! Error Code: ${error}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters