-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
357 lines (253 loc) · 13.5 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>videojs-linear-tv-prototype Demo</title>
<link href="node_modules/video.js/dist/video-js.css" rel="stylesheet">
<link href="dist/videojs-linear-tv-prototype.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.0/css/bootstrap.min.css">
<style>
#timeline {
position: relative;
width: 100%;
height: 50px;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
#timeline li {
float: left;
display: block;
height: 50px;
border-left: 1px solid #eee;
border-right: 1px solid #fff;
}
#timeline span.current {
position: absolute;
width: 5px;
display: block;
height: 50px;
background-color: green;
}
</style>
</head>
<body>
<header>
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
<strong> Linear TV</strong>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
</header>
<main role="main">
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2>This plugin attempts to mimic linear tv add your programs below and click generate tv service button. You can drag and drop added programs.</h2>
<p>You could save the generated json on a server for individual user channels mulitple things could be done with this. Linear TV creates a shared experience so a live chat would be good to implement.</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<video id="videojs-linear-tv-prototype-player" class="video-js vjs-16-9 vjs-default-skin" controls muted></video>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<h3>24 Hour TV Guide</h3>
<ul id="timeline"></ul>
</div>
</div>
<div class="row">
<div class="col-md-3">
<video id="videojs-duration" class="video-js" style="display: none;" controls muted><source src="https://www.youtube.com/watch?v=-A" type="video/youtube"></video>
<form class="mb-3 well">
<div class="form-group">
<label for="media">Program url</label>
<input type="text" class="form-control" name="media" placeholder="media" value="https://www.youtube.com/watch?v=jVKEcUPEF8M" /><br />
</div>
<div class="form-group">
<label for="duration">Duration OPTIONAL - only need if you want to add empty ad blocks</label>
<input type="text" class="form-control" name="duration" placeholder="duration" />
</div>
<input class='add btn btn-primary btn-block mt-3' type='submit' value='Submit' />
</form>
<button class="generate btn btn-primary btn-block">Generate TV Service</button>
</div>
<div class="col-md-9">
<ul id="sortable" class="list-group"></ul>
</div>
</div>
<div class="row mt-4">
<div class="col-md-12">
<h3>Test urls below</h3>
<ul>
<li>6 hours<pre>https://www.youtube.com/watch?v=i56qCzx7g5Q</pre></li>
<li>12 hours<pre>https://www.youtube.com/watch?v=TRgqtaYb4sU</pre></li>
<li><pre>https://s3b-assets-bucket.s3.amazonaws.com/test-videos/ElephantsDream.mp4</pre></li>
<li><pre>https://s3b-assets-bucket.s3.amazonaws.com/test-videos/Sintel.mp4</pre></li>
<li><pre>https://s3b-assets-bucket.s3.amazonaws.com/test-videos/TearsOfSteel.mp4</pre></li>
<li><pre>https://s3b-assets-bucket.s3.amazonaws.com/test-videos/BigBuckBunny.mp4</pre></li>
<li><pre>https://s3b-assets-bucket.s3.amazonaws.com/test-videos/ForBiggerBlazes.mp4</pre></li>
</ul>
</div>
</div>
</div>
</div>
</main>
<ul>
<li><a href="/test/debug.html">Run unit tests in browser.</a></li>
<li><a href="docs/api/">Read generated docs.</a></li>
</ul>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.0/js/bootstrap.bundle.min.js" integrity="sha512-PqRelaJGXVuQ81N6wjUrRQelCDR7z8RvKGiR9SbSxKHPIt15eJDmIVv9EJgwq0XvgylszsjzvQ0+VyI2WtIshQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="node_modules/video.js/dist/video.js"></script>
<script src="assets/youtube.js"></script>
<script src="node_modules/moment/moment.js"></script>
<script src="dist/videojs-linear-tv-prototype.js"></script>
<script>
(function(window, videojs) {
Number.prototype.between = function(a, b) {
var min = Math.min.apply(Math, [a, b]),
max = Math.max.apply(Math, [a, b]);
return this > min && this < max;
};
Number.prototype.between_equals = function(a, b) {
var min = Math.min.apply(Math, [a, b]),
max = Math.max.apply(Math, [a, b]);
return this >= min && this <= max;
};
var programs = [];
var adverts = {
media: {
type: "video/mp4",
src: "https://s3b-assets-bucket.s3.amazonaws.com/test-videos/ForBiggerBlazes.mp4"
}
};
var examplePlayer = videojs('videojs-linear-tv-prototype-player',{
techOrder: ['youtube', 'html5']
});
var linearTvPrototype = examplePlayer.linearTvPrototype({
'programs': programs,
'adverts': adverts
});
// Build TV
var day = moment().startOf('day').unix();
var first_duration, current_duration, updated_time, nextt, nextd;
$('#sortable').sortable({
start: function(event, ui) {
},
change: function(event, ui) {
},
update: function(event, ui) {
updateList();
}
});
$('.generate').click(function (e) {
e.preventDefault();
var json = [];
$('#sortable li').each(function( index, element ) {
json.push({
start: parseInt($(this).attr('data-start')),
end: parseInt($(this).attr('data-start')) + parseInt($(this).attr('data-duration')),
duration: parseInt($(this).attr('data-duration')),
media: {
src: $(this).attr('data-src'),
type: $(this).attr('data-type')
}
});
});
console.log(json);
linearTvPrototype.updateGuide(json);
buildTvGuide(json);
});
// Test player
var durationPlayer = videojs('videojs-duration',{
techOrder: ['youtube', 'html5']
});
$(".add").click(function (e) {
e.preventDefault();
var src = $("input[name='media']").val();
var duration = $("input[name='duration']").val();
if(duration){
var $li = $("<li class='ui-state-default list-group-item' data-src='Adverts' data-duration='" + duration + "'/>").text('Adverts - ' + duration);
$("#sortable").append($li);
$("#sortable").sortable('refresh');
}else{
let mime = 'video/mp4';
if(src.includes("youtube")){
mime = 'video/youtube';
}
durationPlayer.src({src: src, type: mime});
durationPlayer.play();
}
});
durationPlayer.on('loadedmetadata', function (event) {
if (this.hasOwnProperty("tech_")) {
if (this.tech_.hasOwnProperty("ytDuration")) {
this.duration(this.tech_.ytDuration);
}
}
this.pause();
var $li = $("<li class='ui-state-default list-group-item' data-src='" + this.currentSource().src + "' data-type='" + this.currentSource().type + "' data-duration='" + this.duration() + "'/>").text(this.currentSource().src + ' - ' + this.duration());
$("#sortable").append($li);
updateList();
});
function updateList(){
//$('#sortable li').first().data( 'time', day );
$('#sortable li').each(function( index, element ) {
if(index === 0){
first_duration = parseInt($(this).attr('data-duration'));
$(this).attr('data-start', day);
$(this).html(
'Src: ' + $(this).attr('data-src') +
'<br>Starts: ' + moment.unix(day).format("MM/DD/YYYY HH:mm:ss") +
'<br>End: ' + moment.unix(day+first_duration).format("MM/DD/YYYY HH:mm:ss") +
'<br>Duration: ' + first_duration
);
}else{
// second
nextt = parseInt($(this).prev().attr('data-start'));
nextd = parseInt($(this).prev().attr('data-duration'));
current_duration = parseInt($(this).attr('data-duration'));
updated_time = (nextt+nextd);
$(this).attr('data-start', updated_time);
$(this).html(
'Src: ' + $(this).attr('data-src') +
'<br>Starts: ' + moment.unix(updated_time).format("MM/DD/YYYY HH:mm:ss") +
'<br>End: ' + moment.unix(updated_time+current_duration).format("MM/DD/YYYY HH:mm:ss") +
'<br>Duration: ' + current_duration
);
}
});
$("#sortable").sortable('refresh');
}
function buildTvGuide(times){
var start = 0;
var diff = Math.round(moment().endOf('day').unix() - moment().startOf('day').unix());
var current = (moment().unix() - moment().startOf('day').unix())/diff*100;
var html = '';
times.forEach((x, i) => {
html += '<li style="width: ' + (x.end-x.start)/diff*100 + '%;" data-toggle="tooltip" data-placement="top" title="' + x.media.src + ' - Start:' + moment.unix(x.start).format("HH:mm:ss") + ' End:' + moment.unix(x.end).format("HH:mm:ss") + '">' + x.media.src + '</li>';
});
html += '<span class="current" style="left: ' + current + '%;" data-toggle="tooltip" data-placement="top" title="Current time ' + moment().format("HH:mm:ss") + '"></span>';
document.getElementById('timeline').innerHTML = html;
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
}
}(window, window.videojs));
</script>
</body>
</html>