Yuncheol Kwak

Merge branch 'develop' of http://khuhub.khu.ac.kr/2019102147/youtube-comment-seperator into develop

{
"youtubeAPI" : "",//insert your youtube API key.
"papagoClientID" : "", //insert your papago client ID.
"papagoClientSecret":"" //insert your papago client secret.
}
\ No newline at end of file
......@@ -7,7 +7,8 @@ var qs = require('querystring');
var path = require('path');
const {google} = require("googleapis");
const service = google.youtube('v3');
const apiKey = 'AIzaSyCjBrFKnBlGvxsfOD-qJP8nBkdEoqKRHu8'; //api키
const apis = require('./APIs.json');
const apiKey = apis.youtubeAPI; //api키
let videoNum = "TpPwI_Lo0YY"; //비디오 주소(예시)
var videoLang = 'all'; //설정 언어
const serverIP = "http://localhost:3000" //서버의 주소
......@@ -17,29 +18,11 @@ var savednpt = ''
const URLreg1 = new RegExp(/https?:\/\/youtu.be\//);//유튜브에서 제공하는 동영상 공유 기능을 사용하여 얻은 URL 형식
const URLreg2 = new RegExp(/https?:\/\/www.youtube.com\//);//유튜브 주소를 그대로 넣었을 때 URL형식
async function showcomment(response, VideoNum){
let sepComment = new Promise((resolve, reject)=>{
async function inSepCom(){
let tempcommentDisplay = "";
console.log(commentNum);
for(let iterArr = 0; iterArr < commentNum; iterArr++){
await commentList[iterArr].lang.then((languageData) =>{
//console.log(languageData);
if(videoLang == 'all'){
tempcommentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`;
}
else if(videoLang == languageData){
tempcommentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`;
}
});
}
return tempcommentDisplay
}
resolve(inSepCom());
});
let commentDisplay = await sepComment;
function showcomment(response, VideoNum){
let commentDisplay = '';
for(let iterArr = 0; iterArr < commentNum; iterArr++){
commentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`;
}
let body = `
<!doctype html>
<html>
......@@ -100,7 +83,10 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){
"maxResults" : 100,
"pageToken" : npt
}).then(function(response) {
async function loadAndParse(){
//console.log("Response", response);
tempcommentList = new Array();
tempListLen = 0;
for(let iter = 0; iter < response.data.pageInfo.totalResults; iter++){
let templang = papago.getLang(response.data.items[iter].snippet.topLevelComment.snippet.textDisplay)
let tempComment = {
......@@ -109,15 +95,26 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){
'text' : response.data.items[iter].snippet.topLevelComment.snippet.textDisplay,
'lang' : templang
}
commentList.push(tempComment);
commentNum += 1;
}
tempcommentList.push(tempComment);
tempListLen += 1;
}
for(let iter = 0; iter < tempListLen; iter++){
let langPromise = tempcommentList[iter].lang.then(langData=>{
return langData;
});
templang = await langPromise;
if(videoLang == 'all' || videoLang == templang){
commentList.push(tempcommentList[iter]);
commentNum++;
}
}
//console.log(response.data.items[0].snippet.topLevelComment.snippet.textDisplay);
//console.log(response.data.items[1].snippet.topLevelComment.snippet.textDisplay);
npt = response.data.nextPageToken;
if(npt != null){
if( n > 1 ){
if( n > 1 && commentNum < 100){
loadcomment(ApiKey, VideoNum, npt, n - 1, res);
}else{
savednpt = npt; //만약 댓글을 n번 불러온 후에 댓글이 더 남아있으면 savednpt 갱신
......@@ -128,6 +125,8 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){
console.log('end page'); // 댓글의 마지막 페이지
showcomment(res, VideoNum);
}
}
loadAndParse();
},
function(err) { console.error("Execute error", err); });
}
......@@ -193,7 +192,7 @@ var app = http.createServer(function(request,response){ // request는 브라우
console.log(videoNum);
let npt = ""
if(queryData.nextpage != null) npt = queryData.nextpage
loadcomment(apiKey,videoNum,npt,2, response);
loadcomment(apiKey,videoNum,npt,5, response);
}
});
app.listen(3000);
\ No newline at end of file
......
AIzaSyCjBrFKnBlGvxsfOD-qJP8nBkdEoqKRHu8
\ No newline at end of file
var client_id = '6hpmInU0TCrQIiiJwgJX';
var client_secret = 'jpYZbkj0_g';
const apis = require('./APIs.json');
var client_id = apis.papagoClientID;
var client_secret = apis.papagoClientSecret;
// var query = "언어를 감지할 문장을 입력하세요.";
// app.get('/detectLangs', function (req, res) {
// var api_url = 'https://openapi.naver.com/v1/papago/detectLangs';
......