Comparing version 0.0.7 to 0.0.8
{ | ||
"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 | ||
} | ||
} |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15424
1
162
0
- Removedmoment@^2.20.1
- Removedytdl-core@^0.18.7
- Removedhtml-entities@1.4.0(transitive)
- Removedm3u8stream@0.2.2(transitive)
- Removedminiget@1.7.2(transitive)
- Removedmoment@2.30.1(transitive)
- Removedsax@1.4.1(transitive)
- Removedytdl-core@0.18.7(transitive)