Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drkain/scrape-youtube
A lightning fast package to scrape YouTube search results
https://github.com/drkain/scrape-youtube
bot discord maintainer-wanted movie nodejs npm playlist scrape search video youtube
Last synced: 21 days ago
JSON representation
A lightning fast package to scrape YouTube search results
- Host: GitHub
- URL: https://github.com/drkain/scrape-youtube
- Owner: DrKain
- License: mit
- Created: 2018-09-25T02:59:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-31T21:35:23.000Z (6 months ago)
- Last Synced: 2024-10-17T08:34:07.633Z (about 1 month ago)
- Topics: bot, discord, maintainer-wanted, movie, nodejs, npm, playlist, scrape, search, video, youtube
- Language: JavaScript
- Homepage:
- Size: 178 KB
- Stars: 111
- Watchers: 9
- Forks: 29
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [![scrape-youtube](https://raw.githubusercontent.com/DrKain/scrape-youtube/master/text-logo.png)](#)
[![Version](https://img.shields.io/npm/v/scrape-youtube.svg)](https://www.npmjs.com/package/scrape-youtube)
[![Downloads](https://img.shields.io/npm/dt/scrape-youtube)](https://www.npmjs.com/package/scrape-youtube)
[![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/DrKain/scrape-youtube/wiki)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/DrKain/scrape-youtube/graphs/commit-activity)
[![License: MIT](https://img.shields.io/github/license/DrKain/scrape-youtube)](https://github.com/DrKain/scrape-youtube/blob/master/LICENSE)> A lightning fast package to scrape YouTube search results. This was made for Discord Bots.
## Install
```sh
npm install scrape-youtube --save
```## Example
```javascript
import { youtube } from 'scrape-youtube';
// const { youtube } = require('scrape-youtube');youtube.search('Short Change Hero').then((results) => {
// Unless you specify a custom type you will only receive 'video' results
console.log(results.videos);
});
// or
const { videos } = await youtube.search('Short Change Hero');
```## Custom Types
Supported types are: `video`, `live`, `movie`, `channel`, `playlist` and `any`.
These types use the `sp` parameter. If you pass your own `sp` value it will overwrite the types. See the "[custom filters](https://github.com/DrKain/scrape-youtube/wiki#custom-filters)" section for more information.```javascript
youtube.search('lofi hip hop beats to relax/study to', { type: 'live' }).then((results) => {
console.log(results.streams);
});
```## Examples
Please see [the examples](https://github.com/DrKain/scrape-youtube/tree/master/examples) directory for examples on what data you will receive from each search.
Your IDE should have autocompletion that works with the interface files, but these are here just in case.If you want help using this in Discord Bot, please visit the [wiki page](https://github.com/DrKain/scrape-youtube/wiki/Discord-Bot) for TS/JS examples.
## Playlists
Please note that the "videos" listed in playlist responses will only contain 1-2 items. This is what is available from the search results.
If you wish to load an entire playlist, consider using [ytdl-core](https://npmjs.com/package/ytdl-core).## Custom Filters
You can pass `{ sp: 'ABC' }` as the second parameter to use custom filters like upload date, duration, features ect.
You will need to fetch the SP parameter yourself from youtube. Please see [this image](https://i.imgur.com/TdAbYaP.png) for an example.## Request Options
You can pass `{ request: { } }` as the second parameter to use a proxy, custom headers, agents ect.
See [http.request](https://nodejs.org/api/http.html#http_http_request_options_callback) for more information.```ts
const options = {
type: 'video',
request: {
headers: {
Cookie: 'PREF=f2=8000000',
'Accept-Language': 'de'
}
}
};youtube.search('Poets of the fall', options);
```For example, using `Cookie: 'PREF=f2=8000000'` will enable restricted mode to filter out videos with bad language or adult themes.
Additionally, `'Accept-Language': 'de'` will load YouTube in German, sometimes resulting in different titles and content responses.## Extra Info
You can use [ytdl-core](https://github.com/fent/node-ytdl-core) by [fent](https://github.com/fent) to load extra information like exact upload dates,
full descriptions, like/dislike ratio, video ads ect.
Please see [this](https://github.com/DrKain/scrape-youtube/wiki/Extra-Info) example in the wiki to see how.## Subscriber count
As mentioned in issue [#57](https://github.com/DrKain/scrape-youtube/issues/57) some channels appear to have the subscriber count hidden. In this case the package will default to 0.
## Handles
Channel handles will be used if available. Some channels do not have handles, if this is the case the channel link will use the old ID, EG: `/channel/12345` vs `/@user`
I recommend sticking to the ID as handles are unreliable.## Quick Info
- Multiple pages currently can not be loaded. This may change in the future, but currently you will be limited to 20 results.
- This package will only make **1** request per search, even when using `any` types.
- If this package stops working, please open an issue on GitHub. I will fix it within a day.## 👤 Author
This project was made by **Kain (ksir.pw)**
Feel free to contact me if you have any trouble with this package.- Website: [ksir.pw](https://ksir.pw)
- Github: [@DrKain](https://github.com/DrKain)
- Discord: drkain## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/DrKain/scrape-youtube/issues).## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2018 [Kain (ksir.pw)](https://github.com/DrKain).
This project is [MIT](https://github.com/DrKain/scrape-youtube/blob/master/LICENSE) licensed.