-
Notifications
You must be signed in to change notification settings - Fork 0
/
script
50 lines (43 loc) · 1.85 KB
/
script
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
let scheduleUpcomingLive=()=> {
let results = YouTube.Search.list(
'snippet', {
channelId: 'CHANNEL ID', //CHANNEL IDを、予定を取りたいYoutubeのチャンネルのChannel IDに書き換えてください(URLから取れます)
eventType:'upcoming',
type:'video'
}
);
let calendarId = 'YOUR CALENDAR ID';//YOUR CALENDAR IDを、予定を登録したいカレンダーのカレンダーIDに書き換えてください
let now = new Date()
let optionalArgs = {
timeMax: (new Date(now.getTime() + (1095 * 24 * 60 * 60 * 1000))).toISOString(),
timeMin: (new Date(now.getTime() - ( 7 * 24 * 60 * 60 * 1000))).toISOString(),
showDeleted: false,
singleEvents: true,
};
let response = Calendar.Events.list(calendarId, optionalArgs);
let events = response.items;
for(let i in results.items){
let resultsVideo = YouTube.Videos.list(
'snippet,liveStreamingDetails',{
id : results.items[i].id.videoId
}
)
let VideoId = results.items[i].id.videoId
let URLofstream = 'https://www.youtube.com/watch?v=' + VideoId + '&ab_channel=' + resultsVideo.items[0].snippet.channelTitle.replace(/\s+/g, "");
let title = resultsVideo.items[0].snippet.title;
let startTime = new Date(resultsVideo.items[0].liveStreamingDetails.scheduledStartTime);
let endTime = new Date(resultsVideo.items[0].liveStreamingDetails.scheduledStartTime);
endTime.setHours(endTime.getHours() + 1)
let option = {
description: resultsVideo.items[0].snippet.description,
location: URLofstream
}
let arrayOfLocation = []
for (let n in events) {
arrayOfLocation.splice(n,0,events[n].getLocation())
}
if (arrayOfLocation.indexOf(URLofstream) < 0 ) {
CalendarApp.getCalendarById(calendarId).createEvent(title, startTime, endTime, option);
}
}
}