1.0.1 • Published 4 years ago
youtube-parser2 v1.0.1
Youtube Video Parser
A util to extract raw video-URLs and format information from a YouTube-video page.
Install
$ npm install -g youtube-parser2Usage
Promise getVideoData(string url)params:
- url - YouTube video page.
const ytParser = require('youtube-parser2');
ytParser.getVideoData("https://www.youtube.com/watch?v=8uQqaauS5UA")
.then(function (youtubeVideoData) {
console.log(youtubeVideoData);
})
.catch(function (error) {
console.log(error);
})return value - A promise object to resolve with YoutubeVideoData object.
YoutubeVideoData Object
Fields
- metadata - youtube video information
- isPlayable - is video availeable to play
- playabilityStatus - video playability status
- videos - list of all
YoutubeVideoobjects. Sorted byrawData.contentLengthfield in ascending order.
YoutubeVideoData example:
YoutubeVideoData {
metadata: {
videoId: 'videoId',
title: 'Video Title',
lengthSeconds: '123',
keywords: [Array],
channelId: 'channelId',
isOwnerViewing: false,
shortDescription: "...",
isCrawlable: true,
thumbnail: [Object],
averageRating: 4.22,
allowRatings: true,
viewCount: '123123123',
author: 'YT User',
isPrivate: false,
isUnpluggedCorpus: false,
isLiveContent: false
},
isPlayable: false,
playabilityStatus: {
status: 'UNPLAYABLE',
reason: 'Video unavailable'
},
videos: [YoutubeVideo]
}Methods
- getAudioOnlyList() - list of
YoutubeVideoobjects that consists of only a audio track - getVideoWithAudioList() - list of
YoutubeVideoobjects that consists of track with video and audio - getVideoOnlyList() - list of
YoutubeVideoobjects that consists of only a video track
All YoutubeVideo lists sorted by rawData.contentLength field in ascending order. So, if you want to get the lowest quality, just take the first item in the list. For the highest quality, take the last one.
YoutubeVideo Object
Fields
- rawData - raw video information
- url - direct link to the video file
- quality - video quality
- isAudioOnly - file consists only a audio track
- isVideoOnly - file consists only a video track
- qualityLabel - video quality label
YoutubeVideo example:
YoutubeVideo {
rawData: [Object],
url: 'https://.....',
quality: 'medium',
isAudioOnly: false,
isVideoOnly: true,
qualityLabel: '360p'
}