@ibaraki-douji/youtube
TypeScript icon, indicating that this package has built-in type declarations

1.3.4 • Public • Published

YouTube

Simple YouTube scrapper for everyone

Getting started

npm i @ibaraki-douji/youtube --save

Usage

Import the lib

const YouTube = require('@ibaraki-douji/youtube').YouTube

Search

const YouTube = require('@ibaraki-douji/youtube').YouTube

YouTube.search("rick roll", "video").then(console.log)
YouTube.search("John Doe", "channel").then(console.log)
YouTube.search("rick roll", "playlist").then(console.log)

First parameter is the query
Second parameter is the type of search (Optionnal : default = video).

Get All Video information

const YouTube = require('@ibaraki-douji/youtube').YouTube

YouTube.getVideoInformations({
    url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}).then(console.log);

You can have all information about the video + streaming infos

Get All Channel information

const YouTube = require('@ibaraki-douji/youtube').YouTube

YouTube.getChannelInformations({
    url: "https://www.youtube.com/channel/UCYLNVyL_PjgLvTgJ2h-ixtw"
}).then(console.log)

There is a lot of information here like the 30 last videos, last created playlists, the RSS url for new videos and more...

Get All Playlist information

const YouTube = require('@ibaraki-douji/youtube').YouTube

YouTube.getPlaylistInformations({
    url: "https://www.youtube.com/playlist&list=PLjiPh7vdm10JBUJ4mZcQu2PCGJeYy4X09"
}).then(console.log)

You have name, last update, videoCount, 100 first videos

Downaloader

Import the lib

const Downloader = require("@ibaraki-douji/youtube").Downloader;

Download video

const Downloader = require("@ibaraki-douji/youtube").Downloader;
const YouTube = require('@ibaraki-douji/youtube').YouTube

(async () => {
    const video = await YouTube.getVideoInformations({
        url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    });
    Downloader.downloadVideo(video, "1080", "./my/path.mp4", (stdout) => {
        console.log(stdout)
    })
})()

1080 is the quality of the video. It can be "2160" | "1440" | "1080" | "720" | "480" | "360" | "240" | "144".
./my/path.mp4 is the location of the file.
The las one is a function to the current text of the conversion (to remove it just put (s)=>{})

Download Audio

const Downloader = require("@ibaraki-douji/youtube").Downloader;
const YouTube = require('@ibaraki-douji/youtube').YouTube

(async () => {
    const video = await YouTube.getVideoInformations({
        url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    });
    Downloader.downloadAudio(video, "./my/path.mp4", (stdout) => {
        console.log(stdout)
    })
})()

./my/path.mp4 is the location of the file.
The las one is a function to the current text of the conversion (to remove it just put (s)=>{})

Download Playlist Videos

const Downloader = require("@ibaraki-douji/youtube").Downloader;
const YouTube = require('@ibaraki-douji/youtube').YouTube

(async () => {
    const playlist = await YouTube.getPlaylistInformations({
        url: "https://www.youtube.com/playlist&list=PLjiPh7vdm10JBUJ4mZcQu2PCGJeYy4X09"
    });
    Downloader.downloadPlaylistVideo(playlist, "1080", "./my/path", (stdout) => {
        console.log(stdout)
    })
})()

1080 is the quality of the video. It can be "2160" | "1440" | "1080" | "720" | "480" | "360" | "240" | "144".
./my/path is the location of the folder, All the videos goes inside with the title.
The las one is a function to the current text of the conversion (to remove it just put (s)=>{})

Download Playlist Audios

const Downloader = require("@ibaraki-douji/youtube").Downloader;
const YouTube = require('@ibaraki-douji/youtube').YouTube

(async () => {
    const playlist = await YouTube.getPlaylistInformations({
        url: "https://www.youtube.com/playlist&list=PLjiPh7vdm10JBUJ4mZcQu2PCGJeYy4X09"
    });
    Downloader.downloadPlaylistAudio(playlist, "./my/path", (stdout) => {
        console.log(stdout)
    })
})()

./my/path is the location of the folder, All the videos goes inside with the title.
The las one is a function to the current text of the conversion (to remove it just put (s)=>{})

Function alternative

I aslo implement a function fully Typed to have a simple view

    //VIDEO
    Downloader.download(video, quality, path, stdout);
    //AUDIO
    Downloader.download(video, path, stdout);
    //VIDEO PLAYLIST
    Downloader.download(playlist, quality, path, stdout);
    //AUDIO PLAYLIST
    Downloader.download(playlist, path, stdout);

Exemple

const YouTube = require('@ibaraki-douji/youtube').YouTube

// MAKE A ASYNC FUNCTION AT START
(async () => {
    const search = await YouTube.search("rick roll");
    const RR = await YouTube.getVideoInformations(search.res[0]);
    const stream = RR.streams[0]
    console.log("Good quality video : " + stream.url);
})()

More Help and Support

Discord : https://discord.gg/mD9c4zP4Er

Ask me what you want in the Discord server

Package Sidebar

Install

npm i @ibaraki-douji/youtube

Weekly Downloads

0

Version

1.3.4

License

ISC

Unpacked Size

75.5 kB

Total Files

25

Last publish

Collaborators

  • ibaraki-douji