2.2.0 • Published 2 years ago

yt-scraper v2.2.0

Weekly downloads
43
License
MIT
Repository
github
Last release
2 years ago

yt-scraper

Modern YouTube scraper capable of retrieving video and channel info.

Install

First install through NPM:

npm install yt-scraper

Then import into your project:

const ytScraper = require("yt-scraper")

Usage

All returned keys should be treated as optional and may suddenly stop working due to YouTube changes.

Video Info

ytScraper.videoInfo(videoUrl, options = {})

ArgumentTypeDescription
videoUrlString(www.)youtube.com and youtu.be links are accepted alongside simply providing the video ID without a url.
options.includeRawDataBoolraw key will contain JSON data provided by YouTube. Is false by default.
options.bypassIdCheckBoolMake the video request without verifying the ID, only works with a url provided. Is false by default.

Returns a Promise with the object described in the table below. Throws (see Errors below).

KeyTypeDescription
idStringID of the video.
urlStringURL of the video (https://www.youtube.com/watch?v=ID).
titleStringTitle of the video.
viewsNumberVideo views.
descriptionStringDescription of the video, will contain \n.
categoryStringCategory of the video.
lengthNumberLength of the video in seconds.
thumbnailsArray\<Thumbnail>Array of thumbnails, most likely contains at least one. Documentation can be found below.
liveBoolIs video a live stream
privacy.privateBoolIs video private.
privacy.unlistedBoolIs video unlisted.
privacy.familySafeBoolIs video family safe (deemed by YouTube).
privacy.availableCountriesArray\<String>Array of two letter capitalized country coded where video can be viewed (e.g. US). Note it can contain 150+ items.
dates.publishedDateVideo published video. May vary from upload date.
dates.uploadedDateVideo uploaded date. May vary from publish date.
streams.formatsArrayArray of video files that contain audio, may be lower quality than using adaptive formats.
streams.adaptiveFormatsArrayArray of video or audio files but the video files don't contain audio. Higher quality than traditional formats but video and audio must be assembled before playback.
rawObjectIf options.includeRawData is set to true then contains the raw object given by YouTube that is then parsed to get metadata.

Thumbnail

Thumbnails are provided by the YouTube API. Each thumbnail may represent the same image at a different size.

KeyTypeDescription
urlStringURL of the thumbnail, most likely a jpg.
widthNumberWidth of thumbnail.
heightNumberHeight of thumbnail.

Errors

Error NameDescription
YTScraperInvalidVideoURLAn invalid video url was provided.
YTScraperInvalidVideoIDAn invalid video id was provided. Can be bypassed for videoInfo method, check documentation.
YTScraperInvalidChannelIDAn invalid channel id was provided.
YTScraperInvalidChannelURLAn invalid channel url was provided.
YTScraperMissingDataThe webpage provided missing data and the scrape could not be completed.

Contributing

We heavily value contributions, if you would like to contribute please feel free to put in a pull request.

Contributors

  • Thanks to elBarkey for bug fixes and stability contributions in v1.
2.2.0

2 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

7 years ago