Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The yt-search npm package is a simple and efficient tool for searching YouTube videos, channels, and playlists. It provides an easy-to-use interface for fetching YouTube search results and metadata.
Search for Videos
This feature allows you to search for YouTube videos based on a query string. The code sample demonstrates how to search for videos related to 'Node.js tutorial' and log the results.
const ytSearch = require('yt-search');
async function searchVideos(query) {
const result = await ytSearch(query);
return result.videos;
}
searchVideos('Node.js tutorial').then(videos => {
console.log(videos);
});
Search for Channels
This feature allows you to search for YouTube channels based on a query string. The code sample demonstrates how to search for channels related to 'Tech channels' and log the results.
const ytSearch = require('yt-search');
async function searchChannels(query) {
const result = await ytSearch(query);
return result.channels;
}
searchChannels('Tech channels').then(channels => {
console.log(channels);
});
Search for Playlists
This feature allows you to search for YouTube playlists based on a query string. The code sample demonstrates how to search for playlists related to 'Music playlists' and log the results.
const ytSearch = require('yt-search');
async function searchPlaylists(query) {
const result = await ytSearch(query);
return result.playlists;
}
searchPlaylists('Music playlists').then(playlists => {
console.log(playlists);
});
Get Video Details
This feature allows you to get detailed information about a specific YouTube video using its video ID. The code sample demonstrates how to fetch and log details for the video with ID 'dQw4w9WgXcQ'.
const ytSearch = require('yt-search');
async function getVideoDetails(videoId) {
const result = await ytSearch({ videoId });
return result;
}
getVideoDetails('dQw4w9WgXcQ').then(video => {
console.log(video);
});
The youtube-search package provides similar functionality for searching YouTube videos. It allows you to search for videos and retrieve metadata, but it may require an API key for access, unlike yt-search which does not.
The ytsr package is another alternative for searching YouTube content. It offers more advanced search capabilities and filtering options compared to yt-search, but it also requires more configuration.
The simple-youtube-api package provides a more comprehensive interface for interacting with the YouTube Data API. It supports searching for videos, channels, and playlists, as well as managing YouTube resources, but it requires an API key.
simple youtube search API and CLI
npm install yt-search # local module usage
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 }` )
} )
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
https://runkit.com/talmobi/runkit-npm-yt-search-basic
const video = await yts( { videoId: '_4Vt0UGwmgQ' } )
console.log( video.title + ` (${ video.duration.timestamp })` )
Philip Glass. - Koyaanisqatsi (original version) (3:29)
https://runkit.com/talmobi/runkit-npm-yt-search-video
const list = await yts( { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' } )
console.log( 'playlist title: ' + list.title )
list.videos.forEach( function ( video ) {
console.log( video.title )
} )
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
https://runkit.com/talmobi/runkit-npm-yt-search-playlist
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.
FAQs
search youtube
The npm package yt-search receives a total of 141,286 weekly downloads. As such, yt-search popularity was classified as popular.
We found that yt-search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.