곽교린

Feat new comment Recall algorithm

parse comment by selected languages when it recall not make page that is
displayed. and when number of comment that parsed by selected language
is too little(less then 100), load more comment up to 500.
......@@ -17,29 +17,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 +82,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 +94,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 +124,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 +191,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
......