-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYouTubeData.js
97 lines (94 loc) · 2.8 KB
/
YouTubeData.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module.exports.YouTubeTools = async function (props) {
/// Not Yet Implemented
console.log("|Y| Running YouTube API");
const { YTSearcher, validOptions } = require("ytsearcher");
const admin = require("firebase-admin");
let youTubeAPIKey = "";
var dbData = {};
console.log("|Y| Running YouTube API");
async function getDBData() {
var db = admin.firestore();
db
.collection("Secrets")
.get()
.then((snapshot) => {
snapshot.forEach((doc) => {
var key = doc.id;
var data = doc.data();
data["key"] = key;
dbData[key] = data;
});
console.log("|Y| Got Keys, Initiating Query Now");
youTubeAPIKey = String(dbData.APIKeys.YTAPI);
console.log("|Y| Set Online To True");
async function getYouTubeData() {
var db = admin.firestore();
db
.collection("Secrets")
.get()
.then((snapshot) => {
snapshot.forEach((doc) => {
var key = doc.id;
var data = doc.data();
data["key"] = key;
dbData[key] = data;
});
const searcher = new YTSearcher(dbData.APIKeys.YTAPI);
let content = [];
let concResults = [];
console.log("|Y|Connected Getting Data");
async function runSendData(props) {
let result = await searcher.search(props.searchString, {
type: "video, channel",
publishedAfter: "2021-05-04T00:00:00Z",
order: "date",
maxResults: 2,
});
result.currentPage.forEach((ele) => {
if (ele.channelTitle === props.searchString) {
content.push(ele);
var db3 = admin.firestore();
db3.collection("YouTubeCollection").doc().set(
{
Title: ele.title,
LatestRun: admin.firestore.FieldValue.serverTimestamp(),
},
{ merge: true }
);
}
});
console.log("|Y| Sending Results");
console.log(content);
console.log(result.currentPage);
content.forEach((ele) => {
concResults.push({});
});
console.log(concResults);
console.log(
`This is an automated JavaScript bot that queries YouTube channels incrementally for new releases. \r\n`
);
if (JSON.stringify(concResults).length > 5) {
db.collection("Public").doc("DailyYoutube").set(
{
LastRun: admin.firestore.FieldValue.serverTimestamp(),
},
{ merge: true }
);
}
// Database
//begin detection of YouTubeOnOff
if (!dbData.MetaData.YouTubeOn) {
//Call Database Every 60s For OffOn Switch
}
return null;
// Detect FireStoreData
}
return runSendData({ searchString: "CollegeHumor" });
});
}
return getYouTubeData();
});
return null;
}
getDBData();
};