From 233adf68f72669082e8dc0a9e04a8c0a26c233ea Mon Sep 17 00:00:00 2001 From: hazycora Date: Sat, 20 Jul 2024 07:08:47 -0500 Subject: [PATCH] format and lint lmfao why has nobody been doing this --- src/index.ts | 13 +++++++--- src/streamers/qobuz/main.ts | 10 +++++--- src/streamers/qobuz/parse.ts | 14 +++++------ src/streamers/soundcloud/main.ts | 42 +++++++++++++++---------------- src/streamers/soundcloud/parse.ts | 33 ++++++++++++------------ src/streamers/spotify/main.ts | 22 ++++++++++++---- src/streamers/spotify/parse.ts | 17 +++++++++---- src/streamers/tidal/main.ts | 17 ++++++++++--- src/streamers/tidal/parse.ts | 2 +- src/types.ts | 10 ++++---- 10 files changed, 109 insertions(+), 71 deletions(-) diff --git a/src/index.ts b/src/index.ts index 26427ed..5b84ce2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,11 @@ -import { ItemType, GetByUrlResponse, SearchResults, Streamer, StreamerWithLogin, StreamerAccount } from './types.js' +import { + ItemType, + GetByUrlResponse, + SearchResults, + Streamer, + StreamerWithLogin, + StreamerAccount +} from './types.js' interface LucidaOptions { modules: { [key: string]: Streamer | StreamerWithLogin } @@ -41,8 +48,8 @@ class Lucida { async checkAccounts(): Promise<{ [key: string]: StreamerAccount }> { const results = await Promise.all( Object.values(this.modules).map(async (e) => { - if (e.getAccountInfo) return (await e.getAccountInfo()) - else return {valid: false} + if (e.getAccountInfo) return await e.getAccountInfo() + else return { valid: false } }) ) const moduleNames = Object.keys(this.modules) diff --git a/src/streamers/qobuz/main.ts b/src/streamers/qobuz/main.ts index 8e10649..bec7b6e 100644 --- a/src/streamers/qobuz/main.ts +++ b/src/streamers/qobuz/main.ts @@ -33,7 +33,7 @@ interface LoginResponse { id: number display_name: string language_code: string - zone: string, + zone: string store: string country: string creation_date: string @@ -272,8 +272,12 @@ export default class Qobuz implements StreamerWithLogin { } } async getAccountInfo(): Promise { - const loginResponse = await this.#getSigned('user/login', {extra: 'partner', device_manufacturer_id: 'undefined', app_id: this.appId}) - + const loginResponse = await this.#getSigned('user/login', { + extra: 'partner', + device_manufacturer_id: 'undefined', + app_id: this.appId + }) + return { valid: true, premium: loginResponse.user.credential.parameters.hires_streaming, diff --git a/src/streamers/qobuz/parse.ts b/src/streamers/qobuz/parse.ts index ae5d4d6..2b138ae 100644 --- a/src/streamers/qobuz/parse.ts +++ b/src/streamers/qobuz/parse.ts @@ -49,12 +49,12 @@ export interface RawAlbum { upc: string released_at: number label?: { - name: string, + name: string id: number - }, + } genre?: { - name: string, - id: number, + name: string + id: number slug: string } copyright: string @@ -102,9 +102,9 @@ export interface RawTrack { album?: RawAlbum track_number?: number media_number?: number - duration: number, + duration: number parental_warning: boolean - isrc: string, + isrc: string performers?: string } @@ -147,4 +147,4 @@ function parsePerformers(performers: string, track: Track) { } return track -} \ No newline at end of file +} diff --git a/src/streamers/soundcloud/main.ts b/src/streamers/soundcloud/main.ts index b7bb4b2..87888cf 100644 --- a/src/streamers/soundcloud/main.ts +++ b/src/streamers/soundcloud/main.ts @@ -84,7 +84,7 @@ export default class Soundcloud implements Streamer { else if (resultResponse.collection[i].kind == 'playlist') items.albums.push(await parseAlbum(resultResponse.collection[i])) else if (resultResponse.collection[i].kind == 'user') - items.artists.push((await parseArtist(resultResponse.collection[i]))) + items.artists.push(await parseArtist(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 { - const track = await this.getByUrl('https://soundcloud.com/ween/polka-dot-tail') + const track = ( + 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 { 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) } } } diff --git a/src/streamers/soundcloud/parse.ts b/src/streamers/soundcloud/parse.ts index 138f1d6..1de43b7 100644 --- a/src/streamers/soundcloud/parse.ts +++ b/src/streamers/soundcloud/parse.ts @@ -67,7 +67,7 @@ export async function parseAlbum(raw: RawAlbum): Promise { 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 { 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 { - 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 2) throw new Error('Unknown Spotify URL') - if (parts[0] != 'artist' && parts[0] != 'track' && parts[0] != 'album' && parts[0] != 'show' && parts[0] != 'episode') { + if ( + parts[0] != 'artist' && + parts[0] != 'track' && + parts[0] != 'album' && + parts[0] != 'show' && + parts[0] != 'episode' + ) { throw new Error(`Spotify type "${parts[0]}" unsupported`) } if (!parts[1]) throw new Error('Unknown Spotify URL') @@ -63,7 +75,7 @@ class Spotify implements StreamerWithLogin { if (tracks) { return { type, - metadata: {...parseAlbum(metadata), trackCount: tracks.length}, + metadata: { ...parseAlbum(metadata), trackCount: tracks.length }, tracks: tracks?.map((e) => parseTrack(e)) ?? [] } } @@ -93,7 +105,7 @@ class Spotify implements StreamerWithLogin { return { type: 'podcast', metadata: parsePodcast(metadata), - episodes: (metadata.episodes?.map((e) => parseEpisode(e))) ?? [] + episodes: metadata.episodes?.map((e) => parseEpisode(e)) ?? [] } } } @@ -116,7 +128,7 @@ class Spotify implements StreamerWithLogin { return { valid: true, - premium, + premium, country: info.country, explicit: info.allowExplicit } diff --git a/src/streamers/spotify/parse.ts b/src/streamers/spotify/parse.ts index cdf5dd7..f1ab7b0 100644 --- a/src/streamers/spotify/parse.ts +++ b/src/streamers/spotify/parse.ts @@ -1,4 +1,11 @@ -import type { SpotifyAlbum, SpotifyArtist, SpotifyThumbnail, SpotifyTrack, SpotifyEpisode, SpotifyPodcast } from 'librespot/types' +import type { + SpotifyAlbum, + SpotifyArtist, + SpotifyThumbnail, + SpotifyTrack, + SpotifyEpisode, + SpotifyPodcast +} from 'librespot/types' import { Album, Artist, Episode, Podcast, Track } from '../../types.js' function parseThumbnails(raw: SpotifyThumbnail[]) { @@ -33,7 +40,7 @@ export function parseTrack(raw: SpotifyTrack) { trackNumber: raw.trackNumber, discNumber: raw.discNumber, artists: raw.artists?.map((e) => parseArtist(e)) ?? [], - durationMs: raw.durationMs, + durationMs: raw.durationMs } if (raw.album) track.album = parseAlbum(raw.album) if (raw?.isrc) track.isrc = raw.isrc @@ -49,7 +56,7 @@ export function parseAlbum(raw: SpotifyAlbum) { trackCount: raw.totalTracks, releaseDate: raw.releaseDate, coverArtwork: parseThumbnails(raw.coverArtwork), - artists: raw.artists.map((e) => parseArtist(e)), + artists: raw.artists.map((e) => parseArtist(e)) } if (raw.availableMarkets) album.regions = raw.availableMarkets @@ -80,8 +87,8 @@ export function parsePodcast(raw: SpotifyPodcast) { description: raw.description, coverArtwork: parseThumbnails(raw.coverArtwork) } - if (typeof raw.explicit == 'boolean') podcast.explicit = raw.explicit + if (typeof raw.explicit == 'boolean') podcast.explicit = raw.explicit if (raw.episodes) podcast.episodes = raw.episodes.map((e) => parseEpisode(e)) return podcast -} \ No newline at end of file +} diff --git a/src/streamers/tidal/main.ts b/src/streamers/tidal/main.ts index 4e64736..8a9ec25 100644 --- a/src/streamers/tidal/main.ts +++ b/src/streamers/tidal/main.ts @@ -55,7 +55,7 @@ interface SubscriptionData { highestSoundQuality: string premiumAccess: boolean canGetTrial: boolean - paymentType: string, + paymentType: string paymentOverdue: boolean } @@ -95,7 +95,11 @@ export default class Tidal implements Streamer { 'User-Agent': 'TIDAL_ANDROID/1039 okhttp/3.14.9' } } - async #get(url: string, params: { [key: string]: string | number } = {}, base: string = TIDAL_API_BASE): Promise { + async #get( + url: string, + params: { [key: string]: string | number } = {}, + base: string = TIDAL_API_BASE + ): Promise { if (this.failedAuth) throw new Error(`Last request failed to authorize, get new tokens`) if (Date.now() > this.expires) await this.refresh() if (!this.countryCode) await this.getCountryCode() @@ -300,7 +304,10 @@ export default class Tidal implements Streamer { tracks: tracksResponse.items.map(parseTrack) } } - async #getFileUrl(trackId: number | string, quality = 'HI_RES_LOSSLESS'): Promise { + async #getFileUrl( + trackId: number | string, + quality = 'HI_RES_LOSSLESS' + ): Promise { interface PlaybackInfo { manifest: string manifestMimeType: string @@ -413,7 +420,9 @@ export default class Tidal implements Streamer { } async getAccountInfo(): Promise { if (!this.userId) await this.getCountryCode() - const subscription = await this.#get(`users/${this.userId}/subscription`, {}, TIDAL_SUBSCRIPTION_BASE) + const subscription = ( + await this.#get(`users/${this.userId}/subscription`, {}, TIDAL_SUBSCRIPTION_BASE) + ) return { valid: true, diff --git a/src/streamers/tidal/parse.ts b/src/streamers/tidal/parse.ts index 780d434..98b543b 100644 --- a/src/streamers/tidal/parse.ts +++ b/src/streamers/tidal/parse.ts @@ -174,7 +174,7 @@ export function parseMpd(mpdString: string): string[] { if (!initializationUrl) throw new Error('No initialization url') const mediaUrl = segTemplate.getAttribute('media') if (!mediaUrl) throw new Error('No media url') - let trackUrls = [initializationUrl] + const trackUrls = [initializationUrl] const timeline = segTemplate.querySelector('SegmentTimeline') if (timeline) { let numSegments = 0 diff --git a/src/types.ts b/src/types.ts index c14af20..593f6e0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,8 +29,8 @@ export interface Album { coverArtwork?: CoverArtwork[] artists?: Artist[] description?: string - copyright?: string, - label?: string, + copyright?: string + label?: string genre?: string[] regions?: string[] } @@ -102,7 +102,7 @@ export interface GetStreamResponse { export type GetByUrlResponse = | TrackGetByUrlResponse | ArtistGetByUrlResponse - | AlbumGetByUrlResponse + | AlbumGetByUrlResponse | EpisodeGetByUrlResponse | PodcastGetByUrlResponse @@ -136,7 +136,7 @@ export interface StreamerAccount { premium?: boolean country?: string explicit?: boolean -} +} export interface Streamer { hostnames: string[] @@ -151,4 +151,4 @@ export interface Streamer { export interface StreamerWithLogin extends Streamer { login(username: string, password: string): Promise -} \ No newline at end of file +}