npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

mebox-extractor

v0.0.5

Published

🎬 A powerful and type-safe video metadata extractor for YouTube and Bilibili platforms with full TypeScript support

Readme

🎬 mebox-extractor

A powerful and type-safe video metadata extractor for YouTube and Bilibili platforms with full TypeScript support

npm version TypeScript MIT License Node.js

✨ Features

  • 🎯 Simple API: One function to extract video metadata from multiple platforms
  • πŸ”’ Type Safe: Full TypeScript support with comprehensive type definitions
  • 🌐 Multi-Platform: Support for YouTube and Bilibili video platforms
  • πŸ“Ί Rich Metadata: Extract title, description, thumbnail, duration, subtitles, and download URLs
  • ⚑ Fast & Reliable: Built-in retry mechanism and error handling
  • πŸ“¦ Dual Package: Supports both ESM and CommonJS
  • πŸ§ͺ Well Tested: Comprehensive test suite with 66+ test cases
  • πŸ”§ Zero Config: Works out of the box with sensible defaults

Resolution Support

| Platform | 4K | 1080p | 720p | 360p | |----------|----|----|----|----| | YouTube | βœ… | βœ… | βœ… | βœ… | | Bilibili | ⚠️ | βœ… | βœ… | βœ… |

πŸš€ Quick Start

Installation

npm install mebox-extractor

Basic Usage

import { extract } from 'mebox-extractor'

// Extract YouTube video metadata
const metadata = await extract("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

console.log(metadata.title)       // Video title
console.log(metadata.duration)    // Duration in seconds
console.log(metadata.thumbnail)   // Thumbnail URL
console.log(metadata.downloadURL) // Download URL

πŸ“– Usage Examples

YouTube Videos

import { extract } from 'mebox-extractor'

// Standard YouTube URL
const youtubeMetadata = await extract("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

// YouTube Shorts
const shortsMetadata = await extract("https://youtu.be/dQw4w9WgXcQ")

// With custom options
const hdMetadata = await extract("https://www.youtube.com/watch?v=dQw4w9WgXcQ", {
  resolution: '1080p',
  cookies: {
    'session': 'your-session-cookie'
  }
})

Bilibili Videos

import { extract } from 'mebox-extractor'

// Bilibili video
const bilibiliMetadata = await extract("https://www.bilibili.com/video/BV1GJ411x7h7")

// With authentication for higher quality
const hqMetadata = await extract("https://www.bilibili.com/video/BV1GJ411x7h7", {
  resolution: '1080p',
  cookies: {
    'SESSDATA': 'your-sessdata-cookie'
  }
})

Error Handling

import { extract } from 'mebox-extractor'

try {
  const metadata = await extract("https://unsupported-site.com/video")
} catch (error) {
  if (error.message.includes('not supported')) {
    console.log('This platform is not supported')
  } else if (error.message.includes('video id is not found')) {
    console.log('Invalid video URL')
  }
}

πŸ“Š Response Format

The extract function returns a VideoMetadataSchema object:

interface VideoMetadataSchema {
  website: 'youtube' | 'bilibili'
  videoId: string              // Platform-specific video ID
  url: string                  // Original video URL
  downloadURL: string | [DownloadFormat, DownloadFormat]
  previewURL: string           // Preview/streaming URL
  fps: number                  // Frames per second
  title: string                // Video title
  description: string          // Video description
  thumbnail: string            // Thumbnail image URL
  duration: number             // Duration in seconds
  subtitles?: SubTitles        // Subtitle data (if available)
}

Download Formats

For Bilibili videos, downloadURL is an array with separate video and audio streams:

interface DownloadFormat {
  mimeType: string             // e.g., 'video/mp4', 'audio/mp4'
  url: string                  // Direct download URL
}

Subtitles

interface SubTitleItem {
  start: number                // Start time in seconds
  end: number                  // End time in seconds
  text: string                 // Subtitle text
}

type SubTitles = SubTitleItem[]

βš™οΈ Configuration Options

interface ExtractorOptions {
  resolution?: '4k' | '1080p' | '720p' | '360p'  // Preferred resolution
  cookies?: Record<string, string>                // Authentication cookies
}

Note: Higher resolutions may require authentication cookies.

πŸ” Authentication

YouTube

For private or age-restricted videos, provide session cookies:

const metadata = await extract(youtubeUrl, {
  cookies: {
    'session_token': 'your-session-token'
  }
})

Bilibili

For higher quality videos or member-only content:

const metadata = await extract(bilibiliUrl, {
  cookies: {
    'SESSDATA': 'your-sessdata-cookie',
    'buvid3': 'your-buvid3-cookie'
  }
})

πŸ› οΈ Advanced Usage

Using with Different Module Systems

ES Modules

import { extract } from 'mebox-extractor'

CommonJS

const { extract } = require('mebox-extractor')

TypeScript

import { extract, VideoMetadataSchema, ExtractorOptions } from 'mebox-extractor'

Utility Functions

The package also exports utility functions for URL analysis:

import { convertURLToWebsiteKey, getVideoIdByURL } from 'mebox-extractor'

// Check if URL is supported
const website = convertURLToWebsiteKey('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
console.log(website) // 'youtube'

// Extract video ID
const videoId = getVideoIdByURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
console.log(videoId) // 'dQw4w9WgXcQ'

πŸ”§ Development

Setup

git clone https://github.com/one2x/mebox-extractor.git
cd mebox-extractor
npm install

Scripts

npm run build        # Build the project
npm run test         # Run tests
npm run test:watch   # Run tests in watch mode
npm run test:coverage# Run tests with coverage
npm run typecheck    # Type checking
npm run dev          # Development mode with watch
npm run clean        # Clean build artifacts

Testing

The project includes comprehensive tests:

  • Unit Tests: 66+ test cases covering all functionality
  • Integration Tests: End-to-end testing with mocked data
  • Type Tests: TypeScript type checking and validation
npm test             # Run all tests
npm run test:coverage # Run with coverage report

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (npm test)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines

  • Type Safety: No any types allowed
  • Test Coverage: Add tests for new features
  • Documentation: Update README for API changes
  • Code Style: Follow TypeScript best practices and existing code patterns

πŸ“ Changelog

v0.0.1

  • ✨ Initial release
  • 🎯 Support for YouTube and Bilibili
  • πŸ”’ Full TypeScript support
  • πŸ“¦ ESM and CommonJS compatibility
  • πŸ§ͺ Comprehensive test suite
  • πŸ“š Complete documentation

πŸ› Troubleshooting

Common Issues

Module Import Errors

Error: Cannot use import statement outside a module
  • Solution: Use the CommonJS export (require) or ensure your project supports ES modules

Network Timeouts

  • The extractor includes automatic retry logic (3 attempts)
  • For persistent issues, check your network connection and any firewall restrictions

Rate Limiting

  • YouTube and Bilibili may rate limit requests
  • Consider adding delays between requests for bulk operations

πŸ“„ License

MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments