get-youtube-video-info
Version:
Get your YouTube video info instantly.
47 lines (46 loc) • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDuration = exports.getStatistics = exports.getInfo = void 0;
const axios_1 = __importDefault(require("axios"));
async function getInfo({ videoId, apiKey }) {
const httpData = await axios_1.default.get("https://www.googleapis.com/youtube/v3/videos", {
params: {
part: "snippet",
id: videoId,
key: apiKey
},
}).catch(() => undefined);
if (typeof httpData === "undefined")
return;
return httpData.data.items[0].snippet;
}
exports.getInfo = getInfo;
async function getStatistics({ videoId, apiKey }) {
const httpData = await axios_1.default.get("https://www.googleapis.com/youtube/v3/videos", {
params: {
part: "statistics",
id: videoId,
key: apiKey
},
}).catch(() => undefined);
if (typeof httpData === "undefined")
return;
return httpData.data.items[0].statistics;
}
exports.getStatistics = getStatistics;
async function getDuration({ videoId, apiKey }) {
const httpData = await axios_1.default.get("https://www.googleapis.com/youtube/v3/videos", {
params: {
part: "contentDetails",
id: videoId,
key: apiKey
},
}).catch(() => undefined);
if (typeof httpData === "undefined")
return;
return httpData.data.items[0].contentDetails.duration;
}
exports.getDuration = getDuration;