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-search

v2.12.1

Published

search youtube

Downloads

579,577

Readme

npm npm npm mac ubuntu windows

yt-search

simple youtube search API and CLI

Installation

npm install yt-search # local module usage

Easy to use

const yts = require( 'yt-search' )
const r = await yts( 'superman theme' )

const videos = r.videos.slice( 0, 3 )
videos.forEach( function ( v ) {
	const views = String( v.views ).padStart( 10, ' ' )
	console.log( `${ views } | ${ v.title } (${ v.timestamp }) | ${ v.author.name }` )
} )
output
  38878009 | Superman Theme (4:13) | Super Man
   8861479 | Superman • Main Theme • John Williams (4:26) | HD Film Tributes
   7802473 | Superman - Main Theme (BBC Proms) (4:46) | brassbone player
try it

https://runkit.com/talmobi/runkit-npm-yt-search-basic

single video

const video = await yts( { videoId: '_4Vt0UGwmgQ' } )
console.log( video.title + ` (${ video.duration.timestamp })` )
output
Philip Glass. -  Koyaanisqatsi (original version) (3:29)
try it

https://runkit.com/talmobi/runkit-npm-yt-search-video

single playlist

const list = await yts( { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' } )

console.log( 'playlist title: ' + list.title )
list.videos.forEach( function ( video ) {
	console.log( video.title )
} )
output
playlist title: Superman Themes
The Max Fleischer Cartoon (From "Superman")
[Deleted video]
Superman Theme
[Private video]
Superman The Animated Series Full Theme
Smallville theme song
Reprise / Fly Away
Superman Doomsday Soundtrack- Main Title
Hans Zimmer - Man of Steel Theme
Supergirl CW Soundtrack - Superman Theme Extended
try it

https://runkit.com/talmobi/runkit-npm-yt-search-playlist

CLI Usage (interactive)

yt-search superman theme

If you have mpv installed, yt-search can directly play yt videos (or audio only)

yt-search-video Dank Memes Videos
yt-search-audio Wagner

If you don't have mpv installed, you can alternatively try installing yt-play-cli

npm install -g yt-play-cli

see: https://github.com/talmobi/yt-play

About

Simple function to get youtube search results.

Why

Not sure..

How

Using HTTP requests and parsing the results with cheerio.

CLI interactive mode with node-fzf

Options

var opts = { query: 'superman theme' }
yts( opts, function ( err, r ) {
	if ( err ) throw err
	console.log( r.videos ) // video results
	console.log( r.playlists ) // playlist results
	console.log( r.channels ) // channel results
	console.log( r.live ) // live stream results
} )

var opts = { videoId: 'e9vrfEoc8_g' }
yts( opts, function ( err, video ) {
	if ( err ) throw err
	console.log( video ) // single video metadata
} )

var opts = { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' }
yts( opts, function ( err, playlist ) {
	if ( err ) throw err
	console.log( playlist ) // single playlist metadata
	console.log( playlist.videos ) // playlist videos
} )

Alternatives

ytsr

Test

npm test

Development / Debugging

Modify debug.js by adding another mXX function and calling it at the top.

Run with the debug flag ex: DEBUG=1 node debug.js

The HTML response received by yt-search is written to dasu.response.

Prettify dasu.response for easier debugging ex: prettier --parser html -- save it as a temporary file so it's not overwritten when you call the debug fn again if necessary ex: pewdiepie.channel or superman.results

Most/all relevant data for parsing is found in the results inside the ytInitialData object.

We're using jsonpath-plus for resilient parsing of the ytInitialData object that is subject to continuous modifications by YouTube.