scrape-youtube

A lightning fast package to scrape YouTube search results. This was made for Discord Bots.

Usage no npm install needed!

<script type="module">
  import scrapeYoutube from 'https://cdn.skypack.dev/scrape-youtube';
</script>

README

scrape-youtube">

Version Downloads Documentation Maintenance License: MIT

A lightning fast package to scrape YouTube search results. This was made for Discord Bots.

Install

npm install scrape-youtube --save

Example

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);
});

Custom Types

Supported types are: video, live, movie, channel, playlist and any

youtube.search('lofi hip hop beats to relax/study to', { type: 'live' }).then((results) => {
    console.log(results.streams);
});

Examples

Please see the 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 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.

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 for an example.

Request Options

You can pass { requestOptions: { } } as the second parameter to use a proxy, custom headers, agents ect.
See http.request for more information.

const options = {
    requestOptions: {
        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 by fent to load extra information like exact upload dates, full descriptions, like/dislike ratio, video ads ect.
Please see this example in the wiki to see how.

Debugging

In some cases advanced debugging might be required for fixing issues on GitHub.
When enabled each search will create 3 files, please compress/zip and include with your issue.
It's not recommended to use this unless requested specifically.

youtube.debug = true; // Enable regular debugging
youtube.debugger.enabled = true; // Enable debug dumps
youtube.debugger.setDirectory('path/to/somewhere'); // Directory to write the dumps

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.

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2018 Kain (ksir.pw). This project is MIT licensed.