@sushibtw/youtubei
Version:
Simple package to get information from youtube such as videos, playlists, channels, video information & comments, related videos, up next video, and more!
47 lines (46 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContinuationFromContents = exports.stripToInt = exports.getQueryParameter = exports.getDuration = void 0;
const url_1 = require("url");
const getDuration = (s) => {
s = s.replace(/:/g, ".");
const spl = s.split(".");
if (spl.length === 0)
return +spl;
else {
const sumStr = spl.pop();
let sum = +sumStr;
if (spl.length === 1)
sum += +spl[0] * 60;
if (spl.length === 2) {
sum += +spl[1] * 60;
sum += +spl[0] * 3600;
}
return sum;
}
};
exports.getDuration = getDuration;
const getQueryParameter = (url, queryName) => {
try {
return new url_1.URL(url).searchParams.get(queryName) || url;
}
catch (err) {
/* not an URL */
return url;
}
};
exports.getQueryParameter = getQueryParameter;
const stripToInt = (string) => {
if (!string)
return null;
return +string.replace(/[^0-9]/g, "");
};
exports.stripToInt = stripToInt;
const getContinuationFromContents = (data) => {
const lastSecondaryContent = data[data.length - 1];
return "continuationItemRenderer" in lastSecondaryContent
? lastSecondaryContent.continuationItemRenderer.continuationEndpoint.continuationCommand
.token
: undefined;
};
exports.getContinuationFromContents = getContinuationFromContents;