fp/packages/fetchers/src/getPlaylistUrl.ts

23 lines
1016 B
TypeScript
Raw Normal View History

2024-09-16 16:31:51 +00:00
import { configs } from './config.ts'
2024-10-02 17:38:24 +00:00
import { type GenericApiResponse } from '@futureporn/types'
2024-08-31 10:42:28 +00:00
2024-10-02 17:38:24 +00:00
export default async function getPlaylistUrl (url: string): Promise<GenericApiResponse> {
2024-08-31 10:42:28 +00:00
if (!url) throw new Error(`getPlaylistUrl requires a url, but it was undefined.`);
const res = await fetch(`${configs.scoutUrl}/ytdlp/playlist-url?url=${url}`)
if (!res.ok) {
const body = await res.text()
console.error(`failed to getPlaylistUrl res.status=${res.status}, res.statusText=${res.statusText}, body=${body}`)
2024-10-02 17:38:24 +00:00
return {
error: 'PlaylistFailedError',
detail: `failed to getPlaylistUrl. res.status=${res.status}, res.statusText=${res.statusText}, body=${body}`,
data: null,
message: 'something went wrong wile fetching data from @futureporn/scout'
2024-08-31 10:42:28 +00:00
}
2024-10-02 17:38:24 +00:00
} else {
const payload = await res.json() as any
console.log(`>>>>>> getPlaylistUrl data=${payload.data}, error=${payload.error} got a data payload as follows.`)
console.log(payload)
return payload
2024-08-31 10:42:28 +00:00
}
}