style: Style adjustments, headings, search result etc. #20

Merged
timharek merged 14 commits from style-layout-changes into main 2024-04-02 19:14:06 +00:00
8 changed files with 4958 additions and 1127 deletions
Showing only changes of commit 25796ef274 - Show all commits

View File

@ -1,19 +1,21 @@
# NRSS - RSS Feeds for NRK sin podcaster
# NRSS - RSS feeds for NRK's podcasts
https://nrss.deno.dev/
Live version: [nrss.deno.dev](https://nrss.deno.dev/)
## Local devlopment
A webapp built with Deno's [Fresh](https://fresh.deno.dev/) that generates
public accessible RSS-feeds for their produced podcasts via their
[API](https://psapi.nrk.no/documentation/).
install Deno
https://deno.land/manual/getting_started/installation
## Local development
### Run the application
1. [Install Deno](https://deno.land/manual/getting_started/installation)
1. Run the app: `deno task start`
1. Open [localhost:8000](http://localhost:8000) in your browser
```shell
deno task start
```
## What is this?
Open http://localhost:8000/ to view it in the browser
This is made as a reaction that the goverment funded NRK is closing their own
content to their own app instead of building under open standards like RSS.
## Known Problems

View File

@ -5,7 +5,8 @@
"author": " Olav Sundfør <olav@sundfoer.com>",
"tasks": {
"start": "deno run -A --watch=static/,routes/ dev.ts",
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx"
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
"types:nrk": "deno run -A generate-types.ts && deno fmt ./lib"
},
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.6.8/",
@ -14,7 +15,8 @@
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
"$gfm": "https://deno.land/x/gfm@0.6.0/mod.ts"
"$gfm": "https://deno.land/x/gfm@0.6.0/mod.ts",
"openapi-typescript": "npm:openapi-typescript@6.7.5"
},
"compilerOptions": {
"jsx": "react-jsx",

28
generate-types.ts Normal file
View File

@ -0,0 +1,28 @@
import openapiTS from "openapi-typescript";
const nrkTypes: { filename: string; url: URL }[] = [
{
filename: "./lib/nrk-search.ts",
url: new URL("https://psapi.nrk.no/documentation/openapi/search-radio/v1/openapi.yml"),
},
{
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() {
for (const type of nrkTypes) {
const contents = await openapiTS(type.url);
await Deno.writeTextFile(new URL(type.filename, import.meta.url), contents);
}
}
if (import.meta.main) {
await generateTypes();
}

File diff suppressed because it is too large Load Diff

3819
lib/nrk-playback.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,35 +5,59 @@
export interface paths {
"/radio/search/title": {
/** Gives results for titles */
/**
* Title search
* @description Gives results for titles
*/
get: operations["TitleSearch"];
};
"/radio/search/title/suggest": {
/** Gives suggestion for misspelling on titles only */
/**
* Title suggest search
* @description Gives suggestion for misspelling on titles only
*/
get: operations["TitleSuggestSearch"];
};
"/radio/search/suggest": {
/** Deprecated. Use '/radio/search/title/suggest'. Gives suggestion for misspelling */
/**
* Deprecated
* @deprecated
* @description Deprecated. Use '/radio/search/title/suggest'. Gives suggestion for misspelling
*/
get: operations["TitleSuggestSearchDeprecated"];
};
"/radio/search/search": {
/** Search endpoint for all content */
/**
* Search
* @description Search endpoint for all content
*/
get: operations["Search"];
};
"/radio/search/search/suggest": {
/** Gives suggestion for misspelling */
/**
* Search suggest search
* @description Gives suggestion for misspelling
*/
get: operations["RadioSuggestSearch"];
};
"/radio/search/categories/{category}": {
/** Alphabetical listing of all series, podcasts and umbrella seasons that are not excluded from search results in given category. Categories correspond to those in pages-api, including 'alt-innhold'. For the category 'podcast', all podcasts are listed, also those excluded from search results. */
/**
* List all series, podcast and umbrella seasons in category
* @description Alphabetical listing of all series, podcasts and umbrella seasons that are not excluded from search results in given category. Categories correspond to those in pages-api, including 'alt-innhold'. For the category 'podcast', all podcasts are listed, also those excluded from search results.
*/
get: operations["RadioListAllForCategory"];
};
"/radio/search/int/search": {
/** Search endpoint for `internal use only`. Searches series and episodes. */
/**
* Internal search
* @description Search endpoint for `internal use only`. Searches series and episodes.
*/
get: operations["InternalSearch"];
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
/** Series search result */
@ -47,8 +71,6 @@ export interface components {
description?: string;
trimmedDescription?: string;
images?: components["schemas"]["image"][];
} & {
seriesId: unknown;
};
/** Episode search result */
episodesearchintresult: {
@ -57,11 +79,7 @@ export interface components {
/** @description If type is `customSeasonEpisode` */
seasonId?: string;
/** @enum {string} */
type:
| "seriesEpisode"
| "podcastEpisode"
| "singleProgram"
| "customSeasonEpisode";
type: "seriesEpisode" | "podcastEpisode" | "singleProgram" | "customSeasonEpisode";
title: string;
subtitle?: string;
trimmedSubtitle?: string;
@ -88,8 +106,6 @@ export interface components {
/** @description if `isSuggestResult` is true, `suggestQuery` displays the suggested value which is used in the current result set */
suggestQuery?: string;
};
} & {
isSuggestResult: unknown;
};
/**
* Channel result
@ -131,7 +147,7 @@ export interface components {
*/
seriesResult: {
links?: components["schemas"]["nextLink"];
results?: {
results?: ({
/** @description Unique id */
id: string;
seriesId: string;
@ -145,7 +161,7 @@ export interface components {
images: components["schemas"]["image"][];
images_1_1?: components["schemas"]["image"][];
highlights?: components["schemas"]["seriesHighlight"];
}[];
})[];
};
/**
* Episode results
@ -153,7 +169,7 @@ export interface components {
*/
episodeResult: {
links?: components["schemas"]["nextLink"];
results?: {
results?: ({
/** @description Unique id */
id: string;
episodeId: string;
@ -162,11 +178,7 @@ export interface components {
/** @description Only included in type `customSeasonEpisode` */
seasonId?: string;
/** @enum {string} */
type:
| "seriesEpisode"
| "podcastEpisode"
| "customSeasonEpisode"
| "singleProgram";
type: "seriesEpisode" | "podcastEpisode" | "customSeasonEpisode" | "singleProgram";
title: string;
/** @description Not included in type `singleProgram` */
seriesTitle?: string;
@ -175,7 +187,7 @@ export interface components {
/** Format: date */
date: string;
highlights?: components["schemas"]["episodeHighlight"];
}[];
})[];
};
nextLink: {
/**
@ -336,30 +348,48 @@ export interface components {
totalCount: number;
};
};
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export type external = Record<string, never>;
export interface operations {
/** Gives results for titles */
/**
* Title search
* @description Gives results for titles
*/
TitleSearch: {
parameters: {
header: {
accept?: "application/json;api-version=2";
};
query: {
/** The query text */
/**
* @description The query text
* @example stanghelle
*/
q: string;
/** Number of results to take */
/** @description Number of results to take */
take?: number;
/** Number of results to skip */
/**
* @description Number of results to skip
* @example 0
*/
skip?: number;
/** Filters only playable content */
/** @description Filters only playable content */
filterNotPlayable?: boolean;
/** Returns only the specified type */
/** @description Returns only the specified type */
type?: "series" | "episode";
};
header?: {
accept?: "application/json;api-version=2";
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": components["schemas"]["titlesearchresult"];
@ -367,16 +397,22 @@ export interface operations {
};
};
};
/** Gives suggestion for misspelling on titles only */
/**
* Title suggest search
* @description Gives suggestion for misspelling on titles only
*/
TitleSuggestSearch: {
parameters: {
query: {
/** The query text */
/**
* @description The query text
* @example smukker
*/
q: string;
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": string[];
@ -384,18 +420,28 @@ export interface operations {
};
};
};
/** Deprecated. Use '/radio/search/title/suggest'. Gives suggestion for misspelling */
/**
* Deprecated
* @deprecated
* @description Deprecated. Use '/radio/search/title/suggest'. Gives suggestion for misspelling
*/
TitleSuggestSearchDeprecated: {
parameters: {
query: {
/** The query text */
/**
* @description The query text
* @example stanghelle
*/
q: string;
/** Defaults to 10 if not set */
/**
* @description Defaults to 10 if not set
* @example 10
*/
take?: number;
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": string[];
@ -403,26 +449,38 @@ export interface operations {
};
};
};
/** Search endpoint for all content */
/**
* Search
* @description Search endpoint for all content
*/
Search: {
parameters: {
query: {
/** The query text */
/**
* @description The query text
* @example stanghelle
*/
q: string;
/** Number of results to take per type in the result set (see type parameter) */
/** @description Number of results to take per type in the result set (see type parameter) */
take?: number;
/** Number of results to skip */
/**
* @description Number of results to skip
* @example 0
*/
skip?: number;
/** Which page of results to get */
/**
* @description Which page of results to get
* @example 2
*/
page?: number;
/** Filters only playable content, applies to `episodes` and `series` */
/** @description Filters only playable content, applies to `episodes` and `series` */
filterNotPlayable?: boolean;
/** Returns only the specified type */
/** @description Returns only the specified type */
type?: "series" | "episode" | "channel" | "category";
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": components["schemas"]["searchresult"];
@ -430,16 +488,22 @@ export interface operations {
};
};
};
/** Gives suggestion for misspelling */
/**
* Search suggest search
* @description Gives suggestion for misspelling
*/
RadioSuggestSearch: {
parameters: {
query: {
/** The query text */
/**
* @description The query text
* @example smukker
*/
q: string;
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": string[];
@ -447,25 +511,28 @@ export interface operations {
};
};
};
/** Alphabetical listing of all series, podcasts and umbrella seasons that are not excluded from search results in given category. Categories correspond to those in pages-api, including 'alt-innhold'. For the category 'podcast', all podcasts are listed, also those excluded from search results. */
/**
* List all series, podcast and umbrella seasons in category
* @description Alphabetical listing of all series, podcasts and umbrella seasons that are not excluded from search results in given category. Categories correspond to those in pages-api, including 'alt-innhold'. For the category 'podcast', all podcasts are listed, also those excluded from search results.
*/
RadioListAllForCategory: {
parameters: {
path: {
category: string;
};
query: {
query?: {
take?: number;
skip?: number;
};
path: {
category: string;
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": components["schemas"]["categoriesResponse"];
};
};
/** Category not found */
/** @description Category not found */
404: {
content: {
"text/plain": unknown;
@ -473,28 +540,41 @@ export interface operations {
};
};
};
/** Search endpoint for `internal use only`. Searches series and episodes. */
/**
* Internal search
* @description Search endpoint for `internal use only`. Searches series and episodes.
*/
InternalSearch: {
parameters: {
query: {
/** The query text */
/**
* @description The query text
* @example stanghelle
*/
q: string;
/** Defaults to 10 if not set */
/**
* @description Defaults to 10 if not set
* @example 10
*/
take?: number;
/** Defaults to `desc` if not set */
/**
* @description Defaults to `desc` if not set
* @example asc
*/
sort?: string;
/** options `series` or `episode` */
/**
* @description options `series` or `episode`
* @example series
*/
type?: string;
};
};
responses: {
/** OK */
/** @description OK */
200: {
content: {
"application/json": (
| components["schemas"]["episodesearchintresult"]
| components["schemas"]["seriessearchintresult"]
)[];
"application/json":
(components["schemas"]["episodesearchintresult"] | components["schemas"]["seriessearchintresult"])[];
};
};
};

View File

@ -1,37 +1,31 @@
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 { external as playbackComponents } from "./nrk-playback.ts";
type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
type PodcastEpisodes = catalogComponents["schemas"]["EpisodesHalResource"];
type Podcast = catalogComponents["schemas"]["SeriesHalResource"];
type PodcastEpisodesSingle = catalogComponents["schemas"]["EpisodeHalResource"];
export type Serie = catalogComponents["schemas"]["SeriesViewModel"];
type _OriginalEpisode = catalogComponents["schemas"]["EpisodeHalResource"];
export type OriginalEpisode = _OriginalEpisode & { url: string };
export type OriginalEpisode = PodcastEpisodesSingle & { url: string };
export type PodcastEpisode = catalogComponents["schemas"]["PodcastEpisodeHalResource"];
export type SearchResultList = searchComponents["schemas"]["seriesResult"]["results"];
export type SearchResult = ArrayElement<SearchResultList> & {
description?: string;
};
/* Incomplete manifest types */
interface Manifest {
id: string;
playable: {
endSequenceStartTime: null;
duration: string;
assets: {
url: string;
format: string;
mimeType: string;
encrypted: boolean;
}[];
};
}
type Manifest = playbackComponents["schemas/playback-channel.json"]["components"]["schemas"]["PlayableManifest"];
const nrkAPI = `https://psapi.nrk.no`;
async function withDownloadLink(
episode: _OriginalEpisode,
episode: PodcastEpisodesSingle,
): Promise<OriginalEpisode> {
// getting stream link
const [playbackStatus, playbackResponse] = await get<Manifest>(
`https://psapi.nrk.no/playback/manifest/podcast/${episode.episodeId}`,
`${nrkAPI}/playback/manifest/podcast/${episode.episodeId}`,
);
if (playbackStatus === OK && playbackResponse) {
@ -45,23 +39,22 @@ export const nrkRadio = {
search: async (query: string): Promise<SearchResultList> => {
const [status, response] = await get<
searchComponents["schemas"]["searchresult"]
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
>(`${nrkAPI}/radio/search/search?q=${query}`);
if (status === OK && response) {
return response.results.series?.results;
} else {
throw `Something went wrong with ${query} - got status ${status}`;
}
throw `Something went wrong with ${query} - got status ${status}`;
},
getSerieData: async (seriesId: string) => {
const [
[episodeStatus, episodeResponse],
[seriesStatus, serieResponse],
] = await Promise.all([
get<catalogComponents["schemas"]["EpisodesHalResource"]>(
`https://psapi.nrk.no/radio/catalog/podcast/${seriesId}/episodes`,
get<PodcastEpisodes>(
`${nrkAPI}/radio/catalog/podcast/${seriesId}/episodes`,
),
get<catalogComponents["schemas"]["SeriesHalResource"]>(
`https://psapi.nrk.no/radio/catalog/podcast/${seriesId}`,
get<Podcast>(
`${nrkAPI}/radio/catalog/podcast/${seriesId}`,
),
]);
@ -76,17 +69,15 @@ export const nrkRadio = {
...serieResponse.series,
episodes,
};
} else {
throw `Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`;
}
throw `Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`;
},
getEpisode: async (seriesId: string, episodeId: string): Promise<OriginalEpisode | null> => {
const url = `https://psapi.nrk.no/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
const [status, episode] = await get<OriginalEpisode>(url);
if (status !== OK) {
throw `Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`;
getEpisode: async (seriesId: string, episodeId: string): Promise<PodcastEpisode | null> => {
const url = `${nrkAPI}/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
const [status, episode] = await get<PodcastEpisode>(url);
if (status === OK && episode) {
return episode;
}
return episode;
throw `Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`;
},
};

View File

@ -1,12 +1,19 @@
import { FreshContext } from "$fresh/server.ts";
import { parse, toSeconds } from "https://esm.sh/iso8601-duration@2.1.1";
import { nrkRadio, OriginalEpisode } from "../../../../../lib/nrk.ts";
import { nrkRadio, PodcastEpisode } from "../../../../../lib/nrk.ts";
// TODO: This type `OriginalEpisode` is missing stuff.
function toChapters(episode: OriginalEpisode) {
type Chapter = {
title: string | undefined;
startTime: number | undefined;
};
function toChapters(episode: PodcastEpisode): Chapter[] | null {
if (!episode.indexPoints) {
return null;
}
return episode.indexPoints.map((indexPoint) => ({
title: indexPoint.title,
startTime: toSeconds(parse(indexPoint.startPoint)),
startTime: indexPoint.startPoint ? toSeconds(parse(indexPoint.startPoint)) : undefined,
}));
}