add on.soundcloud.com support, bump version

This commit is contained in:
aria 2024-08-12 23:44:10 -04:00
parent c9c15f98b4
commit 43216bb2f2
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "lucida",
"version": "2.0.0-26",
"version": "2.0.0-27",
"description": "A modular music downloader tool",
"main": "build/index.js",
"type": "module",

View File

@ -57,7 +57,7 @@ interface SoundCloudSubscriptionData {
}
export default class Soundcloud implements Streamer {
hostnames = ['soundcloud.com', 'm.soundcloud.com', 'www.soundcloud.com']
hostnames = ['soundcloud.com', 'm.soundcloud.com', 'www.soundcloud.com', 'on.soundcloud.com']
testData = {
'https://soundcloud.com/saoirsedream/charlikartlanparty': {
type: 'track',
@ -144,6 +144,9 @@ export default class Soundcloud implements Streamer {
}
async getByUrl(url: string): Promise<GetByUrlResponse> {
const { hostname } = new URL(url)
if (hostname == 'on.soundcloud.com') url = await followRedirect(url)
return await this.#getMetadata(url)
}
@ -355,3 +358,12 @@ async function getStream(
}
}
}
async function followRedirect(url: string) {
const res = await fetch(url, { redirect: 'manual' })
const location = res.headers.get('Location')
if (res.status != 302 || !location) throw new Error('URL not supported')
return location
}