Skip to content

Latest commit

 

History

History
124 lines (97 loc) · 3.06 KB

README-template.md

File metadata and controls

124 lines (97 loc) · 3.06 KB

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

%f_search%
output
%f_search_output%

single video

%f_video%
output
%f_video_output%

single playlist

%f_playlist%
output
%f_playlist_output%

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.