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