Showing
1 changed file
with
59 additions
and
0 deletions
| ... | @@ -86,6 +86,65 @@ function handleEvent(event) { | ... | @@ -86,6 +86,65 @@ function handleEvent(event) { |
| 86 | // ignore non-text-message event | 86 | // ignore non-text-message event |
| 87 | return Promise.resolve(null); | 87 | return Promise.resolve(null); |
| 88 | } | 88 | } |
| 89 | + else if (event.type == 'message'&& event.message.type == "text"&&event.message.text.indexOf('http')!=-1) { | ||
| 90 | + return new Promise(async(resolve,reject)=>{ | ||
| 91 | + var cheerio = require('cheerio'); | ||
| 92 | + var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; | ||
| 93 | + var imageUrl=event.message.text; | ||
| 94 | + var options = { | ||
| 95 | + uri: uriBase, | ||
| 96 | + qs: { | ||
| 97 | + 'language': 'unk', | ||
| 98 | + 'detectOrientation': 'true', | ||
| 99 | + }, | ||
| 100 | + headers: { | ||
| 101 | + 'Content-Type': 'application/json', | ||
| 102 | + 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc' | ||
| 103 | + }, | ||
| 104 | + body:'{"url": ' + '"' + imageUrl + '"}', | ||
| 105 | + }; | ||
| 106 | + | ||
| 107 | + request.post(options, function (error, response, body) { | ||
| 108 | + var data=JSON.stringify(body); | ||
| 109 | + var text=''; | ||
| 110 | + while(data.indexOf('text\\')!=-1) | ||
| 111 | + { | ||
| 112 | + data=data.substring(data.indexOf('text\\')+9); | ||
| 113 | + text+=data.substring(0,data.indexOf("\\"))+" "; | ||
| 114 | + } | ||
| 115 | + text=text.substring(text.length/10+1,text.length/8+2); | ||
| 116 | + console.log(text); | ||
| 117 | + var url="https://www.genie.co.kr/search/searchLyrics?query="+text; | ||
| 118 | + request(url, function(error, response, html) | ||
| 119 | + { | ||
| 120 | + console.log(url); | ||
| 121 | + var $ = cheerio.load(html); | ||
| 122 | + const $bodyList= $('#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'); | ||
| 123 | + | ||
| 124 | + var songList=[]; | ||
| 125 | + $bodyList.each(function(i, elem){ | ||
| 126 | + if(i<20){ | ||
| 127 | + songList.push({ | ||
| 128 | + singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(), | ||
| 129 | + song: $(this).find("td.info").find("a.title.ellipsis").text().trim(), | ||
| 130 | + }); | ||
| 131 | + | ||
| 132 | + } | ||
| 133 | + }) | ||
| 134 | + var resultm=''; | ||
| 135 | + for(var i=0;i<songList.length;i++){ | ||
| 136 | + if(songList[i].singer!=''){ | ||
| 137 | + resultm+=songList[i].singer+", "+songList[i].song+"\n"; | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + var result = { type: 'text', text:resultm}; | ||
| 141 | + client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | ||
| 142 | + | ||
| 143 | + }); | ||
| 144 | + }); | ||
| 145 | + }); | ||
| 146 | + | ||
| 147 | + } | ||
| 89 | return new Promise(function(resolve, reject) { | 148 | return new Promise(function(resolve, reject) { |
| 90 | //언어 감지 option | 149 | //언어 감지 option |
| 91 | var detect_options = { | 150 | var detect_options = { | ... | ... |
-
Please register or login to post a comment