1.1.0 • Published 6 years ago

swaelos-youtube-validator v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

swaelos-youtube-validator

NodeJS module that validates whether a given URL or id are valid YouTube videos or not

how to install

npm install swaelos-youtube-validator

How does it work?

The string must begin with one of the following

www.  
http://www.  
https://www.  

then it must be followed by one of the following two middle parts (depending on the first)

youtube.com  
www.youtube.com  

This ensures that any URL passed in follows the correct format

Finally, the video ID is then checked against YouTube to make sure it exists

If the URL follows format, and there exists a video matching the ID then we have success

Here are some examples of strings that would pass this test

youtube.com/watch?v=MADvxFXWvwE  
www.youtube.com/watch?v=MADvxFXWvwE  
http://www.youtube.com/watch?v=MADvxFXWvwE  
https://www.youtube.com/watch?v=MADvxFXWvwE  
www.YOUTUBE.COM/watch?v=MADvxFXWvwE  
MADvxFXWvwE  

Here is an example of how to use the library to perform your own validations

var validator = require('swaelos-youtube-validator')  
var URL = 'https://www.youtube.com/watch?v=MADvxFXWvwE'  
validator.validateURL(URL, function(res, err)  
{  
    if(err)  
        console.log("the URL validation resulted in failure")  
    else  
        console.log("SUCCESS")  
})