diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index 966f3ac5..f5973519 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -30,6 +30,7 @@ import { } from '../services/reactionService' import AuthorCard from './AuthorCard' import { faBooks } from '../icons/customIcons' +import { extractYouTubeId, getYouTubeMeta } from '../services/youtubeMetaService' import { classifyUrl } from '../utils/helpers' import { buildNativeVideoUrl } from '../utils/videoHelpers' @@ -92,6 +93,8 @@ const ContentPanel: React.FC = ({ const [showVideoMenu, setShowVideoMenu] = useState(false) const articleMenuRef = useRef(null) const videoMenuRef = useRef(null) + const [ytMeta, setYtMeta] = useState<{ title?: string; description?: string; transcript?: string } | null>(null) + const [showTranscript, setShowTranscript] = useState(false) const { renderedHtml: renderedMarkdownHtml, previewRef: markdownPreviewRef, processedMarkdown } = useMarkdownToHTML(markdown, relayPool) const { finalHtml, relevantHighlights } = useHighlightedContent({ @@ -149,6 +152,21 @@ const ContentPanel: React.FC = ({ // Track external video duration (in seconds) for display in header const [videoDurationSec, setVideoDurationSec] = useState(null) + // Load YouTube metadata/captions when applicable + useEffect(() => { + (async () => { + try { + if (!selectedUrl) return setYtMeta(null) + const id = extractYouTubeId(selectedUrl) + if (!id) return setYtMeta(null) + const locale = navigator?.language?.split('-')[0] || 'en' + const data = await getYouTubeMeta(id, locale) + if (data) setYtMeta({ title: data.title, description: data.description, transcript: data.transcript }) + } catch { + setYtMeta(null) + } + })() + }, [selectedUrl]) const formatDuration = (totalSeconds: number): string => { const hours = Math.floor(totalSeconds / 3600) @@ -367,9 +385,9 @@ const ContentPanel: React.FC = ({ )} = ({ onDuration={(d) => setVideoDurationSec(Math.floor(d))} /> + {ytMeta?.transcript && ( +
+ + {showTranscript && ( +
+ {ytMeta.transcript} +
+ )} +
+ )}