youtube-video-parser
v1.0.4
Published
Extract publicly available details related to a YouTube video
Downloads
6
Readme
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.