Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FitUrRing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wss9
FitUrRing
Commits
993a0c8e
Commit
993a0c8e
authored
6 months ago
by
다인 김
Browse files
Options
Downloads
Patches
Plain Diff
Delete fetchYoutube.js
parent
d4daa487
No related branches found
No related tags found
1 merge request
!44
Feat/router
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
back/src/utils/fetchYoutube.js
+0
-51
0 additions, 51 deletions
back/src/utils/fetchYoutube.js
with
0 additions
and
51 deletions
back/src/utils/fetchYoutube.js
deleted
100644 → 0
+
0
−
51
View file @
d4daa487
require
(
'
dotenv
'
).
config
();
const
fetchVidLength
=
require
(
'
./fetchVideoLength
'
);
// API 키를 사용하여 유튜브 API에 검색 요청 보내기
async
function
fetchYoutube
(
query
,
iteration
,
videoObject
,
pageToken
=
''
)
{
const
fetchUrl
=
`https://www.googleapis.com/youtube/v3/search?part=snippet&q=
${
encodeURIComponent
(
query
)}
&type=video&maxResults=10&videoType=any&key=
${
process
.
env
.
YOUTUBE_API_KEY
}
&pageToken=
${
pageToken
}
`
;
if
(
iteration
>=
maxiterations
)
{
return
;
}
iteration
++
;
try
{
const
response
=
await
fetch
(
fetchUrl
);
const
data
=
await
response
.
json
();
const
results
=
await
Promise
.
all
(
data
.
items
.
map
(
async
item
=>
{
let
{
videoLength
,
videoLikes
,
channelTitle
}
=
await
fetchVidLength
(
item
.
id
.
videoId
);
return
{
video_id
:
item
.
id
.
videoId
,
video_title
:
item
.
snippet
.
title
,
video_description
:
item
.
snippet
.
description
,
video_tag
:
query
,
// 검색 키워드가 들어가게 된다.
video_length
:
videoLength
,
//videoLength 값 사용
video_likes
:
videoLikes
,
channel_title
:
channelTitle
,
//채널명 추가
};
})
);
videoObject
.
push
(...
results
);
//video_object에 추가
//페이지 토큰 설정
let
nextPageToken
=
data
.
nextPageToken
;
//다음페이지 진행
if
(
nextPageToken
)
{
await
fetchYoutube
(
query
,
iteration
,
videoObject
,
nextPageToken
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error during API request:
'
,
err
);
}
}
module
.
export
=
fetchYoutube
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment