Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetchRssItems for custom script. #37

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions generate/rss_parser.ts
Original file line number Diff line number Diff line change
@@ -67,12 +67,16 @@ async function getFolderWithUrlFromRssUrl(
opt: StudioPackGenerator,
): Promise<FolderWithUrlOrData[]> {
console.log(green(`→ url = ${url}`));

const resp = await fetch(url);
const xml = (await resp.text()).replace(/<\?xml-stylesheet [^>]+\?>/, "");
// @ts-ignore rss conv
// deno-lint-ignore no-explicit-any
const rss: Rss = (parse(xml).rss as any).channel;
let rss: Rss;
if (opt.customModule?.fetchRssItems) {
rss = await opt.customModule?.fetchRssItems(url, opt);
} else {
const resp = await fetch(url);
const xml = (await resp.text()).replace(/<\?xml-stylesheet [^>]+\?>/, "");
// @ts-ignore rss conv
// deno-lint-ignore no-explicit-any
rss = (parse(xml).rss as any).channel;
}
const metadata = {
title: rss.title,
description: rss.description,
@@ -83,13 +87,14 @@ async function getFolderWithUrlFromRssUrl(
const duration = i["itunes:duration"];
if (duration) {
return (
duration
.split(":")
.reduce(
(acc, val, index) =>
acc + Math.pow(60, 2 - index) * parseInt(val, 10),
0,
) >= opt.rssMinDuration
(typeof duration === "string"
? duration.split(":")
.reduce(
(acc, val, index) =>
acc + Math.pow(60, 2 - index) * parseInt(val, 10),
0,
)
: duration) >= opt.rssMinDuration
);
} else {
return true;
@@ -136,8 +141,8 @@ async function getFolderWithUrlFromRssUrl(
]?.["@href"]
: imgUrl,
metadata: {
...metadata,
title: name,
...metadata,
...(opt.rssEpisodeNumbers
? {
episodeCount: items.length,
6 changes: 5 additions & 1 deletion types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RssItem } from "./generate/rss_parser.ts";
import type { Rss, RssItem } from "./generate/rss_parser.ts";
import type { StudioPackGenerator } from "./studio_pack_generator.ts";

export interface CustomModule {
@@ -10,6 +10,10 @@ export interface CustomModule {
item: RssItem,
opt: StudioPackGenerator,
) => Promise<string>;
fetchRssItems?: (
url: string,
opt: StudioPackGenerator,
) => Promise<Rss>;
}

export const OPEN_AI_VOICES = [