-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-vod.sh
executable file
·88 lines (79 loc) · 2.1 KB
/
gen-vod.sh
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
#!/bin/sh
HTMLFILE='/srv/videos.html'
HTMLFILENEW='/tmp/videos.html'
# create folder if not mounted
if ! [ -d /vod ]; then mkdir /vod; fi
# convert .flv recording tp .mp4
[ -f "/tmp/$1.flv" ] && (ffmpeg -y -i "/tmp/$1.flv" -c copy -f mp4 "/vod/$1.mp4" || ffmpeg -y -i "/tmp/$1.flv" -f mp4 "/vod/$1.mp4" || rm "/vod/$1.mp4")
# generate html with videojs player
gen_player()
{
if [ -f "/srv/$1.html" ]; then return; fi
printf "<!DOCTYPE html>
<html>
<head>
<title>$1</title>
<link href=\"https://vjs.zencdn.net/7.20.1/video-js.css\" rel=\"stylesheet\" />
</head>
<body style=\"margin:0;\">
<video style=\"width:100vw;height:100vh;\" class=\"video-js\" controls autoplay muted preload=\"auto\" data-setup=\"{}\">
<source src=\"/vod/$1.mp4\" type=\"video/mp4\" />
<p class=\"vjs-no-js\">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href=\"https://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 video</a>
</p>
</video>
<script src=\"https://vjs.zencdn.net/7.20.1/video.min.js\"></script>
</body>
</html>" > "/srv/$1.html"
}
# search vods
FILES=$(find /vod -iname *.mp4 | sort)
# generate html
printf "<!DOCTYPE html>
<html>
<head>
<title>Video on Demand</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
text-align: left;
padding: 4px;
}
</style>
</head>
<h2>Video on Demand</h2>
<table>
<tr>
<th>File</th>
<th>View</th>
<th>Download</th>
<th>Time</th>
<th>Date</th>
</tr>" > "$HTMLFILENEW"
for i in $FILES; do
STAMP=${i##*_}
STAMP=${STAMP%.*}
DATE=$(date -d $STAMP +'%d.%m.%Y')
TIME=$(date -d $STAMP +'%R')
FILE=${i##/vod/}
BASE=${FILE%.*}
gen_player $BASE
printf "
<tr>
<td>${FILE}</td>
<td><a href=\"/$BASE.html\">view</a></td>
<td><a href=\"$i\" download>download</a></td>
<td>$TIME</td>
<td>$DATE</td>
</tr>" >> "$HTMLFILENEW"
done
printf "
</table>
</html>" >> "$HTMLFILENEW"
# update online version
mv "$HTMLFILENEW" "$HTMLFILE"