mirror of
https://codeberg.org/lucida/lucida.git
synced 2026-11-12 14:47:24 -05:00
fix soundcloud processing
This commit is contained in:
@@ -46,11 +46,12 @@ interface SoundcloudTranscoding {
|
||||
export default class Soundcloud implements Streamer {
|
||||
hostnames = ['soundcloud.com', 'm.soundcloud.com', 'www.soundcloud.com']
|
||||
oauthToken?: string
|
||||
client?: ScClient
|
||||
constructor(options: SoundcloudOptions) {
|
||||
this.oauthToken = options?.oauthToken
|
||||
}
|
||||
async search(query: string, limit = 20): Promise<SearchResults> {
|
||||
const client = await this.#getClient()
|
||||
const client = this.client || (await this.#getClient())
|
||||
const response = await fetch(
|
||||
this.#formatURL(
|
||||
`https://api-v2.soundcloud.com/search?q=${encodeURIComponent(
|
||||
@@ -83,7 +84,7 @@ export default class Soundcloud implements Streamer {
|
||||
else if (resultResponse.collection[i].kind == 'playlist')
|
||||
items.albums.push(await parseAlbum(<RawAlbum>resultResponse.collection[i]))
|
||||
else if (resultResponse.collection[i].kind == 'user')
|
||||
items.artists.push(parseArtist(<RawArtist>resultResponse.collection[i]))
|
||||
items.artists.push((await parseArtist(<RawArtist>resultResponse.collection[i])))
|
||||
}
|
||||
|
||||
return items
|
||||
@@ -103,6 +104,7 @@ export default class Soundcloud implements Streamer {
|
||||
id: await fetchKey(response)
|
||||
}
|
||||
|
||||
this.client = client
|
||||
return client
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ export default class Soundcloud implements Streamer {
|
||||
// loosely based off: https://github.com/wukko/cobalt/blob/92c0e1d7b7df262fcd82ea7f5cf8c58c6d2ad744/src/modules/processing/services/soundcloud.js
|
||||
|
||||
const type = await this.getTypeFromUrl(url)
|
||||
const client = await this.#getClient()
|
||||
const client = this.client || (await this.#getClient())
|
||||
|
||||
// getting the IDs and track authorization
|
||||
const html = await (await fetch(url, { method: 'get', headers: headers() })).text()
|
||||
@@ -179,17 +181,13 @@ export default class Soundcloud implements Streamer {
|
||||
const parsed: GetByUrlResponse = {
|
||||
type: 'album',
|
||||
metadata: await parseAlbum(data),
|
||||
tracks: await Promise.all(
|
||||
data.tracks.map(async (track: RawTrack) => {
|
||||
if (!track.title) track = await this.#getRawTrackInfo(track.id, client)
|
||||
track.user = data.user
|
||||
return parseTrack(track)
|
||||
})
|
||||
)
|
||||
tracks: []
|
||||
}
|
||||
|
||||
for (const i in data.tracks) {
|
||||
const track = data.tracks[i]
|
||||
let track = data.tracks[i]
|
||||
|
||||
if (!track.title) track = await this.#getRawTrackInfo(track.id, client)
|
||||
|
||||
const parsedTrack = {
|
||||
type: 'track',
|
||||
@@ -217,7 +215,7 @@ export default class Soundcloud implements Streamer {
|
||||
|
||||
return {
|
||||
type: 'artist',
|
||||
metadata: parseArtist(data)
|
||||
metadata: (await parseArtist(data))
|
||||
}
|
||||
}
|
||||
default:
|
||||
@@ -232,9 +230,9 @@ export default class Soundcloud implements Streamer {
|
||||
headers: headers(this.oauthToken)
|
||||
})
|
||||
).text()
|
||||
)[0]
|
||||
)
|
||||
|
||||
return api
|
||||
return {...api, id}
|
||||
}
|
||||
async getAccountInfo(): Promise<StreamerAccount> {
|
||||
const track = <TrackGetByUrlResponse>await this.getByUrl('https://soundcloud.com/ween/polka-dot-tail')
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface Headers {
|
||||
'User-Agent': string
|
||||
}
|
||||
|
||||
export function parseArtist(raw: RawArtist): Artist {
|
||||
export async function parseArtist(raw: RawArtist): Promise<Artist> {
|
||||
const artist: Artist = {
|
||||
id: raw.id,
|
||||
url: raw.permalink_url,
|
||||
@@ -56,6 +56,7 @@ export interface RawAlbum {
|
||||
track_count: number
|
||||
release_date: string
|
||||
user: RawArtist
|
||||
user_id: number | string
|
||||
kind: 'playlist'
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ export async function parseAlbum(raw: RawAlbum): Promise<Album> {
|
||||
url: raw.permalink_url,
|
||||
trackCount: raw.track_count,
|
||||
releaseDate: new Date(raw.release_date),
|
||||
artists: [parseArtist(raw.user)]
|
||||
artists: [(await parseArtist(raw.user))]
|
||||
}
|
||||
if (raw.tracks?.[0]?.artwork_url != undefined) {
|
||||
album.coverArtwork = [await parseCoverArtwork(raw?.tracks?.[0]?.artwork_url)]
|
||||
@@ -79,7 +80,7 @@ export interface RawTrack {
|
||||
transcodings?: { duration: number }[]
|
||||
}
|
||||
kind: 'track'
|
||||
id: number
|
||||
id: number | string
|
||||
title: string
|
||||
duration: number,
|
||||
created_at: string,
|
||||
@@ -89,6 +90,7 @@ export interface RawTrack {
|
||||
user: RawArtist,
|
||||
last_modified: string,
|
||||
description: string
|
||||
user_id: number | string
|
||||
}
|
||||
|
||||
export async function parseTrack(raw: RawTrack): Promise<Track> {
|
||||
@@ -96,7 +98,7 @@ export async function parseTrack(raw: RawTrack): Promise<Track> {
|
||||
id: raw.id,
|
||||
title: raw.title,
|
||||
url: raw.permalink_url,
|
||||
artists: [parseArtist(raw.user)],
|
||||
artists: [(await parseArtist(raw.user))],
|
||||
durationMs: (raw.full_duration || raw.media?.transcodings?.[0]?.duration),
|
||||
releaseDate: new Date(raw.created_at),
|
||||
description: raw.description
|
||||
|
||||
Reference in New Issue
Block a user