곽교린

Update CommentLoadingTest.js, papago.js

modify papago.js import to require. add comment language(lang) in commen
tList by require papago.js in CommentLoadingTest.
1 +var papago = require("./papago.js");
2 +
1 var http = require('http'); 3 var http = require('http');
2 var fs = require('fs'); 4 var fs = require('fs');
3 var url = require('url'); 5 var url = require('url');
...@@ -8,6 +10,7 @@ const {google} = require("googleapis"); ...@@ -8,6 +10,7 @@ const {google} = require("googleapis");
8 const service = google.youtube('v3'); 10 const service = google.youtube('v3');
9 const apiKey = 'AIzaSyCjBrFKnBlGvxsfOD-qJP8nBkdEoqKRHu8'; //api키 11 const apiKey = 'AIzaSyCjBrFKnBlGvxsfOD-qJP8nBkdEoqKRHu8'; //api키
10 let videoNum = "TpPwI_Lo0YY"; //비디오 주소(예시) 12 let videoNum = "TpPwI_Lo0YY"; //비디오 주소(예시)
13 +const serverIP = "http://localhost:3000" //서버의 주소
11 var commentList = new Array(); 14 var commentList = new Array();
12 var commentNum = 0; 15 var commentNum = 0;
13 var savednpt = '' 16 var savednpt = ''
...@@ -29,7 +32,7 @@ function showcomment(response, VideoNum){ ...@@ -29,7 +32,7 @@ function showcomment(response, VideoNum){
29 <meta charset="utf-8"> 32 <meta charset="utf-8">
30 </head> 33 </head>
31 <body> 34 <body>
32 - <form action="http://localhost:3000/search" method="get"> 35 + <form action="${serverIP}/search" method="get">
33 <p> 36 <p>
34 <textarea name="videourl" placeholder="Write your video Url" >${VideoNum}</textarea> 37 <textarea name="videourl" placeholder="Write your video Url" >${VideoNum}</textarea>
35 </p> 38 </p>
...@@ -42,7 +45,7 @@ function showcomment(response, VideoNum){ ...@@ -42,7 +45,7 @@ function showcomment(response, VideoNum){
42 <iframe width="560" height="315" src="https://www.youtube.com/embed/${VideoNum}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> 45 <iframe width="560" height="315" src="https://www.youtube.com/embed/${VideoNum}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
43 46
44 <br> 47 <br>
45 - <a href="http://localhost:3000/search?videourl=${VideoNum}&nextpage=${savednpt}"><input type="button" value="댓글 더 불러오기"></a> 48 + <a href="${serverIP}/search?videourl=${VideoNum}&nextpage=${savednpt}"><input type="button" value="댓글 더 불러오기"></a>
46 <br> 49 <br>
47 ${commentDisplay} 50 ${commentDisplay}
48 </body> 51 </body>
...@@ -64,10 +67,12 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ ...@@ -64,10 +67,12 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){
64 }).then(function(response) { 67 }).then(function(response) {
65 //console.log("Response", response); 68 //console.log("Response", response);
66 for(let iter = 0; iter < response.data.pageInfo.totalResults; iter++){ 69 for(let iter = 0; iter < response.data.pageInfo.totalResults; iter++){
70 + let templang = papago.getLang(response.data.items[iter].snippet.topLevelComment.snippet.textDisplay)
67 let tempComment = { 71 let tempComment = {
68 'name' : response.data.items[iter].snippet.topLevelComment.snippet.authorDisplayName, 72 'name' : response.data.items[iter].snippet.topLevelComment.snippet.authorDisplayName,
69 'image' : response.data.items[iter].snippet.topLevelComment.snippet.authorProfileImageUrl, 73 'image' : response.data.items[iter].snippet.topLevelComment.snippet.authorProfileImageUrl,
70 - 'text' : response.data.items[iter].snippet.topLevelComment.snippet.textDisplay 74 + 'text' : response.data.items[iter].snippet.topLevelComment.snippet.textDisplay,
75 + 'lang' : templang
71 } 76 }
72 commentList.push(tempComment); 77 commentList.push(tempComment);
73 commentNum += 1; 78 commentNum += 1;
...@@ -106,7 +111,7 @@ var app = http.createServer(function(request,response){ // request는 브라우 ...@@ -106,7 +111,7 @@ var app = http.createServer(function(request,response){ // request는 브라우
106 <meta charset="utf-8"> 111 <meta charset="utf-8">
107 </head> 112 </head>
108 <body> 113 <body>
109 - <form action="http://localhost:3000/search" method="get"> 114 + <form action="${serverIP}/search" method="get">
110 <p> 115 <p>
111 <textarea name="videourl" placeholder="Write your video Url"></textarea> 116 <textarea name="videourl" placeholder="Write your video Url"></textarea>
112 </p> 117 </p>
......
This diff is collapsed. Click to expand it.
1 { 1 {
2 "dependencies": { 2 "dependencies": {
3 - "googleapis": "^100.0.0",
4 - "youtube-v3-api": "^1.1.1",
5 "franc": "^6.0.0", 3 "franc": "^6.0.0",
6 - "langs": "^2.0.0" 4 + "googleapis": "^100.0.0",
7 - }, 5 + "langs": "^2.0.0",
8 - "type": "module" 6 + "request": "^2.88.2",
7 + "youtube-v3-api": "^1.1.1"
8 + }
9 } 9 }
......
1 -var express = require('express'); 1 +
2 -var app = express();
3 var client_id = '6hpmInU0TCrQIiiJwgJX'; 2 var client_id = '6hpmInU0TCrQIiiJwgJX';
4 var client_secret = 'jpYZbkj0_g'; 3 var client_secret = 'jpYZbkj0_g';
5 // var query = "언어를 감지할 문장을 입력하세요."; 4 // var query = "언어를 감지할 문장을 입력하세요.";
...@@ -51,8 +50,13 @@ async function findLanguage(sourceText) { ...@@ -51,8 +50,13 @@ async function findLanguage(sourceText) {
51 }); 50 });
52 }); 51 });
53 } 52 }
54 - 53 +/*
55 export async function getLang(comment) { 54 export async function getLang(comment) {
56 const lang = await findLanguage(comment); 55 const lang = await findLanguage(comment);
57 return lang; 56 return lang;
58 -}
...\ No newline at end of file ...\ No newline at end of file
57 +}
58 +*/
59 +exports.getLang = async function(comment) {
60 + const lang = await findLanguage(comment);
61 + return lang;
62 + }
...\ No newline at end of file ...\ No newline at end of file
......