Toggle navigation
Toggle navigation
This project
Loading...
Sign in
은승우
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
권은령
2019-12-05 00:54:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
07509d80f397114f3e689cc8b7901e9a7ad3bda2
07509d80
1 parent
7588a071
apply lyrics translation
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
8 deletions
app.js
mymusic.js
app.js
View file @
07509d8
...
...
@@ -158,14 +158,86 @@ function handleEvent(event)
});
});
}
else
if
(
event
.
message
.
text
.
substring
(
0
,
7
)
==
'가사 검색 1
'
)
else
if
(
event
.
message
.
text
.
substring
(
0
,
5
)
==
'가사 검색
'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
var
userNum
=
event
.
message
.
text
[
6
]
var
newUrl
=
songList
[
userNum
].
url
;
var
lyric
=
''
;
request
(
newUrl
,
function
(
error
,
response
,
html
)
{
var
result
=
{
type
:
'text'
,
text
:
''
};
result
.
text
=
songList
[
1
].
url
;
var
$
=
cheerio
.
load
(
html
);
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
lyric
=
$
(
'#pLyrics > p'
).
text
();
lyric
=
lyric
.
substring
(
0
,
150
);
console
.
log
(
songList
[
userNum
].
song
);
console
.
log
(
lyric
);
});
return
new
Promise
(
function
(
resolve
,
reject
)
{
//언어 감지 option
var
detect_options
=
{
url
:
languagedetect_api_url
,
form
:
{
'query'
:
lyric
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
//papago 언어 감지
request
.
post
(
detect_options
,
(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
var
detect_body
=
JSON
.
parse
(
response
.
body
);
var
source
=
''
;
var
target
=
''
;
var
result
=
{
type
:
'text'
,
text
:
''
};
//언어 감지가 제대로 됐는지 확인
console
.
log
(
detect_body
.
langCode
);
//번역은 한국어->영어 / 영어->한국어만 지원
if
(
detect_body
.
langCode
==
'ko'
||
detect_body
.
langCode
==
'en'
)
{
source
=
detect_body
.
langCode
==
'ko'
?
'ko'
:
'en'
;
target
=
source
==
'ko'
?
'en'
:
'ko'
;
//papago 번역 option
var
options
=
{
url
:
translate_api_url
,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form
:
{
'source'
:
source
,
'target'
:
target
,
'text'
:
lyric
},
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
// Naver Post API
request
.
post
(
options
,
function
(
error
,
response
,
body
){
// Translate API Sucess
if
(
!
error
&&
response
.
statusCode
==
200
){
// JSON
var
objBody
=
JSON
.
parse
(
response
.
body
);
// Message 잘 찍히는지 확인
result
.
text
=
objBody
.
message
.
result
.
translatedText
;
console
.
log
(
"result: "
+
result
.
text
);
//번역된 문장 보내기
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
});
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else
{
result
.
text
=
'언어를 감지할 수 없습니다. \n 번역 언어는 한글 또는 영어만 가능합니다.'
;
client
.
replyMessage
(
event
.
replyToken
,
result
).
then
(
resolve
).
catch
(
reject
);
}
}
else
{
console
.
log
(
"status code is not 200"
);
}
});
});
}
else
...
...
mymusic.js
View file @
07509d8
...
...
@@ -35,7 +35,7 @@ request(url, function(error, response, html)
//console.log(i+1 + ". "+ songList[i].singer+" - "+songList[i].song);
}
console
.
log
(
result
);
//
console.log(result);
var
randnum
=
function
getRandomInt
(
min
,
max
)
{
min
=
Math
.
ceil
(
min
);
...
...
@@ -49,11 +49,12 @@ request(url, function(error, response, html)
request
(
newUrl
,
function
(
error
,
response
,
html
)
{
var
$
=
cheerio
.
load
(
html
);
var
lyric
=
$
(
'#pLyrics > p'
).
text
();
var
result
=
lyric
.
substring
(
0
,
150
);
lyric
=
lyric
.
substring
(
0
,
150
);
console
.
log
(
songList
[
randnum
].
song
);
console
.
log
(
result
);
console
.
log
(
lyric
);
});
})
\ No newline at end of file
...
...
Please
register
or
login
to post a comment