Noteworthy Programming Masterpiece

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

    0.1.2 • Public • Published

    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.

    Install

    npm i youtube-video-exists

    DownloadsWeekly Downloads

    181

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    25.6 kB

    Total Files

    14

    Last publish

    Collaborators

    • matthiasschwarz