diff --git a/scripts/build-rss.ts b/scripts/build-rss.ts index ef96612..68d4c16 100644 --- a/scripts/build-rss.ts +++ b/scripts/build-rss.ts @@ -143,7 +143,7 @@ function generateRSSFeed(episodes: PodcastEpisode[], trailers: PodcastTrailer[], ${episode.duration ? formatDurationForRSS(episode.duration) : '00:00'} ${episode.explicit ? 'yes' : 'no'} ${episode.imageUrl ? `` : ''} - ${transcriptUrl ? `` : ''} + ${transcriptUrl ? `` : ''} ${chaptersUrl ? `` : ''} ${episode.content ? `` : ''} ${episode.value && episode.value.enabled && episode.value.recipients && episode.value.recipients.length > 0 ? @@ -219,8 +219,9 @@ function eventToPodcastEpisode(event: NostrEvent): PodcastEpisode { publishDate = new Date(event.created_at * 1000); } - // Extract transcript URL from tag + // Extract transcript URL and optional MIME type from tag const transcriptUrl = tags.get('transcript')?.[0]; + const transcriptType = tags.get('transcript')?.[1] || 'text/plain'; // Extract chapters URL from tag const chaptersUrl = tags.get('chapters')?.[0]; @@ -257,6 +258,7 @@ function eventToPodcastEpisode(event: NostrEvent): PodcastEpisode { videoType, imageUrl, transcriptUrl, + transcriptType, chaptersUrl, duration, episodeNumber, diff --git a/src/hooks/usePublishEpisode.ts b/src/hooks/usePublishEpisode.ts index 05b405e..4bfd9b3 100644 --- a/src/hooks/usePublishEpisode.ts +++ b/src/hooks/usePublishEpisode.ts @@ -8,6 +8,19 @@ import { PODCAST_KINDS, isPodcastCreator } from '@/lib/podcastConfig'; import { usePodcastConfig } from '@/hooks/usePodcastConfig'; import { addOP3Prefix } from '@/lib/op3Utils'; +/** Infer transcript MIME type from file extension (File.type is unreliable for .srt) */ +function inferTranscriptMime(filename: string, fileType: string): string { + const ext = filename.split('.').pop()?.toLowerCase(); + const mimeMap: Record = { + srt: 'application/x-subrip', + vtt: 'text/vtt', + json: 'application/json', + html: 'text/html', + txt: 'text/plain', + }; + return mimeMap[ext ?? ''] || fileType || 'text/plain'; +} + /** * Hook for publishing podcast episodes (creator only) */ @@ -94,10 +107,12 @@ export function usePublishEpisode() { // Upload transcript file if provided let transcriptUrl = episodeData.transcriptUrl; + let transcriptType = episodeData.transcriptType; if (episodeData.transcriptFile) { try { const transcriptTags = await uploadFile(episodeData.transcriptFile); transcriptUrl = transcriptTags[0][1]; + transcriptType = inferTranscriptMime(episodeData.transcriptFile.name, episodeData.transcriptFile.type); } catch (error) { throw new Error(`Failed to upload transcript file: ${error instanceof Error ? error.message : 'Unknown error'}`); } @@ -172,9 +187,11 @@ export function usePublishEpisode() { tags.push(['season', episodeData.seasonNumber.toString()]); } - // Add transcript URL if provided + // Add transcript URL and MIME type if provided if (transcriptUrl) { - tags.push(['transcript', transcriptUrl]); + transcriptType + ? tags.push(['transcript', transcriptUrl, transcriptType]) + : tags.push(['transcript', transcriptUrl]); } // Add chapters URL if provided @@ -309,10 +326,12 @@ export function useUpdateEpisode() { // Upload transcript file if provided let transcriptUrl = episodeData.transcriptUrl; + let transcriptType = episodeData.transcriptType; if (episodeData.transcriptFile) { try { const transcriptTags = await uploadFile(episodeData.transcriptFile); transcriptUrl = transcriptTags[0][1]; + transcriptType = inferTranscriptMime(episodeData.transcriptFile.name, episodeData.transcriptFile.type); } catch (error) { throw new Error(`Failed to upload transcript file: ${error instanceof Error ? error.message : 'Unknown error'}`); } @@ -415,9 +434,11 @@ export function useUpdateEpisode() { tags.push(['season', episodeData.seasonNumber.toString()]); } - // Add transcript URL if provided + // Add transcript URL and MIME type if provided if (transcriptUrl) { - tags.push(['transcript', transcriptUrl]); + transcriptType + ? tags.push(['transcript', transcriptUrl, transcriptType]) + : tags.push(['transcript', transcriptUrl]); } // Add chapters URL if provided diff --git a/src/types/podcast.ts b/src/types/podcast.ts index 8f70212..6df8e21 100644 --- a/src/types/podcast.ts +++ b/src/types/podcast.ts @@ -21,6 +21,7 @@ export interface PodcastEpisode { tags: string[]; // Transcript and chapters as URL references transcriptUrl?: string; + transcriptType?: string; // MIME type (e.g. 'application/x-subrip', 'text/vtt') chaptersUrl?: string; guests?: PodcastGuest[]; externalRefs?: ExternalReference[]; @@ -187,6 +188,7 @@ export interface RSSItem { image?: string; // Transcript and chapters as URL references transcriptUrl?: string; + transcriptType?: string; // MIME type (e.g. 'application/x-subrip', 'text/vtt') chaptersUrl?: string; funding?: Array<{ url: string;