Skip to content

servatj/supdata-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supadata API Wrapper

A Node.js wrapper for the Supadata API v1, designed for fetching web content and generating YouTube video transcripts.

supdata.ai is a Web & YouTube to text API for makers

Features

  • Simple API client for all Supadata endpoints
  • Promise-based interface with proper error handling
  • TypeScript-friendly JSDoc comments
  • Examples for common use cases

Installation

# Clone the repository
git clone https://github.com/servatj/supadata-api-client.git

# Navigate to the directory
cd supadata-api-client

# Install dependencies
npm install

# Copy and edit the environment variables
cp .env.example .env
# Edit the .env file with your API key

Or if you're using it as a package:

npm install supadata-api-client

Configuration

Create a .env file in the root directory with your Supadata API key:

SUPADATA_API_KEY=your_api_key_here

Basic Usage

const SupadataClient = require('supadata-api-wrapper');

// Initialize the client with your API key
const client = new SupadataClient('your_api_key_here');

// Or load from environment variables
// const client = new SupadataClient(process.env.SUPADATA_API_KEY);

// Example: Get a YouTube video transcript
async function getTranscript() {
  try {
    const transcript = await client.getTranscript('dQw4w9WgXcQ');
    console.log(transcript);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

getTranscript();

API Reference

Initialization

const client = new SupadataClient(apiKey, options);

Parameters:

  • apiKey (string, required): Your Supadata API key
  • options (object, optional):

Methods

YouTube Transcript

// Get transcript for a YouTube video
const transcript = await client.getTranscript('videoId');

// Translate a YouTube video transcript
const translatedTranscript = await client.translateTranscript('videoId', 'targetLanguage');

Web Content

// Get content from a URL
const content = await client.getUrlContent('https://example.com', options);

// Map a website structure
const siteMap = await client.mapWebsite('https://example.com', options);

// Start a website crawl
const crawlJob = await client.crawlWebsite('https://example.com', options);

// Get crawl results
const crawlResults = await client.getCrawlResult('jobId');

YouTube Data

// Get YouTube video data
const video = await client.getVideo('videoId');

// Get YouTube channel data
const channel = await client.getChannel('channelId');

// Get YouTube playlist data
const playlist = await client.getPlaylist('playlistId');

// Get videos from a channel
const channelVideos = await client.getChannelVideos('channelId', options);

// Get videos from a playlist
const playlistVideos = await client.getPlaylistVideos('playlistId', options);

API Status

// Check if your API key is valid
const status = await client.checkApiKey();

Error Handling

The client includes enhanced error handling that provides meaningful error messages:

try {
  const transcript = await client.getTranscript('invalid_video_id');
} catch (error) {
  console.error(error.message); // Formatted error message
  console.error(error.status);  // HTTP status code if available
  console.error(error.data);    // Error response data if available
}

Examples

Check the examples directory for more usage examples:

# Run the basic usage example
node examples/basic-usage.js transcript dQw4w9Wg

Testing

This package includes comprehensive unit tests using Jest. To run the tests:

npm test

This will run all tests and generate a coverage report in the coverage directory. </rewritten_file>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published