feat: read feed URLs from file
This commit is contained in:
@ -16,3 +16,6 @@ PODCAST_LANGUAGE=ja
|
|||||||
PODCAST_AUTHOR=管理者
|
PODCAST_AUTHOR=管理者
|
||||||
PODCAST_CATEGORIES=Technology
|
PODCAST_CATEGORIES=Technology
|
||||||
PODCAST_TTL=60
|
PODCAST_TTL=60
|
||||||
|
|
||||||
|
# フィードURL一覧ファイルの設定
|
||||||
|
FEED_URLS_FILE=feed_urls.txt
|
||||||
|
@ -12,9 +12,28 @@ interface FeedItem {
|
|||||||
contentSnippet?: string;
|
contentSnippet?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const parser = new Parser<FeedItem>();
|
const parser = new Parser<FeedItem>();
|
||||||
const feedUrls = ["https://example.com/feed1.rss"];
|
const feedUrlsFile = process.env.FEED_URLS_FILE ?? "feed_urls.txt";
|
||||||
|
const feedUrlsPath = path.resolve(__dirname, "..", feedUrlsFile);
|
||||||
|
let feedUrls: string[];
|
||||||
|
try {
|
||||||
|
const data = await fs.readFile(feedUrlsPath, "utf-8");
|
||||||
|
feedUrls = data
|
||||||
|
.split("\n")
|
||||||
|
.map((url) => url.trim())
|
||||||
|
.filter((url) => url.length > 0);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`フィードURLファイルの読み込みに失敗: ${feedUrlsFile}`);
|
||||||
|
feedUrls = [];
|
||||||
|
}
|
||||||
|
|
||||||
for (const url of feedUrls) {
|
for (const url of feedUrls) {
|
||||||
const feed = await parser.parseURL(url);
|
const feed = await parser.parseURL(url);
|
||||||
@ -29,7 +48,7 @@ async function main() {
|
|||||||
pub.getMonth() === yesterday.getMonth() &&
|
pub.getMonth() === yesterday.getMonth() &&
|
||||||
pub.getDate() === yesterday.getDate()
|
pub.getDate() === yesterday.getDate()
|
||||||
) {
|
) {
|
||||||
const already = await markAsProcessed(url, item['id'] as string);
|
const already = await markAsProcessed(url, item["id"] as string);
|
||||||
if (already) continue;
|
if (already) continue;
|
||||||
|
|
||||||
const scriptText = await openAI_GenerateScript({
|
const scriptText = await openAI_GenerateScript({
|
||||||
@ -37,10 +56,13 @@ async function main() {
|
|||||||
link: item.link ?? "",
|
link: item.link ?? "",
|
||||||
contentSnippet: item.contentSnippet ?? "",
|
contentSnippet: item.contentSnippet ?? "",
|
||||||
});
|
});
|
||||||
const audioFilePath = await generateTTS(item['id'] as string, scriptText);
|
const audioFilePath = await generateTTS(
|
||||||
|
item["id"] as string,
|
||||||
|
scriptText,
|
||||||
|
);
|
||||||
|
|
||||||
await saveEpisode({
|
await saveEpisode({
|
||||||
id: item['id'] as string,
|
id: item["id"] as string,
|
||||||
title: item.title ?? "",
|
title: item.title ?? "",
|
||||||
pubDate: pub.toISOString(),
|
pubDate: pub.toISOString(),
|
||||||
audioPath: audioFilePath,
|
audioPath: audioFilePath,
|
||||||
|
Reference in New Issue
Block a user