JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q74359F
  • License MIT

TypeScript SDK for YouTube workflows

Package Exports

  • lyra-sdk
  • lyra-sdk/ai-tools
  • lyra-sdk/fmt
  • lyra-sdk/transcript
  • lyra-sdk/url

Readme

Lyra SDK

npm version License: MIT

A powerful TypeScript SDK for working with YouTube data. Fetch videos, channels, playlists, comments, and transcripts โ€” all with full type safety and zero dependencies.

๐ŸŒ Website ยท ๐Ÿ“š Docs


Installation

npm install lyra-sdk

Requires Node.js 22+ and a YouTube Data API v3 key.


Quick Start

import { yt } from 'lyra-sdk'

const client = yt(process.env.YOUTUBE_API_KEY!)

// Fetch a video
const video = await client.video(videoUrl)
console.log(video.title, video.viewsFmt)

// Fetch a channel by handle
const channelHandle = '@MrBeast'
const channel = await client.channel(channelHandle)
console.log(channel.name, channel.subscribersFmt)

// Fetch a full playlist
const playlist = await client.playlist(playlistUrl)
console.log(playlist.title, playlist.videoCount)

Fetch Video Transcript (No API Key)

import { transcribeVideo, toPlainText } from 'lyra-sdk/transcript'

const videoUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
const lines = await transcribeVideo(videoUrl)
console.log(toPlainText(lines)) // Full transcript as plain text

The transcript module uses YouTube's internal Innertube API โ€” no quota consumption, no API key.


Transcribe Playlist (Batch)

import { transcribePlaylist, InMemoryCache } from 'lyra-sdk'

const result = await transcribePlaylist(playlistUrl, {
  apiKey: process.env.YOUTUBE_API_KEY!,
  concurrency: 5,
  cache: new InMemoryCache(),
  onProgress(done, total, videoId, status) {
    console.log(`[${status}] ${done}/${total} โ€” ${videoId}`)
  },
})

console.log(`Succeeded: ${result.succeeded}, Failed: ${result.failed}`)

Features: concurrency control, smart caching, partial failure handling, range filtering.


Comments & Comment Threads

// Fetch all comment threads
const threads = await client.comments(videoUrl)

// Top comments by relevance
const top5 = await client.topComments(videoUrl, 5)

// All replies to a specific comment
const replies = await client.commentReplies(commentId)

// Search comments by keyword
const results = await client.searchComments(videoUrl, 'great song')

// Compute aggregate stats
const stats = client.commentStats(videoUrl, threads)
console.log(`Unique authors: ${stats.uniqueAuthors}`)

Playlist Query Builder

const result = await client
  .playlistQuery(playlistUrl)
  .filterByDuration({ min: 300 })
  .filterByViews({ min: 100_000 })
  .sortBy('views', 'desc')
  .between(1, 10)
  .execute()

URL Utilities & Formatting (No API Key)

import { parseURL, extractVideoId } from 'lyra-sdk/url'
import { formatNumber, formatDurationClock } from 'lyra-sdk/fmt'

parseURL(videoUrl)
formatNumber(1_763_613_349) // '1.8B'
formatDurationClock(214)    // '3:34'

Error Handling

import { NotFoundError, QuotaError } from 'lyra-sdk'

try {
  const video = await client.video('invalid-id')
} catch (err) {
  if (err instanceof NotFoundError) console.log('Video not found')
  if (err instanceof QuotaError) console.log('API quota exceeded')
}

Packages

Package Description
lyra-sdk Core SDK
lyra-sdk/url Standalone URL utilities (no API key)
lyra-sdk/fmt Standalone formatters (no API key)
lyra-sdk/transcript Transcript fetching (no API key for single videos)

Documentation

Full docs, API reference, and examples: docs.uselyra.xyz


License

MIT


If you find Lyra useful, please consider giving it a โญ on GitHub!