New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yt-api

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yt-api - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

14

package.json
{
"name": "yt-api",
"version": "0.0.7",
"version": "0.0.8",
"description": "",
"main": "index.js",
"types": "typings/index.ts",
"main": "src/index.js",
"types": "typings/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"dependencies": {
"moment": "^2.20.1",
"snekfetch": "^3.6.4",
"ytdl-core": "^0.18.7"
"snekfetch": "^3.6.4"
}
}
const snekfetch = require("snekfetch");
const moment = require("moment");
const utils = require("./Utils.js");

@@ -51,7 +50,9 @@

async searchYouTube(query, callback) {
request(`https://www.googleapis.com/youtube/v3/search?part=id,snippet&q=${encodeURIComponent(query)}&type=video&key=${this.key}`, function (err, res, body) {
let json = JSON.parse(body);
async getVideo(search) {
return new Promise(async (res, rej) => {
let apiResponse = await snekfetch.get(`https://www.googleapis.com/youtube/v3/search?part=id,snippet&q=${encodeURIComponent(search)}&type=video&key=${this.key}`);
let json = JSON.parse(apiResponse.text);
let data = json.items[0];
if(!data) return console.log("Error: The provided video search returned 0 results!");
if(!data) rej("The search returned zero results!");
let info = {

@@ -68,15 +69,15 @@ videoID: data.id.videoId,

}
callback(info);
return res(info);
});
}
async searchVideos(query, amount, cb) {
request(`https://www.googleapis.com/youtube/v3/search?part=id,snippet&q=${encodeURIComponent(query)}&type=video&maxResults=${amount}&key=${this.key}`, function (err, res, body) {
let json = JSON.parse(body);
let vids = [];
if(err) throw err;
for(var i = 0; i < amount; i++) {
async getVideos(search, maxResults) {
return new Promise(async (res, rej) => {
let apiResponse = await snekfetch.get(`https://www.googleapis.com/youtube/v3/search?part=id,snippet&q=${encodeURIComponent(search)}&type=video&maxResults=${maxResults}&key=${this.key}`);
let json = JSON.parse(apiResponse.text);
if(!json.items[0]) rej("No videos were found for this search!");
let results = [];
for(let i = 0; i < maxResults; i++) {
let data = json.items[i];
if(!data) return console.log("No data was found for this search!");
let vidinfo = {
let resultInfo = {
videoID: data.id.videoId,

@@ -92,7 +93,7 @@ url: `https://www.youtube.com/watch?v=${data.id.videoId}`,

}
vids.push(vidinfo);
results.push(resultInfo);
}
return cb(vids);
return res(results);
});
}
}

@@ -0,1 +1,3 @@

import { YouTubeAPI } from "../src";
declare module "yt-api" {

@@ -5,4 +7,5 @@ export class VideoAPI extends YouTubeAPI<string>{

public key: string;
public getVideo(id: string): Promise<VideoInfo>;
public getVideo(search: string): Promise<SearchedVideoInfo>;
public getVideos(search: string, maxResults: number): Promise<Array<SearchedVideoInfo>>;
}

@@ -25,6 +28,6 @@

duration: {
days: number|string;
hours: number|string;
minutes: number|string;
seconds: number|string;
days: number;
hours: number;
minutes: number;
seconds: number;
};

@@ -39,2 +42,14 @@ statistics: {

}
export type SearchedVideoInfo = {
videoID: string,
url:string ,
title: string,
channel: {
id: string,
user: string,
url: string
},
thumbnail: string
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc