# scrape-yt

> Simple package to scrape information from youtube such as search results, video information, related videos, and up next video

Latest version **1.4.8** (published 2021-02-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install scrape-yt
pnpm add scrape-yt
yarn add scrape-yt
bun add scrape-yt
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.8 |
| Published | 2021-02-14 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 124.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Vincent Jonathan |
| Maintainers | vincentjonathan |
| Keywords | youtube, yt, scrape, scraper, webscraper, search, video, videos, playlist, channel, related |

## Links

- npm: https://www.npmjs.com/package/scrape-yt
- Repository: https://github.com/SuspiciousLookingOwl/scrape-yt
- Homepage: https://github.com/SuspiciousLookingOwl/scrape-yt#readme
- Issues: https://github.com/SuspiciousLookingOwl/scrape-yt/issues
- npm.io page: https://npm.io/package/scrape-yt

## Dependencies (2)

- [bent](https://npm.io/package/bent.md) ^7.3.0
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.3

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.4.8 (latest) — 2021-02-14
- 2.0.1-alpha.0 (alpha) — 2020-12-17
- 1.4.4-beta.0 (beta) — 2020-10-25
- 1.4.7 — 2020-12-09
- 1.4.6 — 2020-11-14
- 1.4.5 — 2020-11-13
- 1.4.3 — 2020-09-21
- 1.4.2 — 2020-08-31
- 1.4.1 — 2020-07-23
- 1.4.0 — 2020-07-03
- 1.3.3 — 2020-06-24
- 1.3.2 — 2020-06-14
- 1.2.4 — 2020-05-17
- 1.2.1 — 2020-05-16
- 1.2.0 — 2020-05-02
- … 7 more at https://npm.io/package/scrape-yt/versions

## README

# scrape-yt
[![NPM](https://nodei.co/npm/scrape-yt.png?downloads=true)](https://nodei.co/npm/scrape-yt)

`scarpe-yt` is a simple package to scrape information from Youtube such as search results, video information, related videos, playlist information, and up next video

#### APIs:
- [search](#searchquery-options)
- [getPlaylist](#getplaylistplaylistid-options)
- [getVideo](#getvideovideoid-options)
- [getRelated](#getrelatedvideoid-options)
- [getUpNext](#getupnextvideoid-options)

## Installation
```bash
npm i scrape-yt
```

## Usage Example
Basic usage:
```js
// ES5 
const scrapeYt = require("scrape-yt");

// ES6 / TypeScript
import scrapeYt from "scrape-yt";
// or import only necessary methods
import { search, getVideo } from "scrape-yt"

// Searches for video, playlist, or channel with keyword "Never gonna give you up" and limited to 10 search result
(async() => {
    let videos = await scrapeYt.search("Never gonna give you up");
    console.log(videos[0]);
})();

// Or use promises
scrapeYt.search("Never gonna give you up", {
    type: "video"
}).then(videos => {
    console.log(videos);
});

```

Type check (see available [types](https://github.com/VincentJonathan/scrape-yt/blob/master/src/common/types.ts)):
```js

import scrapeYt, { SearchOptions } from "scrape-yt";

let options: SearchOptions = {
    type: "channel",
    limit: 5
}
await scrapeYt.search("Rick astley", options); 

```

## API
### search(query, [options])
Searches for result with given `query`.  `options` is optional and can have the following keys
- `type` - Search type, can be `all`, `video`, `playlist` or `channel` (Default = `all`)
- `limit` - The max count of the search result (Default = `10`)
- `page` - Show result on specified page (Default = `1`)
- `useWorkerThread` - Whether to use worker thread for scraping or not (Default = `false`)

Result example (video):
```json
[
    {
        "id": "dQw4w9WgXcQ",
        "title": "Rick Astley - Never Gonna Give You Up (Video)",
        "duration": 213,
        "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg?sqp=-oaymwEjCPYBEIoBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLBW5JbJn5nTCNKe8PvMuOqEiuttiQ",
        "channel": {
            "id": "UCuAXFkgsw1L7xaCfnd5JJOw",
            "name": "Official Rick Astley",
            "url": "https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw"
        },
        "uploadDate": "10 tahun yang lalu",
        "viewCount": 680314160,
        "type": "video"
    },
    ...
]
```
Result example (playlist):
```json
[
    {
        "id": "PLx65qkgCWNJIgVrndMrhsedBz1VDp0kfm",
        "title": "Very Important Videos",
        "thumbnail": "https://i.ytimg.com/vi/0woboOZ9dmY/hqdefault.jpg?sqp=-oaymwEXCPYBEIoBSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLDcy1wd9LA-toJs7Gq-_I5-00n0Mw",
        "channel": {
            "id": "electrickeye91",
            "name": "Thomas Frank",
            "url": "https://www.youtube.com/user/electrickeye91"
        },
        "videoCount": 37,
        "type": "playlist"
    },
    ...
]
```
Result example (channel):
```json
[
    {
        "id": "beegeestv",
        "name": "beegees",
        "thumbnail": "https://lh3.googleusercontent.com/a-/AOh14Gh8qGEFRMCi1sYKrapMiXS3pcOsejBEGK9WAGQsgA=s176-c-k-c0x00ffffff-no-rj-mo",
        "videoCount": 55,
        "url": "https://www.youtube.com/user/beegeestv",
        "type": "channel"
    },
    ...
]
```


---
### getPlaylist(playlistId, [options])
Get playlist information and videos from the given `playlistId`. `options` is optional and can have the following keys
- `useWorkerThread` - Whether to use worker thread for scraping or not (Default = `false`)

Result example:
```json
{
    "id": "PLx65qkgCWNJIgVrndMrhsedBz1VDp0kfm",
    "title": "Very Important Videos",
    "videoCount": 37,
    "viewCount": 159705,
    "lastUpdatedAt": "Terakhir diperbarui pada 13 Okt 2019",
    "channel": {
        "id": "electrickeye91",
        "name": "Thomas Frank",
        "thumbnail": "https://yt3.ggpht.com/a/AATXAJyAUDbyAyY3JkoMO-7Pvvf4QtksJF9Y6C6fTg=s100-c-k-c0xffffffff-no-rj-mo",
        "url": "https://www.youtube.com/user/electrickeye91"
    },
    "videos": [
        {
            "id": "0woboOZ9dmY",
            "title": "Poopy-di Scoop",
            "duration": 17,
            "thumbnail": "https://i.ytimg.com/vi/0woboOZ9dmY/hqdefault.jpg?sqp=-oaymwEiCKgBEF5IWvKriqkDFQgBFQAAAAAYASUAAMhCPQCAokN4AQ==&rs=AOn4CLD-Z5XXZlfjshvyd3K-oYIkGo-0Rw",
            "channel": {
                "id": "UCwPDMtvphYeGbzDKa8obOnQ",
                "name": "Poorly Made",
                "url": "https://www.youtube.com/channel/UCwPDMtvphYeGbzDKa8obOnQ"
            }
        },
        ...
     ]
}
```
**Note**: `videos` only limited to 100

---
### getVideo(videoId, [options])
Get video information of given `videoId`. `options` is optional and can have the following keys
- `useWorkerThread` - Whether to use worker thread for scraping or not (Default = `false`)

Result example:
```json
{
    "id": "dQw4w9WgXcQ",
    "title": "Rick Astley - Never Gonna Give You Up (Video)",
    "duration": 212,
    "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
    "description": "Rick Astley's official music video for “Never Gonna Give You Up”...",
    "channel": {
        "id": "UCuAXFkgsw1L7xaCfnd5JJOw",
        "name": "Official Rick Astley",
        "thumbnail": "https://yt3.ggpht.com/a-/AOh14GirqtIADQGwQOF14rTXYeSzIkuySwxwlqAZyzo0mQ=s176-c-k-c0xffffffff-no-nd-rj",
        "url": "https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw"
    },
    "uploadDate": "Dipublikasikan tanggal 24 Okt 2009",
    "viewCount": 680735840,
    "likeCount": 5257356,
    "dislikeCount": 193590,
    "isLiveContent": false,
    "tags": [
        "#RickAstley",
        "#NeverGonnaGiveYouUp",
        "#DancePop"
    ]
}
```

---
### getRelated(videoId, [options])
Get videos related to given `videoId`. `options` is optional and can have the following keys
- `limit` - The max count of the search result (Default = `10`)
- `useWorkerThread` - Whether to use worker thread for scraping or not (Default = `false`)

Result example:
```json
[
    {
        "id": "I_izvAbhExY",
        "title": "Bee Gees - Stayin' Alive (Official Video)",
        "duration": 250,
        "thumbnail": "https://i.ytimg.com/vi/I_izvAbhExY/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLCEl-X_ZnGdzoLqS-wfFcs1rED1LQ",
        "channel": {
            "id": "UCD9sCcKXnFxMeuFoNayVxeQ",
            "name": "beegees",
            "url": "https://www.youtube.com/channel/UCD9sCcKXnFxMeuFoNayVxeQ"
        },
        "uploadDate": "10 tahun lalu",
        "viewCount": 530482048
    },
    ...
]
```

---
### getUpNext(videoId, [options])
Get up next video of given `videoId`. `options` is optional and can have the following keys
- `useWorkerThread` - Whether to use worker thread for scraping or not (Default = `false`)

Result example:
```json
{
    "id": "yPYZpwSpKmA",
    "channel": {
        "id": "UCuAXFkgsw1L7xaCfnd5JJOw",
        "name": "Official Rick Astley",
        "url": "https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw"
    },
    "title": "Rick Astley - Together Forever (Official Music Video)",
    "duration": 205,
    "thumbnail": "https://i.ytimg.com/vi/yPYZpwSpKmA/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLAIYA0llYwvjijecWwCYJgXMx6YWA",
    "uploadDate": "10 tahun lalu",
    "viewCount": 98107272
}

```
---
**Note**:
* `duration` is in second
* `uploadDate` and `lastUpdatedAt` language is based on  the default language the youtube set for you 


## License
[MIT](https://github.com/VincentJonathan/scrape-yt/blob/master/LICENSE)

---
_Source: https://npm.io/package/scrape-yt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
