refactor: extract processFeedUrl function

This commit is contained in:
2025-06-04 15:12:28 +09:00
committed by Satsuki Akiba (aider)
parent 91f0f23442
commit 8490e383ac

View File

@ -24,7 +24,6 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
async function main() { async function main() {
const parser = new Parser<FeedItem>();
const feedUrlsFile = import.meta.env["FEED_URLS_FILE"] ?? "feed_urls.txt"; const feedUrlsFile = import.meta.env["FEED_URLS_FILE"] ?? "feed_urls.txt";
const feedUrlsPath = path.resolve(__dirname, "..", feedUrlsFile); const feedUrlsPath = path.resolve(__dirname, "..", feedUrlsFile);
let feedUrls: string[]; let feedUrls: string[];
@ -41,6 +40,18 @@ async function main() {
// フィードごとに処理 // フィードごとに処理
for (const url of feedUrls) { for (const url of feedUrls) {
try {
await processFeedUrl(url);
} finally {
await updatePodcastRSS();
}
}
console.log("処理完了:", new Date().toISOString());
}
const processFeedUrl = async (url: string) => {
const parser = new Parser<FeedItem>();
const feed = await parser.parseURL(url); const feed = await parser.parseURL(url);
// フィードのカテゴリ分類 // フィードのカテゴリ分類
@ -78,10 +89,7 @@ async function main() {
// トピックごとの統合音声生成 // トピックごとの統合音声生成
const feedUrlHash = crypto.createHash("md5").update(url).digest("hex"); const feedUrlHash = crypto.createHash("md5").update(url).digest("hex");
const categoryHash = crypto const categoryHash = crypto.createHash("md5").update(category).digest("hex");
.createHash("md5")
.update(category)
.digest("hex");
const uniqueId = `${feedUrlHash}-${categoryHash}`; const uniqueId = `${feedUrlHash}-${categoryHash}`;
const audioFilePath = await generateTTS(uniqueId, podcastContent); const audioFilePath = await generateTTS(uniqueId, podcastContent);
@ -129,12 +137,7 @@ async function main() {
continue; continue;
} }
} }
};
await updatePodcastRSS();
}
console.log("処理完了:", new Date().toISOString());
}
main().catch((err) => { main().catch((err) => {
console.error("エラー発生:", err); console.error("エラー発生:", err);