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

@hssoftvn/yt-search-api

v1.0.9

Published

Node.js easy to get Youtube results by provided keywords, no Login or API key required!

Downloads

42

Readme

Youtube Search API

Youtube Search API is an API for getting Youtube search results.

Installation

npm install @hssoftvn/yt-search-api

Usage (import)

const ytSearchApi = require("@hssoftvn/yt-search-api");

1. SearchVideosByKeyword (Promise)

Search YouTube videos by the keyword

const SearchVideosByKeyword: (keyword: any, lang?: any, country?: any, withPlaylist?: any, limit?: any, options?: any) => Promise<{
    items: any[];
    nextPage: {
        nextPageToken: null;
        nextPageContext: {
            context: null;
            continuation: {};
        };
    };
}>

Parameters

| Parameter | Type | Value | | ------------ | ---------- | ------------------------------------------------------ | | keyword | String | up to you | | lang | boolean | user language code that video applies for, default vi | | country | boolean | country code that video applies for, default vn | | withPlaylist | boolean | whether the search results consist of playlist | | limit | number | limit the number of result items found | | options | JSON Array | [{type:"video/channel/playlist/movie"}] |

Result

  • JSON of items found, and nextPage token
  • items is the array from youtube, "nextPage" needs to pass when going to the next page. If playlist arg is true, will return type:'playlist' but the videos:[] property will not return the whole videos in the list, need to call GetPlaylistData to get real playlist's videos. Item with Video type will return isLive=[true/false] to identify live video or not.
  • item is a VideoRender structure
const VideoRender: (json: any) => {
    vid: any;
    type: string;
    thumbnail: string;
    title: any;
    channelTitle: any;
    channelId: any;
    channelThumbnail: any;
    duration: any;
    viewCount: any;
    publishedAt: any;
    isLive: boolean;
} | {
}

Example

ytSearchApi.SearchVideosByKeyword("Hello").then((result) => {
	console.log(result.items[0], result.nextPage);
});

2. FetchWhatToWatchByYouTube (Promise)

FetchWhatToWatchByYouTube

const FetchWhatToWatchByYouTube: (lang?: string, country?: string, pageToken?: string) => Promise<{
    items: any[];
    nextPage: {
        nextPageToken: null;
        nextPageContext: {
            context: null;
            continuation: {};
        };
    };
}>

Parameters

| Parameter | Type | Value | | ------------ | ---------- | ------------------------------------------------------ | | lang | String | up to you | | country | String | up to you | | pageToken | String | token of the page to search for |

Result

  • JSON of items found, and nextPage token
  • Same as SearchVideosByKeyword

Example

ytSearchApi.FetchWhatToWatchByYouTube().then((result) => {
	console.log(result);
});

3. FetchTrending (Promise)

Fetch Trending

const FetchTrending: (tab?: any, lang?: any, country?: any, limit?: any) => Promise<{
    items: any[];
    nextPage: {
        nextPageToken: null;
        nextPageContext: {
            context: null;
            continuation: {};
        };
    };
}>

Parameters

| Parameter | Type | Value | | ------------ | ---------- | ------------------------------------------------------ | | tab | Number | 0=now, 1=music, 2=gaming, 3=movies | | lang | String | up to you | | country | String | up to you | | limit | String | limit the result items |

Result

  • JSON of items found, and nextPage token
  • Same as SearchVideosByKeyword

Example

ytSearchApi.FetchTrending("0").then((result) => {
	console.log(result.items && result.items[0], result.nextPage);
});

4. GetVideoDetailsWithSuggestion (Promise)

Get details of current videos along with its video suggestions, nextVideo, and endscreen elements

const GetVideoDetailsWithSuggestion: (videoId: any, lang?: any, country?: any) => Promise<{
    title: any;
    isLive: any;
    thumbnail: string;
    description: any;
    channel: any;
    channelThumbnail: any;
    duration: string;
    viewCount: any;
    publishedAt: any;
    publishedAt2: any;
    suggestion: ResultItem[];
    nextVideo: ResultItem;
    endscreen: {
        startMs: any,
        elements:ResultItem[];
    };
}>

Parameters

| Parameter | Type | Value | | ------------ | ---------- | ------------------------------------------------------ | | videoId | String | Video Id | | lang | String | up to you | | country | String | up to you |

Result

  • JSON object of video details and its videos suggestion array
{
    title: any;
    isLive: any;
    thumbnail: string;
    description: any;
    channel: any;
    channelThumbnail: any;
    duration: string;
    viewCount: any;
    publishedAt: any;
    publishedAt2: any;
    suggestion: ResultItem[] || [];
    nextVideo: ResultItem;
    endscreen: {
        startMs: any,
        elements:ResultItem [];
    };
}

//Structure of ResultItem
ResultItem: {
	vid: any;
	type: string;
	thumbnail: any;
	title: any;
	channelTitle: string;
	channelId: string;
	channelThumbnail: string;
	duration: string;
	viewCount: any;
	publishedAt: any;
	isLive: boolean;
}

Example

ytSearchApi.GetVideoDetailsWithSuggestion("oQl9XjVKdQ4").then((result) => {
	console.log(result);
});

Notice:

  1. We just focus on the 4 functions above.
  2. Other functions we are note sure if they work.

Message

If you want to work with me to fix bug or implement new idea. You are available to send me some new idea of this project.

Indeed, I will also need to clean up this later.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Todo

  1. Tidy up source

History

2024-08-01

Initial publish the module.

We just focus on the 4 functions below. Other functions we are note sure if they work.

  1. SearchVideosByKeyword
  2. FetchWhatToWatchByYouTube
  3. FetchTrending
  4. GetVideoDetailsWithSuggestion

License

MIT

Support me

https://ko-fi.com/hssoftvn