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
Yuncheol Kwak
2022-05-18 15:02:05 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
25fd4179f51deadb5c2bc083122bd1c702322c52
25fd4179
2 parents
d4d72d65
8cba81be
fix conflict
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
43 deletions
CommentLoadingTest.js
client_secret_197854895056-dk8etrtt0otte8ebrra2c9lvt2k0mff4.apps.googleusercontent.com.json
CommentLoadingTest.js
View file @
25fd417
var
http
=
require
(
'http'
);
var
fs
=
require
(
'fs'
);
//모듈이라 부름
var
fs
=
require
(
'fs'
);
var
url
=
require
(
'url'
);
var
testFolder
=
'./data'
;
var
qs
=
require
(
'querystring'
);
...
...
@@ -11,15 +11,55 @@ let videoNum = "TpPwI_Lo0YY"; //비디오 주소(예시)
var
commentList
=
new
Array
();
var
commentNum
=
0
;
var
savednpt
=
''
const
URLreg1
=
new
RegExp
(
/https
?
:
\/\/
youtu.be
\/
/
);
//유튜브에서 제공하는 동영상 공유 기능을 사용하여 얻은 URL 형식
const
URLreg2
=
new
RegExp
(
/https
?
:
\/\/
www.youtube.com
\/
/
);
//유튜브 주소를 그대로 넣었을 때 URL형식
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>
<a href="http://localhost:3000/search?videourl=
${
VideoNum
}
&nextpage=
${
savednpt
}
"><input type="button" value="댓글 더 불러오기"></a>
<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 +78,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
);
});
...
...
@@ -82,46 +125,17 @@ var app = http.createServer(function(request,response){ // request는 브라우
commentNum
=
0
;
//코멘트 리스트 초기화
videoNum
=
queryData
.
videourl
;
//유튜브 주소를 그대로 넣었을 때 videoNum 추출
if
(
URLreg2
.
test
(
videoNum
)){
let
tempvideoNum
=
url
.
parse
(
videoNum
,
true
).
query
;
videoNum
=
tempvideoNum
.
v
;
}
//유튜브 URL공유 기능을 사용하여 얻은 주소를 넣었을 때 videoNum 추출
videoNum
=
videoNum
.
replace
(
URLreg1
,
""
);
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
);
})
if
(
queryData
.
nextpage
!=
null
)
npt
=
queryData
.
nextpage
loadcomment
(
apiKey
,
videoNum
,
npt
,
2
,
response
);
}
});
app
.
listen
(
3000
);
\ No newline at end of file
...
...
client_secret_197854895056-dk8etrtt0otte8ebrra2c9lvt2k0mff4.apps.googleusercontent.com.json
deleted
100644 → 0
View file @
d4d72d6
{
"web"
:{
"client_id"
:
"197854895056-dk8etrtt0otte8ebrra2c9lvt2k0mff4.apps.googleusercontent.com"
,
"project_id"
:
"youtubecommentseperator"
,
"auth_uri"
:
"https://accounts.google.com/o/oauth2/auth"
,
"token_uri"
:
"https://oauth2.googleapis.com/token"
,
"auth_provider_x509_cert_url"
:
"https://www.googleapis.com/oauth2/v1/certs"
,
"client_secret"
:
"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"
,
"javascript_origins"
:[
"http://localhost:3031"
]}}
\ No newline at end of file
Please
register
or
login
to post a comment