-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-site.js
134 lines (125 loc) · 4.19 KB
/
update-site.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const videos = require('./videos.json');
const dattel = require('dattel-client')({
server_url: process.env.DATTEL_SERVER,
auth_token: process.env.DATTEL_TOKEN,
});
const path = require('path');
const fs = require('fs-extra');
const child_process = require('child_process');
const VIDEOS_DIR = path.join(__dirname, 'videos');
const INPUT_VIDEOS_DIR = path.join(__dirname, 'videos_input');
const OUT_DIR = path.join(__dirname, 'public');
const BASE_URL = 'https://media.dacdn.de';
const TEMPLATE = (v) => `<!DOCTYPE html>
<html>
<head>
<title>${v.title} – media.datenanfragen.de</title>
<script src="https://static.dacdn.de/js/media/clappr.min.js"></script>
<script src="https://static.dacdn.de/js/media/clappr-stats.min.js"></script>
<script src="https://static.dacdn.de/js/media/clappr-nerd-stats.min.js"></script>
<script src="https://static.dacdn.de/js/media/clappr-playback-rate-plugin.min.js"></script>
<script src="https://static.dacdn.de/js/media/clappr-level-selector.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
border: 0;
}
#player {
width: 100vw;
height: 100vh;
}
.cc-controls[data-cc-controls] {
display: block;
}
</style>
</head>
<body>
<div id="player"></div>
<script>
var player = new Clappr.Player({
width: '100%',
height: '100%',
source: "${BASE_URL}/videos/${v.id}/index.m3u8",
poster: '${BASE_URL}/videos/${v.id}/poster.jpg',
playback: {
crossOrigin: 'anonymous',
${v.subtitles ? 'externalTracks: ' + JSON.stringify(v.subtitles) + ',' : ''}
},
parentId: "#player",
plugins: [
PlaybackRatePlugin,
ClapprNerdStats, ClapprStats,
LevelSelector
],
clapprStats: {
onReport: function(){}
},
clapprNerdStats: {
shortcut: ['command+shift+s', 'ctrl+shift+s'],
iconPosition: 'none'
},
levelSelectorConfig: {
labelCallback: function(playbackLevel, customLabel) {
return playbackLevel.level.height + 'p';
}
},
playbackRateConfig: {
defaultValue: 1,
options: [
{value: 0.25, label: '0.25x'},
{value: 0.5, label: '0.5x'},
{value: 0.75, label: '0.75x'},
{value: 1, label: '1x'},
{value: 1.5, label: '1.5x'},
{value: 1.75, label: '1.75x'},
{value: 2, label: '2x'},
{value: 2.5, label: '2.5x'},
{value: 3, label: '3x'},
],
},
});
</script>
</body>
</html>`;
async function main() {
fs.removeSync(OUT_DIR);
fs.mkdirpSync(path.join(OUT_DIR, 'embed'));
fs.copyFileSync(path.join(__dirname, 'index.html'), path.join(OUT_DIR, 'index.html'));
for (const v of videos) {
const video_dir = path.join(VIDEOS_DIR, v.id);
if (!fs.pathExistsSync(video_dir)) {
console.log(`Transcoding and uploading new video ${v.id}…`);
child_process.execFileSync(path.join(__dirname, 'video2hls'), [
path.join(INPUT_VIDEOS_DIR, v.in_file),
'--output',
video_dir,
'--hls-segment-prefix',
`${BASE_URL}/videos/${v.id}/`,
'--hls-playlist-prefix',
`${BASE_URL}/videos/${v.id}/`,
]);
}
const content = TEMPLATE(v);
fs.mkdirpSync(path.join(OUT_DIR, 'embed', v.id));
fs.writeFileSync(path.join(OUT_DIR, 'embed', v.id, 'index.html'), content);
child_process.execFileSync(path.join(__dirname, 'upload-video.sh'), [v.id], {
cwd: video_dir,
});
}
if (process.env.DATTEL_SERVER && process.env.DATTEL_TOKEN) {
console.log('Deploying to dattel…');
const site_id = 'dade-media';
try {
await dattel.cancelDeploy(site_id).catch((_) => {});
const deploy_info = (await dattel.startDeploy(site_id)).data.deploy;
await dattel.deployDirectory(site_id, deploy_info.id, deploy_info.files, path.join(__dirname, 'public'));
await dattel.publishDeploy(site_id, deploy_info.id);
} catch (err) {
console.error(err);
}
} else {
console.error('Environment variables DATTEL_SERVER and DATTEL_TOKEN are needed to deploy the site.');
}
}
main();