add episodes/podcasts to spotify, fix soundcloud bugs

This commit is contained in:
aria
2024-07-17 04:12:16 -04:00
parent 25f7babb3e
commit 12a04b2a7b
8 changed files with 217 additions and 32 deletions

View File

@@ -141,18 +141,21 @@ export default class Soundcloud implements Streamer {
switch (type) {
case 'track': {
const trackId = html
.split(`{"hydratable":"sound",`)?.[1]
?.split(`"id":`)?.[1]
?.split(',')?.[0]
.split(`<link rel="alternate" href="android-app://com.soundcloud.android/soundcloud/sounds:`)?.[1]
?.split(`">`)?.[0]
let naked = `https://api-v2.soundcloud.com/tracks/${trackId}`
let path = new URL(url).pathname
if (path.split('/').length == 4) naked = `${naked}?secret_token=${path.split('/')[3]}`
const api = JSON.parse(
await (
await fetch(
this.#formatURL(`https://api-v2.soundcloud.com/tracks?ids=${trackId}`, client),
this.#formatURL(naked, client),
{ method: 'get', headers: headers(this.oauthToken) }
)
).text()
)[0]
)
return {
type: 'track',
@@ -215,6 +218,8 @@ export default class Soundcloud implements Streamer {
metadata: parseArtist(data)
}
}
default:
throw(`Type "${type}" not supported.`)
}
}
async #getRawTrackInfo(id: number | string, client: ScClient) {

View File

@@ -81,10 +81,14 @@ export interface RawTrack {
kind: 'track'
id: number
title: string
duration: number,
created_at: string,
full_duration: number,
permalink_url: string
artwork_url?: string
full_duration: number
user: RawArtist
artwork_url?: string,
user: RawArtist,
last_modified: string,
description: string
}
export async function parseTrack(raw: RawTrack): Promise<Track> {
@@ -93,12 +97,12 @@ export async function parseTrack(raw: RawTrack): Promise<Track> {
title: raw.title,
url: raw.permalink_url,
artists: [parseArtist(raw.user)],
durationMs: raw.media?.transcodings?.[0]?.duration
durationMs: (raw.full_duration || raw.media?.transcodings?.[0]?.duration),
releaseDate: new Date(raw.created_at),
description: raw.description
}
if (raw?.artwork_url != undefined) {
track.coverArtwork = [await parseCoverArtwork(raw?.artwork_url)]
}
if (raw?.artwork_url != undefined) track.coverArtwork = [await parseCoverArtwork(raw?.artwork_url)]
return track
}