Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이승윤
/
OpenSource-MyCookBook
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
이승윤
2021-05-28 18:39:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e814c47ed05d8800d23b86c081fd8118ffe8191c
e814c47e
1 parent
73f8599a
feat: 카테고리별 동영상을 나타내는 src
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
routes/Videos.js
routes/Videos.js
0 → 100644
View file @
e814c47
var
Youtube
=
require
(
'youtube-node'
);
var
youtube
=
new
Youtube
();
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
var
word
=
'백종원'
;
// 검색어 지정
var
limit
=
10
;
// 출력 갯수
var
video
=
[];
var
test
=
'test'
;
var
count
=
0
;
youtube
.
setKey
(
'AIzaSyAsKr_oWGZIBbL5tLdIl98Lf9Pzqj8jX4o'
);
// API 키 입력
youtube
.
addParam
(
'order'
,
'rating'
);
// 평점 순으로 정렬
youtube
.
addParam
(
'type'
,
'video'
);
// 타입 지정
youtube
.
addParam
(
'videoLicense'
,
'creativeCommon'
);
// 크리에이티브 커먼즈 아이템만 불러옴
youtube
.
search
(
word
,
limit
,
function
(
err
,
result
)
{
// 검색 실행
if
(
err
)
{
console
.
log
(
err
);
}
// 에러일 경우 에러공지하고 빠져나감
//console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력
var
items
=
result
[
'items'
];
// 결과 중 items 항목만 가져옴
for
(
var
i
in
items
)
{
var
it
=
items
[
i
];
for
(
var
j
in
it
)
{
if
(
it
[
j
][
'title'
]
!=
null
)
{
var
title
=
it
[
j
][
'title'
];
}
if
(
it
[
j
][
'videoId'
]
!=
null
)
{
var
video_id
=
it
[
j
][
'videoId'
];
}
var
urls
=
'https://www.youtube.com/watch?v='
+
video_id
;
}
var
item
=
{
id
:
count
,
title
:
title
,
video_id
:
video_id
,
urls
:
urls
,
};
count
++
;
video
.
push
(
item
);
}
});
router
.
get
(
'/'
,
function
(
req
,
res
)
{
res
.
render
(
'home'
,
{
videos
:
video
}
// DB에서 받은 videos를 videos변수명으로 내보냄
);
});
module
.
exports
=
router
;
Please
register
or
login
to post a comment