Skip to content

Add YouTube oEmbed support for link previews - #882

Merged
KallynGowdy merged 2 commits into
developfrom
claude/youtube-oembed-link-preview-r69t7g
Aug 28, 2026
Merged

KallynGowdy merged 2 commits into
developfrom
claude/youtube-oembed-link-preview-r69t7g

Conversation

@KallynGowdy

Copy link
Copy Markdown
Member

Summary

This PR adds specialized support for YouTube URLs in the link preview system by integrating YouTube's oEmbed endpoint, providing better metadata extraction for video content.

Key Changes

  • YouTube URL Detection: Added isYouTubeHostname() function and YOUTUBE_HOSTNAMES set to identify YouTube URLs across multiple domains (youtube.com, youtu.be, m.youtube.com, youtube-nocookie.com, etc.)
  • oEmbed Integration: Implemented _getYouTubeOEmbedData() method to fetch preview data from YouTube's oEmbed endpoint with proper schema validation using Zod
  • Schema Validation: Created YOUTUBE_OEMBED_SCHEMA using Zod to validate and type YouTube's oEmbed responses
  • Data Extraction: Added extractYouTubeOEmbedData() function to map oEmbed fields onto the standard LinkPreviewData format
  • Refactored Preview Logic: Extracted generic HTML scraping into _getGenericPreviewData() method and introduced PreviewDataResult type to handle both success and failure cases uniformly
  • Comprehensive Tests: Added extensive test coverage for YouTube URL detection, oEmbed endpoint integration, error handling, and caching behavior

Implementation Details

  • YouTube URLs are detected by hostname and routed to the oEmbed endpoint instead of generic HTML scraping
  • The oEmbed response is validated against a schema before use, returning unacceptable_url errors for invalid responses
  • Preview data is cached with the same TTL logic as generic previews, respecting cache-control headers
  • The implementation maintains backward compatibility with existing generic link preview functionality
  • All YouTube-specific code is properly exported for testing and reusability

https://claude.ai/code/session_01PCVUPdxNMWehtCNeGCmLXL

LinkPreviewController now detects youtube.com/youtu.be (and related host
variants) and fetches https://www.youtube.com/oembed?url={url}&format=json
instead of scraping the page's HTML, since YouTube's client-rendered pages
make OpenGraph scraping unreliable. The oEmbed response is validated with
zod before being mapped onto LinkPreviewData, and falls back to the same
caching/rate-limit/error-handling flow used by the generic HTML path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PCVUPdxNMWehtCNeGCmLXL
@CLAassistant

CLAassistant commented Aug 28, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ KallynGowdy
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

@KallynGowdy
KallynGowdy merged commit 353bdc7 into develop Aug 28, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants