-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-firebase.js
68 lines (52 loc) · 1.5 KB
/
main-firebase.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var firebaseUrl = "";
var secret = "";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
function main() {
var videoId = "WuSCrKqSlMg";
var videoData = getVideoDetails(videoId); //get current views in video
//var firebaseViews = updateFirebaseData(videoData);
if (updateFirebaseData(videoData) == true){
updateDetails(videoData);
}
Logger.log(videoData);
// if(!validate(videoData)){
// updateDetails(videoData);
// }
Logger.log(videoData);
}
//get current views in video
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;
}
//update video title
function updateDetails(videoData){
var resource = {
snippet : {
title: "O/L Blender SpeedArt, views " + videoData.viewCount + ")",
categoryId : videoData.categoryId
},
id : videoData.id
};
Logger.log(resource);
YouTube.Videos.update(resource, "snippet,id");
}
function updateFirebaseData(videoData){
var viewNumber = base.getData();
return videoData.title.indexOf(videoData.viewCount) > viewNumber;
}
function setdataFirebase(){
///hfuhd
}