youtube-video-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

YouTube Video Parser

Extract publicly available details related to a YouTube video

Installation

> npm install youtube-video-parser --save

OR

> yarn add youtube-video-parser

Usage

//Import library
import { YouTubeVideo } from 'youtube-video-parser';
 
//Get YouTube video id from url
const videoId = YouTubeVideo.getVideoId('https://www.youtube.com/watch?v=ogfYd705cRs');
 
//Get video details from videoId
const video = await YouTubeVideo.fetch(videoId);
 
/* video object will be in the structure
{
    videoId: string
    title: string
    duration: number
    keywords: Array<string>
    channelId: string
    thumbnails: Array<{
        url: string
        width: string
        height: string
        type: 'HighRes' | 'Default' | 'Other'
    }>
    author: string
    viewCount: number
    avgRating: number
    isLive: boolean
    caption: {
        tracks: Array<{
            url: string
            language: {
                code: string
                name: string
            }
            autoGenerated: boolean
            rtl: boolean
            captions(): Promise<Array<{ start: number, duration: number, text: string }>>
        }>
    }
    language: string
    streamingData: {
        expiresIn: number
        formats: Array<{
            itag: number
            url: string
            mimeType: {
                type: string
                codec: string
            }
            bitrate: number
            avgBitrate: number
            width: number
            height: number
            contentLength: number
            quality: string
            qualityLabel: string
            audioQuality: 'Low' | 'Medium' | 'High'
            audioSampleRate: number
            duration: number
            highReplication: boolean
        }>
        adaptiveFormats: Array<{
            itag: number
            url: string
            mimeType: {
                type: string
                codec: string
            }
            bitrate: number
            avgBitrate: number
            width: number
            height: number
            contentLength: number
            quality: string
            qualityLabel: string
            audioQuality: 'Low' | 'Medium' | 'High'
            audioSampleRate: number
            duration: number
            highReplication: boolean
            isVideoOnly: boolean
            isAudioOnly: boolean
            fps: number
        }>
    }
}
*/
 
//Get english language captions
const captionInfo = video.caption.tracks.find(track => track.language.code === 'en');
const captions = await captionInfo.captions();

Disclaimer

This library is developed for research and educational purpose. Please check YouTube's terms and conditions before using it in production.

Readme

Keywords

none

Package Sidebar

Install

npm i youtube-video-parser

Weekly Downloads

9

Version

1.0.4

License

ISC

Unpacked Size

25.5 kB

Total Files

7

Last publish

Collaborators

  • arjun_g