feat: Add Manifest type
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
8950028f5b
commit
9bb0d022b7
|
|
@ -14,7 +14,6 @@
|
|||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
||||
"twind": "https://esm.sh/twind@0.16.17",
|
||||
"twind/": "https://esm.sh/twind@0.16.17/",
|
||||
"zod": "https://deno.land/x/zod@v3.22.4/mod.ts",
|
||||
"openapi-typescript": "npm:openapi-typescript@6.7.5"
|
||||
},
|
||||
"compilerOptions": {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ const nrkTypes: { filename: string; url: URL }[] = [
|
|||
filename: "./lib/nrk-catalog.ts",
|
||||
url: new URL("https://psapi.nrk.no/documentation/openapi/programsider-radio/openapi.yml"),
|
||||
},
|
||||
{
|
||||
filename: "./lib/nrk-playback.ts",
|
||||
url: new URL("https://psapi.nrk.no/documentation/openapi/playback/2.0/openapi.json"),
|
||||
},
|
||||
] as const;
|
||||
|
||||
async function generateTypes() {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
25
lib/nrk.ts
25
lib/nrk.ts
|
|
@ -1,7 +1,7 @@
|
|||
import { get, OK } from "https://deno.land/x/kall@v0.1.0/mod.ts";
|
||||
import { components as searchComponents } from "./nrk-search.ts";
|
||||
import { components as catalogComponents } from "./nrk-catalog.ts";
|
||||
import { z } from "zod";
|
||||
import { external as playbackComponents } from "./nrk-playback.ts";
|
||||
|
||||
type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
|
||||
type PodcastEpisodes = catalogComponents["schemas"]["EpisodesHalResource"];
|
||||
|
|
@ -16,24 +16,7 @@ export type SearchResult = ArrayElement<SearchResultList> & {
|
|||
description?: string;
|
||||
};
|
||||
|
||||
const manifestSchema = z.object({
|
||||
id: z.string(),
|
||||
playable: z.object({
|
||||
endSequenceStartTime: z.null(),
|
||||
duration: z.string(),
|
||||
assets: z.array(z.object({
|
||||
url: z.string(),
|
||||
format: z.string(),
|
||||
mimeType: z.string(),
|
||||
encrypted: z.boolean(),
|
||||
})),
|
||||
}),
|
||||
});
|
||||
|
||||
/** Incomplete manifest types.
|
||||
* TODO: Add OpenAPI Manifest to `generate-types.ts`.
|
||||
*/
|
||||
type Manifest = z.infer<typeof manifestSchema>;
|
||||
type Manifest = playbackComponents["schemas/playback-channel.json"]["components"]["schemas"]["PlayableManifest"];
|
||||
|
||||
const nrkAPI = `https://psapi.nrk.no`;
|
||||
|
||||
|
|
@ -41,12 +24,10 @@ async function withDownloadLink(
|
|||
episode: PodcastEpisodesSingle,
|
||||
): Promise<OriginalEpisode> {
|
||||
// getting stream link
|
||||
const [playbackStatus, playbackResponseRaw] = await get<Manifest>(
|
||||
const [playbackStatus, playbackResponse] = await get<Manifest>(
|
||||
`${nrkAPI}/playback/manifest/podcast/${episode.episodeId}`,
|
||||
);
|
||||
|
||||
const playbackResponse = manifestSchema.parse(playbackResponseRaw);
|
||||
|
||||
if (playbackStatus === OK && playbackResponse) {
|
||||
return { ...episode, url: playbackResponse.playable.assets[0].url };
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue