Skip to content

Commit

Permalink
feat: fetchRssItems for custom script.
Browse files Browse the repository at this point in the history
Also fixed a little issue with duration parsing
  • Loading branch information
farfromrefug committed Oct 27, 2024
1 parent c26feec commit afae95e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
33 changes: 19 additions & 14 deletions generate/rss_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -136,8 +141,8 @@ async function getFolderWithUrlFromRssUrl(
]?.["@href"]
: imgUrl,
metadata: {
...metadata,
title: name,
...metadata,
...(opt.rssEpisodeNumbers
? {
episodeCount: items.length,
Expand Down
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 {
Expand All @@ -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 = [
Expand Down

0 comments on commit afae95e

Please sign in to comment.