make getTypeFromUrl async

This commit is contained in:
hazycora
2024-04-15 21:51:32 -04:00
parent 94c5134af2
commit 172b1cf056
6 changed files with 14 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
import crypto from 'crypto'
import fetch from 'node-fetch'
import {
ItemType,
StreamerWithLogin,
SearchResults,
GetByUrlResponse,
@@ -214,7 +215,7 @@ export default class Qobuz implements StreamerWithLogin {
}
return [urlParts[0], urlParts[1]]
}
getTypeFromUrl(url: string): 'artist' | 'album' | 'track' {
async getTypeFromUrl(url: string): Promise<ItemType> {
return this.#getUrlParts(url)[0]
}
async getByUrl(url: string): Promise<GetByUrlResponse> {

View File

@@ -1,6 +1,6 @@
import fetch, { HeadersInit } from 'node-fetch'
import { DEFAULT_HEADERS, SC_VERSION } from './constants.js'
import { Streamer, SearchResults, GetByUrlResponse, GetStreamResponse } from '../../types.js'
import { ItemType, Streamer, SearchResults, GetByUrlResponse, GetStreamResponse } from '../../types.js'
import {
parseAlbum,
parseTrack,
@@ -97,7 +97,7 @@ export default class Soundcloud implements Streamer {
return client
}
getTypeFromUrl(url: string): 'artist' | 'album' | 'track' {
async getTypeFromUrl(url: string): Promise<ItemType> {
const { pathname } = new URL(url)
if (pathname.split('/').slice(1).length == 1) return 'artist'
else {
@@ -125,7 +125,7 @@ export default class Soundcloud implements Streamer {
async #getMetadata(url: string): Promise<GetByUrlResponse> {
// loosely based off: https://github.com/wukko/cobalt/blob/92c0e1d7b7df262fcd82ea7f5cf8c58c6d2ad744/src/modules/processing/services/soundcloud.js
const type = this.getTypeFromUrl(url)
const type = await this.getTypeFromUrl(url)
const client = await this.#getClient()
// getting the IDs and track authorization

View File

@@ -1,6 +1,6 @@
import Librespot, { LibrespotOptions } from 'librespot'
import { parseArtist, parseAlbum, parseTrack } from './parse.js'
import { GetByUrlResponse, SearchResults, StreamerWithLogin } from '../../types.js'
import { ItemType, GetByUrlResponse, SearchResults, StreamerWithLogin } from '../../types.js'
class Spotify implements StreamerWithLogin {
client: Librespot
@@ -21,7 +21,7 @@ class Spotify implements StreamerWithLogin {
if (!parts[1]) throw new Error('Unknown Spotify URL')
return [parts[0], parts[1]]
}
getTypeFromUrl(url: string) {
async getTypeFromUrl(url: string) {
return this.#getUrlParts(url)[0]
}
async getByUrl(url: string, limit = 0): Promise<GetByUrlResponse> {

View File

@@ -1,6 +1,6 @@
import fetch from 'node-fetch'
import { spawn } from 'child_process'
import { GetByUrlResponse, GetStreamResponse, SearchResults, Streamer, Track } from '../../types.js'
import { ItemType, GetByUrlResponse, GetStreamResponse, SearchResults, Streamer, Track } from '../../types.js'
import { TIDAL_AUTH_BASE, TIDAL_API_BASE } from './constants.js'
import {
Contributor,
@@ -334,7 +334,7 @@ export default class Tidal implements Streamer {
}
return [urlParts[0], urlParts[1]]
}
getTypeFromUrl(url: string): 'artist' | 'album' | 'track' {
async getTypeFromUrl(url: string): Promise<ItemType> {
return this.#getUrlParts(url)[0]
}
async getByUrl(url: string): Promise<GetByUrlResponse> {