# YOUTUBE SEARCH & DOWNLOAD

![ytvanced](https://vancedyoutube.org/wp-content/uploads/2023/03/youtube-vanced-icon.png)

A YouTube Video downloader.

# HOW TO INSTALL?
```
npm i youtube-s-dl
```

# Require to export function
```js
//CommonJS
const {download, search, getStreamFormats, getVideoInfo} = require("youtube-s-dl");
```

## SIMPLE USAGE
### search and download videos
```js
const {download, search, getVideoInfo} = require("youtube-s-dl");

let result = await search("Senpai (feat. Hentai Dude)")
console.log(result)
let info = getVideoInfo(result[0].videoId)
console.log(info)
try{
    //download have 2 params. first is videoId required
    //2nd Format object is optional param. 
    format = {
        mimeType: 'video',
        qualityLabel: '480p',
        fps: 30
        //etc.
    }
    stream = await download(result[0].videoId, format)
    path = "./tmp/videoplayback.mp4"
    file = fs.createWriteStream(path)
    stream.pipe(file).on('finish',()=>{
	    console.log("Video Downloaded")
    }).on('close',()=>{
	    console.log("Request Finished")
    }).on('error',()=>{
	    console.log("Seems there's an error happened while writing the file.")
    })
}
catch(e){
    console.log(e)
}
```