npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yt-playlist-scraper

v1.2.1

Published

Package that retrieves the videos in a youtube playlist without an API key.

Downloads

58

Readme

If your project has the ability to use a Youtube API key I recommend using yt-playlists instead.

YT-PLAYLIST-SCRAPER

This is a utility for getting the data of videos in a youtube playlist. I made it for my yt_mp3 project, which at first used yt-playlists but keeping the API key hidden turned into a hassle.

Installing

npm i yt-playlist-scraper -s

Using

const playlists = require("yt-playlist-scraper")
playlists("PLc1l1_YXYDH4BoWto9Mds2aaL_bn1lAG_")
.then(playListData => {
	// Do whatever you want
})

Output

You can refer to the example_output.json file to see an example of the data this package outputs.

How this scraper works

The following text does not include getting through the cookie consent barrier. Although the currently implementation is fairly straightforward I still want to do more research in finding a more efficient way.

Initial request

First this scraper makes a request to https://www.youtube.com/playlist?list=$ID, but this is already where it gets tricky, because there are 2 possible responses for that request. Only when requesting with a User-Agent header set will youtube respond the same way as it does in the browser, we need this response because it contains a piece of json (an object called ytInitialData) inside the html which we can parse to get all the video data without having to rely on the HTML itself. This however only fetches us the first 100 videos

Fetching more

Sinds version 1.1.0 of this package the method of fetching more entries has changed. Now the last entry of the array of videos is a continuationItemRenderer instead of a playlistVideoRenderer. This contains the continuation token. To get another 100 videos you can then use the token in a POST request to https://www.youtube.com/youtubei/v1/browse. The searchparams should contain an api key (I am using a static one currently, because I am unsure where to retrieve it) and the POST data should contain the continuation token and an object called context with a lot of properties.