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

Add YouTube video caption tool and related stories/tests #149

Closed

Conversation

elkernel128
Copy link

@elkernel128 elkernel128 commented Nov 14, 2024

Description

This pull request introduces the YouTube Video Caption Tool to the KaibanJS project. This tool extracts video captions from YouTube videos using the YouTube Data API and youtube-captions-scraper.

Changes

  • Added the YouTubeVideoCaption class in index.js.
  • Implemented functionality to fetch and process captions for a given YouTube video ID.
  • Defined the input schema using Zod for validation.

Requirements

  1. YouTube API Token

    • You need an API token to authenticate requests to the YouTube Data API.
    • This token should be passed when creating an instance of the YouTubeVideoCaption class.
  2. Input Parameters

    • The tool requires a single input parameter:
      • videoId: A string representing the ID of the YouTube video from which you want to extract captions.

Example Usage

import { YouTubeVideoCaption } from './index.js';

// Create an instance of the tool with the required API token
const youtubeCaptionTool = new YouTubeVideoCaption({ token: 'YOUR_YOUTUBE_API_TOKEN' });

// Define the input parameter
const input = {
  videoId: 'VIDEO_ID_HERE',
};

// Call the tool to extract captions
youtubeCaptionTool._call(input).then((captions) => {
  console.log(captions);
}).catch((error) => {
  console.error(error);
});

Checklist

  • Added YouTubeVideoCaption class.
  • Implemented caption extraction functionality.
  • Defined input schema using Zod.
  • Added unit tests for the new tool.
  • Verified that all tests pass.

How to Test

  1. Clone the repository and navigate to the project directory.
  2. Install dependencies: npm install
  3. Run tests: npm run test
  4. Verify that the YouTubeVideoCaption tool works as expected by following the usage instructions in the updated README.md file.

Copy link
Contributor

@darielnoel darielnoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check minor details

constructor(fields) {
super(fields);
this.token = fields.token;
this.name = 'youtube_video_caption';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to call the tool: youtube-captions-scraper

this.schema = z.object({
videoId: z
.string()
.describe('The ID of the YouTube video to extract captions from.'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the Youtube url instead of the video id.

@@ -1,2 +1,3 @@
export * from './firecrawl/index.js';
export * from './tavily/index.js';
export * from './youtube-video-caption/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is best to call the tool: youtube-captions-scraper

import { HTTPError } from 'ky';
import { getSubtitles } from 'youtube-captions-scraper';

export class YouTubeVideoCaption extends Tool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is best to call the tool: youtube-captions-scraper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LEt's use for the name of the file tool.stories.jsx

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use for the name of the file

LEt's use for the name of the file tool.test.js

@darielnoel
Copy link
Contributor

Don't forget to add the Tool basic doc to the Readme

https://github.com/kaiban-ai/KaibanJS/blob/main/packages/tools/README.md

@darielnoel darielnoel added this to the v0.10.0 milestone Nov 14, 2024
@darielnoel darielnoel modified the milestones: v0.10.0, v0.11.0 Nov 16, 2024
@anthonydevs17
Copy link
Collaborator

Guide: Obtain YouTube API Authorization Token Without Custom Credentials

This guide will help you get a YouTube API authorization token for testing purposes using Google’s OAuth 2.0 Playground without requiring a Client ID and Client Secret.

Step 1: Access OAuth 2.0 Playground
  • Go to the OAuth 2.0 Playground.
  • This tool allows you to interact with Google APIs and generate authorization tokens.
Step 2: Select YouTube API Scopes
  • Look for the YouTube Data API scopes in Step 1 of the Playground.
  • Choose the appropriate scopes depending on the API actions you want to test:
    • https://www.googleapis.com/auth/youtube: Full access to manage YouTube account.
    • https://www.googleapis.com/auth/youtube.readonly: Read-only access to YouTube account.
    • https://www.googleapis.com/auth/youtube.force-ssl: Allows uploading, managing, and retrieving video content securely, including captions.
Step 3: Authorize the APIs
  • Click the "Authorize APIs" button.
  • A Google sign-in page will appear:
    • Sign in with your Google account.
    • Grant the requested permissions.
Step 4: Exchange Authorization Code for Tokens
  • After successful authorization, go to Step 2 of the Playground.
  • Click the "Exchange authorization code for tokens" button.
  • The Playground will generate:
    • Access Token: Use this token to make API requests.
    • (Optional) Refresh Token: If available, use this to get a new access token when the current one expires.
Step 5: Test API Requests
  • Use Step 3 of the Playground to test API requests directly:
    1. Enter the YouTube API endpoint (e.g., https://www.googleapis.com/youtube/v3/videos).
    2. Add required parameters and headers.
    3. Use the generated access token for authentication.
Limitations
  • Short-lived Access Token: The token typically expires in 1 hour.
  • Default Credentials Restrictions: Some advanced API features may not be accessible.
  • No Persistent Refresh Token: A new authorization process might be needed for extended testing.
Recommendation for Advanced Testing

For more comprehensive testing, create your own project in the Google Cloud Console and obtain a Client ID and Client Secret to fully unlock the YouTube API features.

@anthonydevs17
Copy link
Collaborator

Implement with different approach soon...

@darielnoel darielnoel removed this from the v0.11.0 milestone Dec 6, 2024
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