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.
Showing
1 changed file
with
26 additions
and
28 deletions
... | @@ -17,29 +17,11 @@ var savednpt = '' | ... | @@ -17,29 +17,11 @@ var savednpt = '' |
17 | const URLreg1 = new RegExp(/https?:\/\/youtu.be\//);//유튜브에서 제공하는 동영상 공유 기능을 사용하여 얻은 URL 형식 | 17 | const URLreg1 = new RegExp(/https?:\/\/youtu.be\//);//유튜브에서 제공하는 동영상 공유 기능을 사용하여 얻은 URL 형식 |
18 | const URLreg2 = new RegExp(/https?:\/\/www.youtube.com\//);//유튜브 주소를 그대로 넣었을 때 URL형식 | 18 | const URLreg2 = new RegExp(/https?:\/\/www.youtube.com\//);//유튜브 주소를 그대로 넣었을 때 URL형식 |
19 | 19 | ||
20 | -async function showcomment(response, VideoNum){ | 20 | +function showcomment(response, VideoNum){ |
21 | - let sepComment = new Promise((resolve, reject)=>{ | 21 | + let commentDisplay = ''; |
22 | - async function inSepCom(){ | 22 | + for(let iterArr = 0; iterArr < commentNum; iterArr++){ |
23 | - | 23 | + commentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`; |
24 | - let tempcommentDisplay = ""; | 24 | + } |
25 | - console.log(commentNum); | ||
26 | - | ||
27 | - for(let iterArr = 0; iterArr < commentNum; iterArr++){ | ||
28 | - await commentList[iterArr].lang.then((languageData) =>{ | ||
29 | - //console.log(languageData); | ||
30 | - if(videoLang == 'all'){ | ||
31 | - tempcommentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`; | ||
32 | - } | ||
33 | - else if(videoLang == languageData){ | ||
34 | - tempcommentDisplay += `<br>${commentList[iterArr].name}<br>${commentList[iterArr].text}<br><br>`; | ||
35 | - } | ||
36 | - }); | ||
37 | - } | ||
38 | - return tempcommentDisplay | ||
39 | - } | ||
40 | - resolve(inSepCom()); | ||
41 | - }); | ||
42 | - let commentDisplay = await sepComment; | ||
43 | let body = ` | 25 | let body = ` |
44 | <!doctype html> | 26 | <!doctype html> |
45 | <html> | 27 | <html> |
... | @@ -100,7 +82,10 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ | ... | @@ -100,7 +82,10 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ |
100 | "maxResults" : 100, | 82 | "maxResults" : 100, |
101 | "pageToken" : npt | 83 | "pageToken" : npt |
102 | }).then(function(response) { | 84 | }).then(function(response) { |
85 | + async function loadAndParse(){ | ||
103 | //console.log("Response", response); | 86 | //console.log("Response", response); |
87 | + tempcommentList = new Array(); | ||
88 | + tempListLen = 0; | ||
104 | for(let iter = 0; iter < response.data.pageInfo.totalResults; iter++){ | 89 | for(let iter = 0; iter < response.data.pageInfo.totalResults; iter++){ |
105 | let templang = papago.getLang(response.data.items[iter].snippet.topLevelComment.snippet.textDisplay) | 90 | let templang = papago.getLang(response.data.items[iter].snippet.topLevelComment.snippet.textDisplay) |
106 | let tempComment = { | 91 | let tempComment = { |
... | @@ -109,15 +94,26 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ | ... | @@ -109,15 +94,26 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ |
109 | 'text' : response.data.items[iter].snippet.topLevelComment.snippet.textDisplay, | 94 | 'text' : response.data.items[iter].snippet.topLevelComment.snippet.textDisplay, |
110 | 'lang' : templang | 95 | 'lang' : templang |
111 | } | 96 | } |
112 | - commentList.push(tempComment); | 97 | + tempcommentList.push(tempComment); |
113 | - commentNum += 1; | 98 | + tempListLen += 1; |
114 | - } | 99 | + } |
100 | + for(let iter = 0; iter < tempListLen; iter++){ | ||
101 | + let langPromise = tempcommentList[iter].lang.then(langData=>{ | ||
102 | + return langData; | ||
103 | + }); | ||
104 | + templang = await langPromise; | ||
105 | + if(videoLang == 'all' || videoLang == templang){ | ||
106 | + commentList.push(tempcommentList[iter]); | ||
107 | + commentNum++; | ||
108 | + } | ||
109 | + } | ||
110 | + | ||
115 | //console.log(response.data.items[0].snippet.topLevelComment.snippet.textDisplay); | 111 | //console.log(response.data.items[0].snippet.topLevelComment.snippet.textDisplay); |
116 | //console.log(response.data.items[1].snippet.topLevelComment.snippet.textDisplay); | 112 | //console.log(response.data.items[1].snippet.topLevelComment.snippet.textDisplay); |
117 | npt = response.data.nextPageToken; | 113 | npt = response.data.nextPageToken; |
118 | 114 | ||
119 | if(npt != null){ | 115 | if(npt != null){ |
120 | - if( n > 1 ){ | 116 | + if( n > 1 && commentNum < 100){ |
121 | loadcomment(ApiKey, VideoNum, npt, n - 1, res); | 117 | loadcomment(ApiKey, VideoNum, npt, n - 1, res); |
122 | }else{ | 118 | }else{ |
123 | savednpt = npt; //만약 댓글을 n번 불러온 후에 댓글이 더 남아있으면 savednpt 갱신 | 119 | savednpt = npt; //만약 댓글을 n번 불러온 후에 댓글이 더 남아있으면 savednpt 갱신 |
... | @@ -128,6 +124,8 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ | ... | @@ -128,6 +124,8 @@ function loadcomment(ApiKey, VideoNum, npt, n, res){ |
128 | console.log('end page'); // 댓글의 마지막 페이지 | 124 | console.log('end page'); // 댓글의 마지막 페이지 |
129 | showcomment(res, VideoNum); | 125 | showcomment(res, VideoNum); |
130 | } | 126 | } |
127 | + } | ||
128 | + loadAndParse(); | ||
131 | }, | 129 | }, |
132 | function(err) { console.error("Execute error", err); }); | 130 | function(err) { console.error("Execute error", err); }); |
133 | } | 131 | } |
... | @@ -193,7 +191,7 @@ var app = http.createServer(function(request,response){ // request는 브라우 | ... | @@ -193,7 +191,7 @@ var app = http.createServer(function(request,response){ // request는 브라우 |
193 | console.log(videoNum); | 191 | console.log(videoNum); |
194 | let npt = "" | 192 | let npt = "" |
195 | if(queryData.nextpage != null) npt = queryData.nextpage | 193 | if(queryData.nextpage != null) npt = queryData.nextpage |
196 | - loadcomment(apiKey,videoNum,npt,2, response); | 194 | + loadcomment(apiKey,videoNum,npt,5, response); |
197 | } | 195 | } |
198 | }); | 196 | }); |
199 | app.listen(3000); | 197 | app.listen(3000); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment