-
Notifications
You must be signed in to change notification settings - Fork 2
/
insertVideos.js
62 lines (48 loc) · 1.78 KB
/
insertVideos.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
const {addVideo,video,createVideoTable,getAllVideos,getVideobyID, getVideobyHash, dropAllVideos,getPartOfVideobyID,getVideoSizeByID,getRelatedVideos}=require('./database')
const fs=require('fs')
const { getVideoDurationInSeconds } = require('get-video-duration')
// converts seconds to hours:minuts:sec
function secondsToTime(allsec){
allsec=parseInt(allsec)
const hour=parseInt(allsec/60/60)
const min=parseInt(allsec/60)-hour*60
const sec=allsec-min*60-hour*60*60
return `${hour}:${min}:${sec}`
}
async function putinDatabase(){
await new Promise(e=>{
fs.readdir('./videos',(err,files)=>{
const fun=async ()=>{
for(let i=0;i<files.length;i++){
const fullpath=`./videos/${files[i]}`
await new Promise(ee=>{
fs.readFile(fullpath,(err,data)=>{
const v=new video()
v.title=fullpath
v.content=data
v.description="Epstin didnt kill himself"
v.tags="#porn"
v.thumbnail="/thumbnail/0"
v.views=parseInt(Math.random()*1000000)
v.likes=parseInt(Math.random()*v.views)
v.dislikes=v.views-v.likes
getVideoDurationInSeconds(fullpath).then((secs)=>{
v.length=secondsToTime(secs)
addVideo(v)
console.log(`video added ${v.title}`)
ee()
})
})
})
}
e()
}
fun()
})
})
}
async function main(){
createVideoTable()
await putinDatabase()
}
main()