### Setup Project Source: https://github.com/supadata-ai/js/blob/main/example/README.md Navigates to the example directory and installs project dependencies using npm. ```bash cd example\nnpm install ``` -------------------------------- ### Run Example Source: https://github.com/supadata-ai/js/blob/main/example/README.md Starts the Supadata JS SDK example project after setup. ```bash npm start ``` -------------------------------- ### Run SDK in Watch Mode Source: https://github.com/supadata-ai/js/blob/main/example/README.md Executes the SDK in development watch mode for continuous updates. ```bash npm run dev ``` -------------------------------- ### Install Supadata JS SDK Source: https://github.com/supadata-ai/js/blob/main/README.md Installs the Supadata JavaScript SDK using npm. This is the first step to integrate Supadata's data scraping and processing capabilities into your project. ```bash npm install @supadata/js ``` -------------------------------- ### Get Transcript from URL Source: https://github.com/supadata-ai/js/blob/main/README.md Fetches a transcript from a given URL (e.g., YouTube, TikTok, Instagram, Twitter) or a file. Supports optional language and text formatting. For large files, it returns a job ID for asynchronous processing. ```typescript import { TranscriptOrJobId, } from '@supadata/js'; // Get transcript from any supported platform (YouTube, TikTok, Instagram, Twitter) or file const transcriptResult: TranscriptOrJobId = await supadata.transcript({ url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', lang: 'en', // optional text: true, // optional: return plain text instead of timestamped chunks mode: 'auto', // optional: 'native', 'auto', or 'generate' }); // Check if we got a transcript directly or a job ID for async processing if ('jobId' in transcriptResult) { // For large files, we get a job ID and need to poll for results console.log(`Started transcript job: ${transcriptResult.jobId}`); // Poll for job status const jobResult = await supadata.transcript.getJobStatus( transcriptResult.jobId ); if (jobResult.status === 'completed') { console.log('Transcript:', jobResult.result); } else if (jobResult.status === 'failed') { console.error('Transcript failed:', jobResult.error); } else { console.log('Job status:', jobResult.status); // 'queued' or 'active' } } else { // For smaller files, we get the transcript directly console.log('Transcript:', transcriptResult); } ``` -------------------------------- ### Initialize Supadata Client Source: https://github.com/supadata-ai/js/blob/main/README.md Demonstrates how to initialize the Supadata client with your API key. This client instance is used to interact with Supadata's services for data retrieval and processing. ```typescript import { Supadata, } from '@supadata/js'; // Initialize the client const supadata = new Supadata({ apiKey: 'YOUR_API_KEY', }); ``` -------------------------------- ### YouTube Transcript and Metadata Operations Source: https://github.com/supadata-ai/js/blob/main/README.md Provides methods to retrieve YouTube transcripts, translate them, fetch video and channel metadata, and list video IDs from channels or playlists. Supports batch processing for multiple video IDs. ```typescript import { Transcript, YoutubeVideo, YoutubeChannel, YoutubePlaylist, VideoIds, TranscriptOrJobId, } from '@supadata/js'; // Get YouTube transcript const transcript: Transcript = await supadata.youtube.transcript({ url: 'https://youtu.be/dQw4w9WgXcQ', }); // Translate YouTube transcript const translated: Transcript = await supadata.youtube.translate({ videoId: 'dQw4w9WgXcQ', lang: 'es', }); // Get a YouTube Video metadata const video: YoutubeVideo = await supadata.youtube.video({ id: 'dQw4w9WgXcQ', // can be url or video id }); // Get a YouTube channel metadata const channel: YoutubeChannel = await supadata.youtube.channel({ id: 'https://youtube.com/@RickAstleyVEVO', // can be url, channel id, handle }); // Get a list of video IDs from a YouTube channel const channelVideos: VideoIds = await supadata.youtube.channel.videos({ id: 'https://youtube.com/@RickAstleyVEVO', // can be url, channel id, handle type: 'all', // 'video', 'short', 'live', 'all' limit: 10, }); // Get the metadata of a YouTube playlist const playlist: YoutubePlaylist = await supadata.youtube.playlist({ id: 'PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI', // can be url or playlist id }); // Get a list of video IDs from a YouTube playlist const playlistVideos: VideoIds = await supadata.youtube.playlist.videos({ id: 'https://www.youtube.com/playlist?list=PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc', // can be url or playlist id limit: 10, }); // Start a YouTube transcript batch job const transcriptBatch: TranscriptOrJobId = await supadata.youtube.transcript.batch({ videoIds: ['dQw4w9WgXcQ', 'xvFZjo5PgG0'], // playlistId: 'PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc' // alternatively // channelId: 'UC_9-kyTW8ZkZNDHQJ6FgpwQ' // alternatively lang: 'en', }); console.log(`Started transcript batch job: ${transcriptBatch.jobId}`); // Start a YouTube video metadata batch job const videoBatch = await supadata.youtube.video.batch({ videoIds: ['dQw4w9WgXcQ', 'xvFZjo5PgG0', 'L_jWHffIx5E'], // playlistId: 'PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc' // alternatively // channelId: 'UC_9-kyTW8ZkZNDHQJ6FgpwQ' // alternatively }); console.log(`Started video batch job: ${videoBatch.jobId}`); // Get results for a batch job (poll until status is 'completed' or 'failed') const batchResults = await supadata.youtube.batch.getBatchResults( transcriptBatch.jobId ); // or videoBatch.jobId if (batchResults.status === 'completed') { console.log('Batch job completed:', batchResults.results); console.log('Stats:', batchResults.stats); } else { console.log('Batch job status:', batchResults.status); } ``` -------------------------------- ### Web Scraping and Crawling Source: https://github.com/supadata-ai/js/blob/main/README.md Enables scraping content from a specific web page, mapping website URLs, and crawling entire websites with configurable limits. It also provides functionality to retrieve the results of crawl jobs. ```typescript import { Scrape, Map, JobId, CrawlJob, } from '@supadata/js'; // Scrape web content const webContent: Scrape = await supadata.web.scrape('https://supadata.ai'); // Map website URLs const siteMap: Map = await supadata.web.map('https://supadata.ai'); // Crawl website const crawl: JobId = await supadata.web.crawl({ url: 'https://supadata.ai', limit: 10, }); // Get crawl job results const crawlResults: CrawlJob = await supadata.web.getCrawlResults(crawl.jobId); ``` -------------------------------- ### Handle SupadataError in TypeScript Source: https://github.com/supadata-ai/js/blob/main/README.md Demonstrates how to catch SupadataError exceptions when interacting with the Supadata API. It shows how to access specific error properties like `error`, `message`, `details`, and `documentationUrl` for robust error management. ```typescript import { SupadataError } from '@supadata/js'; try { const transcript = await supadata.youtube.transcript({ videoId: 'INVALID_ID', }); } catch (e) { if (e instanceof SupadataError) { console.error(e.error); // e.g., 'video-not-found' console.error(e.message); // Human readable error message console.error(e.details); // Detailed error description console.error(e.documentationUrl); // Link to error documentation (optional) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.