feat: generate unique filenames for audio files
This commit is contained in:
@ -3,6 +3,7 @@ import { openAI_GenerateScript } from "../services/llm";
|
|||||||
import { generateTTS } from "../services/tts";
|
import { generateTTS } from "../services/tts";
|
||||||
import { saveEpisode, markAsProcessed } from "../services/database";
|
import { saveEpisode, markAsProcessed } from "../services/database";
|
||||||
import { updatePodcastRSS } from "../services/podcast";
|
import { updatePodcastRSS } from "../services/podcast";
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
interface FeedItem {
|
interface FeedItem {
|
||||||
id: string;
|
id: string;
|
||||||
@ -51,16 +52,17 @@ async function main() {
|
|||||||
// Use item.id if available, otherwise generate fallback ID from title or link
|
// Use item.id if available, otherwise generate fallback ID from title or link
|
||||||
const itemId = item["id"] as string | undefined;
|
const itemId = item["id"] as string | undefined;
|
||||||
const fallbackId = item.link || item.title || JSON.stringify(item);
|
const fallbackId = item.link || item.title || JSON.stringify(item);
|
||||||
const finalItemId = itemId && typeof itemId === 'string' && itemId.trim() !== ''
|
const finalItemId =
|
||||||
|
itemId && typeof itemId === "string" && itemId.trim() !== ""
|
||||||
? itemId
|
? itemId
|
||||||
: `fallback-${Buffer.from(fallbackId).toString('base64')}`;
|
: `fallback-${Buffer.from(fallbackId).toString("base64")}`;
|
||||||
|
|
||||||
// Skip if even the fallback ID is missing (should be rare)
|
// Skip if even the fallback ID is missing (should be rare)
|
||||||
if (!finalItemId || finalItemId.trim() === '') {
|
if (!finalItemId || finalItemId.trim() === "") {
|
||||||
console.warn(`フィードアイテムのIDを生成できませんでした`, {
|
console.warn(`フィードアイテムのIDを生成できませんでした`, {
|
||||||
feedUrl: url,
|
feedUrl: url,
|
||||||
itemTitle: item.title,
|
itemTitle: item.title,
|
||||||
itemLink: item.link
|
itemLink: item.link,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -73,13 +75,16 @@ async function main() {
|
|||||||
link: item.link ?? "",
|
link: item.link ?? "",
|
||||||
contentSnippet: item.contentSnippet ?? "",
|
contentSnippet: item.contentSnippet ?? "",
|
||||||
});
|
});
|
||||||
const audioFilePath = await generateTTS(
|
|
||||||
item["id"] as string,
|
// Generate a unique filename using the feed URL hash and item ID
|
||||||
scriptText,
|
const feedUrlHash = crypto.createHash("md5").update(url).digest("hex");
|
||||||
);
|
const itemIdHash = crypto.createHash("md5").update(finalItemId).digest("hex");
|
||||||
|
const uniqueFilename = `${feedUrlHash}-${itemIdHash}.mp3`;
|
||||||
|
|
||||||
|
const audioFilePath = await generateTTS(uniqueFilename, scriptText);
|
||||||
|
|
||||||
await saveEpisode({
|
await saveEpisode({
|
||||||
id: item["id"] as string,
|
id: finalItemId,
|
||||||
title: item.title ?? "",
|
title: item.title ?? "",
|
||||||
pubDate: pub.toISOString(),
|
pubDate: pub.toISOString(),
|
||||||
audioPath: audioFilePath,
|
audioPath: audioFilePath,
|
||||||
|
Reference in New Issue
Block a user