Socket
Socket
Sign inDemoInstall

youtube-video-exists

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    youtube-video-exists

Checks if a YouTube video exists under the given ID. No API key is required.


Version published
Weekly downloads
53
increased by140.91%
Maintainers
1
Install size
411 kB
Created
Weekly downloads
 

Readme

Source

youtube-video-exists

NPM Coverage Status

Checks if a YouTube video exists under the given ID. No API key is required.

How does it work?

Firstly the video id is checked against a regular expression if it is in a valid format. When this check succedes the YouTube oEmbed API is used to see if a video is present under the given ID. This requires no API key and might be the best option to receive this information without one.

API

getVideoInfo

function getVideoInfo(id: string): Promise<VideoInfoResponse> {/** Code ommited **/}

Checks if a YouTube video exists under the given ID. When a video is found the return object also includes the title and author of the video

Parameters
  • id: string - YouTube video id
Returns
  • VideoInfoResponse when Promise is resolved
Example
const example = {
  existing: true,
  validId: true,
  private: false,
  info: {
    title: 'YouTube Developers Live: Embedded Web Player Customization',
    author: {
      name: 'Google Developers',
      url: 'https://www.youtube.com/user/GoogleDevelopers',
    },
  }
}
Throws
  • AxiosError when a network issue occurred

Usage

Check if the video exists

Async
getVideoInfo('M7lc1UVf-VE').then(value => {
    if (value.existing) console.log('Video exists!')
})
Blocked
async function example() {
    const existing = (await getVideoInfo('M7lc1UVf-VE')).existing
    if (existing) console.log('Video exists!')
}

Check if the video is private

Async
getVideoInfo('ZFxT6d13OKo').then(value => {
    if (value.existing && value.private) console.log('Video is private!')
})
Blocked
async function example() {
    const response = await getVideoInfo('ZFxT6d13OKo')
    if (response.existing && response.private) console.log('Video is private!')
}

License

Licensed under the MIT License.

Keywords

FAQs

Last updated on 07 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc