Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove dependency on 3rd-party YouTube API for thumbnails and title #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kraj2503
Copy link

@kraj2503 kraj2503 commented Dec 23, 2024

YouTube Thumbnail Integration and Next.js Configuration Updates

Overview

This PR updates the YouTube video integration by switching from the YouTube Search API to the oEmbed API for video details, adds support for YouTube thumbnails, and updates the Next.js configuration for image domains.

Changes Made

API Integration Changes

  • Replaced YouTube Search API with YouTube oEmbed API for video details:
const res = await axios.get(
  `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${videoId}&format=json`
);
  • Updated video metadata parsing:
    • Title: res.data.title ?? "Can't find video"
    • Thumbnail: https://img.youtube.com/vi/${videoId}/mqdefault.jpg

UI Component Updates

  • Replaced LiteYouTubeEmbed with native Image component for thumbnails:
{inputLink && !loading && (() => {
  const match = inputLink.match(YT_REGEX);
  if (match) {
    const extractedId = match[1];
    return (
      <div className="mt-4">
        <Image
          src={`https://img.youtube.com/vi/${extractedId}/maxresdefault.jpg`}
          alt="Thumbnail"
          width={480}
          height={320}
        />
      </div>
    );
  }
})()}

Next.js Configuration Updates

  • Updated next.config.js to include img.youtube.com in allowed image domains:
images: {
  domains: ['images.unsplash.com', 'i.ytimg.com', 'img.youtube.com'],
}

Benefits

  • Reduced API dependencies by using oEmbed
  • Improved thumbnail loading performance
  • More reliable video metadata fetching
  • Better error handling for missing video data

@kraj2503 kraj2503 marked this pull request as draft December 23, 2024 20:16
@kraj2503 kraj2503 marked this pull request as ready for review December 23, 2024 20:26
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.

1 participant