video_sad.js
2.41 KB
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
var Info = require('./Info');
exports.check = function(message,replyToken){
const rand_0to9 = Math.floor(Math.random() * 10); // 0~9까지 난수생성
var ids = ['p5iu1V30myk', 'i-SBnhaZSSU', 'Etfgb6A7hSI', 'IN2mml9xs_s', // 모든 동영상 id를 관리하는 배열
'tp1uoFAfgHE', 'Qx22TnVVIfU', '3y1QIqR115A', 'VXBI1wt8XII', 'aWMBn2--E0Q', 'HyTbgBlnLCo'];
const request = require('request');
const fs = require('fs');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
var { google } = require('googleapis');
var service = google.youtube('v3');
service.videos.list
(
{
key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518',
part: 'snippet',
id: ids[rand_0to9], // 동영상 Id random input
fields: 'items(snippet(title))'
},
function (err, response)
{
if (err)
{
console.log('The API returned an error: ', err);
return;
}
var video = response.data.items;
if (video.length == 0)
{
console.log('검색된 동영상이 없습니다.');
}
else
{
sendMessage = JSON.stringify(response.data.items[0].snippet.title);
console.log(sendMessage);
request.post(
{
url: TARGET_URL,
headers:
{
'Authorization': `Bearer ${Info.TOKEN}`
},
json:
{
"replyToken": replyToken,
"messages":
[
{
"type": "image",
"originalContentUrl": "https://img.youtube.com/vi/"+ids[rand_0to9]+"/hqdefault.jpg",
"previewImageUrl": "https://img.youtube.com/vi/"+ids[rand_0to9]+"/hqdefault.jpg"
},
{
"type": "text",
"text": sendMessage
}
]
}
}
);
}
}
)
}