-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
383 lines (339 loc) · 12.9 KB
/
index.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<html>
<head>
<style>
div {
border:1px solid;
align-content: center;
}
div.title {
font-size: 25px;
text-align: center;
}
div.title>span {
color: red;
}
div>div.global-controls{
display: inline-block;
}
.play_speed {
display: inline-block;
padding: 5px;
text-align: center;
}
.controls {
display: inline-block;
padding: 5px;
text-align: center;
}
.showMap > iframe {
width: 600px;
height: 450px;
}
video {
width: 600px;
height: 450px;
}
table tr td {
border:1px solid;
text-align: center;
}
textarea {
width: 100%;
}
div.readme {
padding: 5px;
}
code {
background:lightgrey
}
</style>
</head>
<body>
<div>
<div>
<strong>Select TeslaCam Directory</strong>(Must be in same directory as Index.html):<br/>
<input type="file" id="fileBrowser" accept="video/mp4" webkitdirectory multiple/>
</div>
<div>
Browse Loaded Clips: <select class="date-select"><option>- - - - - -</option></select>
</div>
</div>
<div class="global-controls">
<div class="play_speed">
<span>Play Speed</span><br/>
<button onclick="playRate(0.5)">0.5x</button>
<button onclick="playRate(1)">1x</button>
<button onclick="playRate(2)">2x</button>
<button onclick="playRate(3)">3x</button>
<button onclick="playRate(8)">8x</button>
</div>
<div class="controls">
<span>General Controls</span><br/>
<button class="previous"><<PREV<<</button>
<button class="skip" onclick="skipTo(-5)">-5</button>
<button class="skip" onclick="skipTo(-3)">-3</button>
<button onclick="playPause()">PLAY/PAUSE</button>
<button class="skip" onclick="skipTo(3)">3</button>
<button class="skip" onclick="skipTo(5)">5</button>
<button class="next">>>NEXT>></button>
<input checked type="checkbox" name="autoplay"/>Autoplay
</div>
</div>
<div>
<div class="title">
<span>No Videos Loaded</span>
</div>
<table>
<tr>
<td><video class="left_repeater" src="" controls controlsList="play pause"></video></td>
<td><video class="front" src="" controls controlsList="play pause"></video></td>
<td><video class="right_repeater" src="" controls controlsList="play pause"></video></td>
</tr>
<tr>
<td colspan="1" class="showMap" id="showMap"></td>
<td colspan="1"><video class="back" src="" controls controlsList="play pause"></video></td>
<td colspan="1"></td>
</tr>
</table>
</div>
<div class="readme">
<h2>README</h2>
<hr/>
<strong>Directory Placement</strong><br/>
This <code>index.html</code> file <strong>must</strong> be at the same level as the <code>TeslaCam</code> folder which can be placed directly on the root of the USB drive.<br/>
<strong>Example:</strong><br/>
<code>
Root Folder<br/>
|- index.html<br/>
|- TeslaCam(USB Drive Top Level Folder)<br/>
|- Saved Clips<br/>
|- Sentry Videos<br/>
|- ...<br/>
</code><br/>
</div>
</body>
<script>
var carouselIndex;
var selectItemIndex;
var files;
var playbackRate = 1
var playPauseFlag = true;
var carousel = []
var carouselEventFiles = []
var title = document.querySelector("div.title")
var backVideo = document.querySelector("video.back")
var frontVideo = document.querySelector("video.front")
var leftVideo = document.querySelector("video.left_repeater")
var rightVideo = document.querySelector("video.right_repeater")
var next = document.querySelector("button.next")
var previous = document.querySelector("button.previous")
var setVideos = document.querySelector("button.setVideos")
var dateSelector = document.querySelector("select.date-select")
var skip = document.querySelector("button.skip")
class TeslaCamFile {
separator = "/" //default separator(necessary? not sure)
clipType = "SentryClip" //Recorded/SentryClip...
triggerDate = "" // folder name doubles as the date the video clip was triggered
clipDate = "" // transformed clip name
clipName = "" // the clip name
file = "" // webkit file incase we need other data
constructor(file){
this.clipName = file.name
this.clipDate = Date.parse(this.parseToDate(file.name))
this.getDirectories(file)
//just in case we need it for the future
this.file = file
}
getDirectories(file){
this.separator = file.webkitRelativePath.replace(file.name, "").substr(-1)
var directoryParts = file.webkitRelativePath.split(this.separator)
this.clipType = directoryParts[1]
this.triggerDate = directoryParts[2]
}
//format to ISO(sorta) - no TZ so defaults to local
parseToDate(filename){
let nameArry = filename.split("_");
let dateArry = nameArry[0].split("-");
let hourArry = nameArry[1].split("-");
return dateArry[0]+"-"+dateArry[1]+"-"+dateArry[2]+"T"+hourArry[0]+":"+hourArry[1]+":"+hourArry[2];
}
build(){
var filePath = "TeslaCam" + this.separator + this.clipType
if(this.clipType != "RecentClips"){
filePath += this.separator + this.triggerDate
}
return filePath + this.separator + this.clipName.replace(/-back.mp4$/gm,'')
}
buildEvent(){
var filePath = "TeslaCam" + this.separator + this.clipType
if(this.clipType != "RecentClips"){
filePath += this.separator + this.triggerDate
}
return filePath + this.separator
}
}
//The following code uses webkitdirectory to get all the videos from a directory
document.querySelector("input[type=file][id=fileBrowser]").addEventListener("change", function(e){
var files = e.target.files
tcFiles = []
var eventFiles = {}
//get "back" files to sort from webkitRelativePath
for (let i=0; i<files.length; i++) {
var file = files[i]
if(file.webkitRelativePath.endsWith("-back.mp4")){
var tcFile = new TeslaCamFile(file)
tcFiles.push(tcFile)
}
if(file.webkitRelativePath.endsWith("event.json")){
eventFiles[file.webkitRelativePath] = file
}
}
//Sort the files in ascending date
tcFiles.sort(function(a,b){
var firstDate = a.clipDate
var secondDate = b.clipDate
return firstDate - secondDate
})
// Create dropdown for clips
tmpDir = [] //track dir's added
// if(document.querySelector("select.date-select") != undefined) {
// document.querySelector("select.date-select").remove()
// }
dateSelector.innerHTML = null
tcFiles.forEach((tcFile, index) => {
dir = tcFile.clipType+tcFile.separator+tcFile.triggerDate
if (tcFile.clipType == "RecentClips") {
dir = tcFile.clipType+tcFile.separator+tcFile.clipName.replace(/-back.mp4$/gm,'')
}
if (!tmpDir.includes(dir)) {
tmpDir.push(dir)
var option = document.createElement("option")
option.innerText = dir
option.value = index // assume that the index is going to be the first clip for each new date.
dateSelector.appendChild(option)
}
})
carousel = tcFiles
carouselEventFiles = eventFiles
loadVideos(0)
})
dateSelector.addEventListener("change", function(e){
carouselIndex = parseInt(e.target.options[e.target.selectedIndex].value)
loadVideos(carouselIndex)
})
function loadVideos(index){
title.innerHTML = carousel[index].build()
backVideo.src = carousel[index].build()+"-back.mp4"
frontVideo.src = carousel[index].build()+"-front.mp4"
leftVideo.src = carousel[index].build()+"-left_repeater.mp4"
rightVideo.src = carousel[index].build()+"-right_repeater.mp4"
//load the map window -> display google maps
if (carouselEventFiles[carousel[index].buildEvent()+"event.json"] == undefined) {
document.querySelector("td#showMap").innerHTML = ""
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
var data = JSON.parse(contents)
console.log(data)
var zoom = 2000
var iframe = document.createElement("iframe")
iframe.src = "https://www.google.com/maps/embed?pb=!1m10!1m8!1m3!1d"+zoom+"!2d"+data.est_lon+"!3d"+data.est_lat+"!!!!!!!!!!!"
document.querySelector("td#showMap").innerHTML = ""
document.querySelector("td#showMap").appendChild(iframe)
};
reader.readAsText(carouselEventFiles[carousel[index].buildEvent()+"event.json"]);
}
function playVideos(){
frontVideo.play()
backVideo.play()
leftVideo.play()
rightVideo.play()
frontVideo.playbackRate=playbackRate;
backVideo.playbackRate=playbackRate;
leftVideo.playbackRate=playbackRate;
rightVideo.playbackRate=playbackRate;
}
function playRate(rate){
playbackRate = rate
playVideos()
}
function pauseVideos(){
frontVideo.pause()
backVideo.pause()
leftVideo.pause()
rightVideo.pause()
}
function playPause() {
if (playPauseFlag!=true){
playVideos()
playPauseFlag = true;
} else {
pauseVideos()
playPauseFlag = false;
}
}
let videos = document.querySelectorAll("video");
function skipTo(seconds){
videos.forEach(video => {
video.currentTime += seconds
})
}
//Add listeners for play, pause and click buttons for each video.
videos.forEach(video => {
video.addEventListener("play", function(e){
console.log(e)
playVideos()
})
video.addEventListener("pause", function(e){
console.log(e)
if(e.target.ended){
if(document.querySelector("input[name=autoplay]").checked){
carouselIndex+=1
loadVideos(carouselIndex)
}
} else {
pauseVideos()
}
})
video.addEventListener("click", function(e){
console.log(e)
var currentTime = e.target.currentTime
if(e.target != frontVideo) {
frontVideo.currentTime = currentTime
}
if(e.target != leftVideo) {
leftVideo.currentTime = currentTime
}
if(e.target != rightVideo) {
rightVideo.currentTime = currentTime
}
if(e.target != backVideo) {
backVideo.currentTime = currentTime
}
})
video.addEventListener("canplaythrough", function(e){
console.log("Can Play Through")
if(document.querySelector("input[name=autoplay]").checked){
playVideos()
}
})
})
var carouselIndex = 0
next.addEventListener("click", function(){
carouselIndex+=1
loadVideos(carouselIndex)
})
previous.addEventListener("click", function(){
carouselIndex-=1
loadVideos(carouselIndex)
})
backVideo.addEventListener("ended", function(){
console.log("Ended")
if(document.querySelector("input[name=autoplay]").checked){
carouselIndex+=1
loadVideos(carouselIndex)
}
})
</script>
</html>