Toggle navigation
Toggle navigation
This project
Loading...
Sign in
곽윤철
/
youtube-comment-seperator
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
곽교린
2022-05-12 19:23:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e7f73584f5cf38f657f9b7435a8b329fe53a2fc9
e7f73584
1 parent
86b4f32f
Update CommentLoadingTest.js
correct error : load page asynchronous
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
41 deletions
CommentLoadingTest.js
CommentLoadingTest.js
View file @
e7f7358
...
...
@@ -12,14 +12,51 @@ var commentList = new Array();
var
commentNum
=
0
;
var
savednpt
=
''
function
loadcomment
(
ApiKey
,
VideoNum
,
npt
,
n
){
function
showcomment
(
response
,
VideoNum
){
let
body
=
''
let
commentDisplay
=
""
;
console
.
log
(
commentNum
);
for
(
let
iterArr
=
0
;
iterArr
<
commentNum
;
iterArr
++
){
commentDisplay
+=
`<br>
${
commentList
[
iterArr
].
name
}
<br>
${
commentList
[
iterArr
].
text
}
<br><br>`
}
body
=
`
<!doctype html>
<html>
<head>
<title>Youtube Comment</title>
<meta charset="utf-8">
</head>
<body>
<form action="http://localhost:3000/search" method="get">
<p>
<textarea name="videourl" placeholder="Write your video Url" >
${
VideoNum
}
</textarea>
</p>
<p>
<input type="submit">
</p>
</form>
<br>
<br>
<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>
<br>
<br>
${
commentDisplay
}
</body>
</html>
`
;
response
.
writeHead
(
200
);
response
.
end
(
body
);
}
function
loadcomment
(
ApiKey
,
VideoNum
,
npt
,
n
,
res
){
return
service
.
commentThreads
.
list
({
"key"
:
ApiKey
,
"part"
:[
"snippet, replies"
],
"videoId"
:
VideoNum
,
//비디오 주소
"maxResults"
:
5
0
,
"maxResults"
:
10
0
,
"pageToken"
:
npt
}).
then
(
function
(
response
)
{
//console.log("Response", response);
...
...
@@ -38,12 +75,15 @@ function loadcomment(ApiKey, VideoNum, npt, n){
if
(
response
.
data
.
pageInfo
.
totalResults
==
response
.
data
.
pageInfo
.
resultsPerPage
){
if
(
n
>
1
){
loadcomment
(
ApiKey
,
VideoNum
,
npt
,
n
-
1
);
loadcomment
(
ApiKey
,
VideoNum
,
npt
,
n
-
1
,
res
);
}
else
{
savednpt
=
npt
;
//만약 댓글을 n번 불러온 후에 댓글이 더 남아있으면 savednpt 갱신
showcomment
(
res
,
VideoNum
);
}
}
else
{
savednpt
=
''
;
console
.
log
(
'end page'
);
// 댓글의 마지막 페이지
showcomment
(
res
,
VideoNum
);
}
},
function
(
err
)
{
console
.
error
(
"Execute error"
,
err
);
});
...
...
@@ -84,44 +124,7 @@ var app = http.createServer(function(request,response){ // request는 브라우
videoNum
=
queryData
.
videourl
;
console
.
log
(
videoNum
);
let
npt
=
""
loadcomment
(
apiKey
,
videoNum
,
npt
,
2
).
then
(()
=>
{
setTimeout
(()
=>
{
//딜레이를 주어 강제로 댓글을 여러번 불러오도록 구현, async화 필요.
let
commentDisplay
=
""
;
console
.
log
(
commentNum
);
for
(
let
iterArr
=
0
;
iterArr
<
commentNum
;
iterArr
++
){
commentDisplay
+=
`<br>
${
commentList
[
iterArr
].
name
}
<br>
${
commentList
[
iterArr
].
text
}
<br><br>`
}
body
=
`
<!doctype html>
<html>
<head>
<title>Youtube Comment</title>
<meta charset="utf-8">
</head>
<body>
<form action="http://localhost:3000/search" method="get">
<p>
<textarea name="videourl" placeholder="Write your video Url" >
${
videoNum
}
</textarea>
</p>
<p>
<input type="submit">
</p>
</form>
<br>
<br>
<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>
<br>
<br>
${
commentDisplay
}
</body>
</html>
`
;
response
.
writeHead
(
200
);
response
.
end
(
body
);
},
1000
);
})
loadcomment
(
apiKey
,
videoNum
,
npt
,
2
,
response
);
}
});
app
.
listen
(
3000
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment