simple youtube search API and CLI
npm install yt-search # local module usage
%f_search%
%f_search_output%
%f_video%
%f_video_output%
%f_playlist%
%f_playlist_output%
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
Simple function to get youtube search results.
Not sure..
Using HTTP requests and parsing the results with cheerio.
CLI interactive mode with node-fzf
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
} )
npm test
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.