-
Notifications
You must be signed in to change notification settings - Fork 10
/
Util.js
49 lines (40 loc) · 1.42 KB
/
Util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict"
exports.compress = function(key) {
return (key && key['runs'] ? key['runs'].map((v) => v.text) : []).join('');
}
function isChannelVerified(vRender) {
const badges = (vRender['ownerBadges'] ?
vRender['ownerBadges'].map((badge) => badge['metadataBadgeRenderer']['style']) : []
);
return badges.includes('BADGE_STYLE_TYPE_VERIFIED_ARTIST');
}
exports.getChannelData = function(vRender) {
const channel = vRender.ownerText.runs[0];
return {
name: channel.text,
link: 'https://www.youtube.com'+ channel['navigationEndpoint']['commandMetadata']['webCommandMetadata']['url'],
verified: isChannelVerified(vRender)
};
}
exports.getUploadDate = function(vRender) {
return vRender['publishedTimeText'] ? vRender['publishedTimeText']['simpleText'] : '';
}
exports.getViews = function(vRender) {
return parseInt(vRender.viewCountText.simpleText.replace(/[^0-9]/g, ''));
}
exports.idToThumbnail = function(id) {
return 'https://i.ytimg.com/vi/'+ id +'hqdefault.jpg';
}
exports.parseDuration = function(vRender) {
const nums = vRender.lengthText.simpleText.split(':');
let sum = 0;
let multi = 1;
while (nums.length > 0) {
sum += multi * parseInt(nums.pop() || '-1', 10);
multi *= 60;
}
return sum;
}
exports.shareLink = function(id, short = true) {
return short ? 'https://youtu.be/'+ id : 'https://www.youtube.com/watch?v='+ id;
}