swift·rust

Showcase

Video

Drop a YouTube URL, get an embed. Auto-detected, privacy-preserving, zero JavaScript required from your bundle.

YouTube embed, auto-detected

The component inspects the URL, extracts the video ID, and switches to a privacy-preserving youtube-nocookie embed automatically. No provider config needed — paste, render, ship.

example.tsx
import { Video, isYouTubeUrl, getYouTubeId } from "swift-rust";

const url = "https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS";

// Responsive: a fixed-ratio wrapper, video fills 100%.
<div className="aspect-video w-full">
  <Video src={url} aspectRatio="16 / 9" className="h-full w-full rounded-xl" />
</div>

isYouTubeUrl(url);   // → true
getYouTubeId(url);   // → "rTJzsHwpZko"

Auto-detection in action

The same isYouTubeUrl helper that powers the Video component is exported from swift-rust. Try a few URLs against the live detector:

YouTubeisYouTubeUrl("https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS") → true
https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdSYouTube
https://www.youtube.com/watch?v=rTJzsHwpZkoYouTube
https://www.youtube.com/embed/rTJzsHwpZkoYouTube
https://www.youtube.com/shorts/rTJzsHwpZkoYouTube
https://example.com/clip.mp4
https://vimeo.com/76979871
not-a-url

Helper functions

Need to know what kind of URL you have, or build an embed URL yourself? These utilities are exported from swift-rust.

helpers.ts
import {
  isYouTubeUrl,
  getYouTubeId,
  detectProvider,
  getYouTubeEmbedUrl,
} from "swift-rust";

const url = "https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS";

isYouTubeUrl(url);                       // → true
getYouTubeId(url);                       // → "rTJzsHwpZko"
detectProvider(url);                     // → "youtube"
getYouTubeEmbedUrl("rTJzsHwpZko", { autoPlay: true, mute: true });
// → "https://www.youtube-nocookie.com/embed/rTJzsHwpZko?autoplay=1&mute=1"