Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신지원
/
LineMusicChatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
신지원
2021-06-02 12:44:12 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9f8c3c0fb57e61d2eaf37aab4134318bd2cae8e3
9f8c3c0f
1 parent
d6e7273c
재생목록 중 1곡 뽑아내기
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
73 deletions
Youtube API/.vscode/launch.json
index.js
index_Temp.js
video_sad.js
Youtube API/.vscode/launch.json
View file @
9f8c3c0
...
...
@@ -11,7 +11,7 @@
"skipFiles"
:
[
"<node_internals>/**"
],
"program"
:
"${workspaceFolder}/
playlistbyi
d.js"
"program"
:
"${workspaceFolder}/
video_list_sa
d.js"
}
]
}
\ No newline at end of file
...
...
index.js
View file @
9f8c3c0
...
...
@@ -14,9 +14,11 @@ const bodyParser = require('body-parser');
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
// var { google } = require('googleapis');
/// ----
var
{
google
}
=
require
(
'googleapis
'
);
/// ----
var
sad
=
require
(
'./video_sad
'
);
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -35,7 +37,6 @@ app.post('/hook', function (req, res) {
res
.
sendStatus
(
200
);
});
function
trans
(
replyToken
,
message
)
{
request
.
post
(
...
...
@@ -48,12 +49,11 @@ function trans(replyToken, message) {
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
body
:
'source=ko&target=en&text='
+
message
,
json
:
true
json
:
true
},
(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
// message 가 사용자에게서 입력받은 메시지 내용입니다. sendMessage 는 보낼 메시지 내용입니다.
// 위에 PAPAGO API부분은 추후 API를 연동시킬 때 맞춰서 작성하기 쉽도록 템플릿을 남겨놓았습니다. 자세한 정보는 교수님 학습 자료의 experiment의 trans 폴더를 참고하세요.
// (현재 코드에선 PAPAGO API의 작동 결과는 반영되지 않습니다.)
...
...
@@ -61,79 +61,17 @@ function trans(replyToken, message) {
// var sendMessage;
// --------
if
(
message
==
"노래 추천해줘"
)
{
var
sendMessage
=
"아이유의 노래를 추천드립니다."
;
console
.
log
(
typeof
(
sendMessage
));
console
.
log
(
sendMessage
);
if
(
message
==
"슬픈노래"
)
{
sad
.
check
(
message
,
replyToken
);
}
else
{
// var sendMessage = "무슨 말인지 못알아먹겠습니다";
// --------
var
service
=
google
.
youtube
(
'v3'
);
service
.
videos
.
list
({
key
:
'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518'
,
part
:
'snippet,statistics'
,
id
:
'p5iu1V30myk'
,
// 동영상 Id
fields
:
'items(snippet(title))'
},
function
(
err
,
response
)
{
if
(
err
)
{
console
.
log
(
'The API returned an error: '
,
err
);
return
;
else
{
sad
.
check
(
message
,
replyToken
);
}
var
video
=
response
.
data
.
items
;
if
(
video
.
length
==
0
){
console
.
log
(
'검색된 동영상이 없습니다.'
);
}
else
{
// var sendMessage ="123";
// console.log(JSON.stringify(response.data.items[0].snippet.title));// 콘솔에 출력
// console.log(JSON.stringify(response.data.items[0].snippet));// 콘솔에 출력
// console.log(JSON.stringify(response.data.items[0]));// 콘솔에 출력
// console.log(JSON.stringify(response.data));// 콘솔에 출력
var
sendMessage
=
JSON
.
stringify
(
response
.
data
.
items
[
0
].
snippet
.
title
);
// sendMessage = response.data.items[0].snippet.title;
console
.
log
(
sendMessage
);
console
.
log
(
typeof
(
sendMessage
));
}
})
// // --------
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
console
.
log
(
"11111"
);
console
.
log
(
body
.
message
);
console
.
log
(
"11111"
);
// console.log(typeof(response.data.items[0].snippet.title));
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
sendMessage
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
...
...
index_Temp.js
0 → 100644
View file @
9f8c3c0
This diff is collapsed. Click to expand it.
video_sad.js
0 → 100644
View file @
9f8c3c0
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
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'Kb1/rQYz4MUhF8XyKQv7z9x0MxVQ5bX/XO8S/yt/1qQEJVAbsEFAaMvXKEOx9Umr7KhivfyDPfZHRRLFPngR0O4ZGWV2VFses8ufPE7uAdvYr4G6keBNAU69nBz5IC71HfbIrUHxXYqD7GfhVwXzpwdB04t89/1O/w1cDnyilFU='
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
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
sendMessage
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
})
}
Please
register
or
login
to post a comment