-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
46 lines (37 loc) · 993 Bytes
/
main.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
function myFunction() {
}
function main() {
var videoId = "WuSCrKqSlMg";
var videoData = getVideoDetails(videoId);
if(!validate(videoData)){
updateDetails(videoData);
}
Logger.log(videoData);
}
function getVideoDetails(videoId){
var result = YouTube.Videos.list('snippet,statistics', {id:videoId});
var obj = {
id:videoId,
title: result.items[0].snippet.title,
categoryId: result.items[0].snippet.categoryId,
viewCount: result.items[0].statistics.viewCount
}
return obj;
}
function validate(videoData){
if(videoData.title.indexOf(videoData.viewCount) > 0){
return true;
}
return false;
}
function updateDetails(videoData){
var resource = {
snippet : {
title: "O/L Results Speed Art (views: " + videoData.viewCount + ")",
categoryId : videoData.categoryId
},
id : videoData.id
};
Logger.log(resource);
YouTube.Videos.update(resource, "snippet,id");
}