forked from distubejs/ytdl-core
-
Notifications
You must be signed in to change notification settings - Fork 5
API Documentation
YBD Project edited this page Oct 6, 2024
·
6 revisions
This document describes how to use ytdl-core and how to best use it.
To use it, you need to install @ybd-project/ytdl-core
from any location. The following uses npm, but you can use yarn or whatever.
npm install @ybd-project/ytdl-core@latest
Once installed, import using require
for JavaScript (Node.js) or import
for TypeScript.
/* For JS */
const { YtdlCore } = require('@ybd-project/ytdl-core');
/* For TS */
import { YtdlCore } from '@ybd-project/ytdl-core';
Warning
All of the following code follows the above introduction and assumes that the YtdlCore
class has been imported.
The most basic use of @ybd-project/ytdl-core
is to create class instances. Here is an example.
Tip
The instance can also be specified with options that will be the default options for functions to be executed thereafter. If the option is specified again for the function to be executed, it will take precedence.
/* Most basic use */
const ytdl = new YtdlCore();
ytdl.getBasicInfo('https://www.youtube.com/watch?v=ID');
/* ↑ This `getBasicInfo` function is executed without options. */
/* You can specify default options */
const ytdl = new YtdlCore({
lang: 'en',
...
});
ytdl.getBasicInfo('https://www.youtube.com/watch?v=ID');
/* ↑ This `getBasicInfo` function is executed with the option `lang: 'en'`. */
ytdl.getBasicInfo('https://www.youtube.com/watch?v=ID', {
lang: 'ja',
...
});
/* ↑ This `getBasicInfo` function is executed with the option `lang` overridden from `en` to `ja`. */