format and lint

lmfao why has nobody been doing this
This commit is contained in:
hazycora
2024-07-20 08:08:47 -04:00
parent 62e032fea8
commit 233adf68f7
10 changed files with 109 additions and 71 deletions

View File

@@ -84,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((await parseArtist(<RawArtist>resultResponse.collection[i])))
items.artists.push(await parseArtist(<RawArtist>resultResponse.collection[i]))
}
return items
@@ -143,21 +143,18 @@ export default class Soundcloud implements Streamer {
switch (type) {
case 'track': {
const trackId = html
.split(`"soundcloud://sounds:`)?.[1]
?.split(`">`)?.[0]
const trackId = html.split(`"soundcloud://sounds:`)?.[1]?.split(`">`)?.[0]
let naked = `https://api-v2.soundcloud.com/tracks/${trackId}`
let path = new URL(url).pathname
const 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(naked, client),
{ method: 'get', headers: headers(this.oauthToken) }
)
await fetch(this.#formatURL(naked, client), {
method: 'get',
headers: headers(this.oauthToken)
})
).text()
)
@@ -215,11 +212,11 @@ export default class Soundcloud implements Streamer {
return {
type: 'artist',
metadata: (await parseArtist(data))
metadata: await parseArtist(data)
}
}
default:
throw(`Type "${type}" not supported.`)
throw `Type "${type}" not supported.`
}
}
async #getRawTrackInfo(id: number | string, client: ScClient) {
@@ -232,16 +229,17 @@ export default class Soundcloud implements Streamer {
).text()
)
return {...api, id}
return { ...api, id }
}
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')
)
const stream = await track.getStream()
if (stream.mimeType.startsWith('audio/mp4')) {
stream.stream.unpipe()
return {valid: true, premium: true, explicit: true}
}
else return {valid: true, premium: false, explicit: true}
return { valid: true, premium: true, explicit: true }
} else return { valid: true, premium: false, explicit: true }
}
}
@@ -277,11 +275,11 @@ async function getStream(
): Promise<GetStreamResponse> {
let filter = transcodings.filter((x) => x.quality == 'hq')
if (hq == true && filter.length == 0) throw new Error('Could not find HQ format.')
if (filter.length == 0) filter = transcodings.filter((x) => x.preset.startsWith('aac_')) // prioritize aac (go+)
if (filter.length == 0) filter = transcodings.filter((x) => x.preset.startsWith('mp3_')) // then mp3
if (filter.length == 0) filter = transcodings.filter((x) => x.preset.startsWith('aac_')) // prioritize aac (go+)
if (filter.length == 0) filter = transcodings.filter((x) => x.preset.startsWith('mp3_')) // then mp3
if (filter.length == 0) filter = transcodings.filter((x) => x.preset.startsWith('opus_')) // then opus
if (filter.length == 0) throw new Error('Could not find applicable format.') // and this is just in case none of those exist
if (filter.length == 0) throw new Error('Could not find applicable format.') // and this is just in case none of those exist
const transcoding = filter[0]
const streamUrlResp = await fetch(
@@ -305,7 +303,7 @@ async function getStream(
return {
mimeType: transcoding.format.mime_type,
stream: (await parseHls(json.url, container))
stream: await parseHls(json.url, container)
}
}
}

View File

@@ -67,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: [(await parseArtist(raw.user))]
artists: [await parseArtist(raw.user)]
}
if (raw.tracks?.[0]?.artwork_url != undefined) {
album.coverArtwork = [await parseCoverArtwork(raw?.tracks?.[0]?.artwork_url)]
@@ -82,13 +82,13 @@ export interface RawTrack {
kind: 'track'
id: number | string
title: string
duration: number,
created_at: string,
full_duration: number,
duration: number
created_at: string
full_duration: number
permalink_url: string
artwork_url?: string,
user: RawArtist,
last_modified: string,
artwork_url?: string
user: RawArtist
last_modified: string
description: string
user_id: number | string
}
@@ -98,21 +98,22 @@ export async function parseTrack(raw: RawTrack): Promise<Track> {
id: raw.id,
title: raw.title,
url: raw.permalink_url,
artists: [(await parseArtist(raw.user))],
durationMs: (raw.full_duration || raw.media?.transcodings?.[0]?.duration),
artists: [await parseArtist(raw.user)],
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
}
export async function parseHls(url: string, container: string): Promise<NodeJS.ReadableStream> {
return new Promise(async function(resolve, reject) {
const folder = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'lucida'))
const folder = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'lucida'))
return new Promise(function (resolve, reject) {
const ffmpegProc = spawn('ffmpeg', [
'-hide_banner',
'-loglevel',
@@ -128,13 +129,13 @@ export async function parseHls(url: string, container: string): Promise<NodeJS.R
let err: string
ffmpegProc.stderr.on('data', function(data) {
ffmpegProc.stderr.on('data', function (data) {
err = data.toString()
})
ffmpegProc.once('exit', function(code) {
ffmpegProc.once('exit', function (code) {
if (code == 0) resolve(fs.createReadStream(`${folder}/hls.${container}`))
else reject((`FFMPEG HLS error: ${err}` || 'FFMPEG could not parse the HLS.'))
else reject(`FFMPEG HLS error: ${err}` || 'FFMPEG could not parse the HLS.')
})
})
}