-
Notifications
You must be signed in to change notification settings - Fork 24
/
videos.js
92 lines (86 loc) · 1.85 KB
/
videos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const axios = require('axios')
const _ = require('lodash')
const YOUTUBE_API_KEY = process.env.YOUTUBE_API_KEY
const videos = {
WORK: [
"DNFtCIzJQ7A",
"g-fGYtagSDY",
"00rPgc0tISM",
"qa9G5EdKiRw",
"3AyH1fBN7ac",
"HQtZ4kud2qA",
"puDQoBPpWyQ",
"A0Scr2TW2ZA",
"2zzj4CO9xSw",
"twZgNP8iZBQ",
"8QlvQC4MXxs",
"PF54jfEFhIM",
"CPQ1budJRIQ",
"_R8gBnhyMSA",
"350F0VsECvo",
"KA-6OwyGGfI",
"Q23Exmnio8s"
],
LIFE: [
"6tbHYvH347A",
"6vuetQSwFW8",
"7_R4AsV2fPI",
"njQcOKOpFwk",
"5g0QHTcwP8k",
"t-H7_aAuiC8",
"5e338_RFOr8",
"U3V701IUZ2E",
"ZkabeHig_r4",
"FK16iXPRAjI",
"4pxiU89O1wE",
"2otRxX6y7mQ",
"bGc9mXhdMkw",
"UMF_oJkOZmg",
"cRMogDrHnMQ",
"pfWGoLj1JCM",
"EyhOmBPtGNM",
"5fOiu0OdpoI",
"DNITe9snHqA",
"GtCD6e1fa_I"
],
GYM: [
"Fh-rCrREEgA",
"xoXYe9e01_Y",
"hV63DbQ_qSc",
"YxzQ6umhH4Q",
"lsSC2vx7zFQ",
"aMGoxlXmA0o",
"at7QvbFy9fM",
"qapsrR8zIJM",
"vnMtpNhcDOE",
"OV6-n5wtCWA",
"lpVRxa9jsrE",
"7fSLbC-1b0Q",
"n_8ZIYxtPvc",
"j0FFNcIYZMI",
"R1JBQMXbN2k",
"B_3pHAhhdM0"
]
}
const getYoutubeVideoMetadata = (videoId) => {
const apiUrl = `https://content.googleapis.com/youtube/v3/videos?id=${videoId}&part=snippet&key=${YOUTUBE_API_KEY}`
return axios.get(apiUrl)
.then(res => {
const video = res.data.items[0].snippet
return {
description: video.description,
thumbnail: (video.thumbnails.high || video.thumbnails.standard).url,
title: video.title,
url: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1'
}
})
}
module.exports = {
getRandomVideo: (category) => {
if (!category) {
category = _.sample(_.keys(videos))
}
const videoId = _.sample(videos[category])
return getYoutubeVideoMetadata(videoId)
}
}