-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
337 lines (289 loc) · 13.2 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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style>
/***************************
* Download Video *
***************************/
/* Order elements in the control bar to place a download button after the fullscreen button. */
.video-js .downloadStyle {
order: 9;
-webkit-box-ordinal-group: 9;
-moz-box-ordinal-group: 9;
-webkit-order: 9;
-ms-flex-order: 9;
padding-top: 7px;
background-repeat: no-repeat;
background-position: center center;
cursor: pointer;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' height='24px' viewBox='0 0 24 24' width='24px' fill='%23FFFFFF'%3e%3cpath d='M0 0h24v24H0z' fill='none'/%3e%3cpath d='M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z'/%3e%3c/svg%3e");
}
.video-js .downloadStyle a {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-size: contain;
}
.video-js .downloadStyle.downloading {
background-position: center bottom;
background-size: contain;
cursor: progress;
/* Loading anim By Sam Herbert (@sherb), https://github.com/SamHerbert/SVG-Loaders */
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg width='120' height='30' viewBox='0 0 120 30' xmlns='http://www.w3.org/2000/svg' fill='%23fff'%3e%3ccircle cx='15' cy='15' r='15'%3e%3canimate attributeName='r' from='15' to='15' begin='0s' dur='0.8s' values='15;9;15' calcMode='linear' repeatCount='indefinite' /%3e%3canimate attributeName='fill-opacity' from='1' to='1' begin='0s' dur='0.8s' values='1;.5;1' calcMode='linear' repeatCount='indefinite' /%3e%3c/circle%3e%3ccircle cx='60' cy='15' r='9' fill-opacity='0.3'%3e%3canimate attributeName='r' from='9' to='9' begin='0s' dur='0.8s' values='9;15;9' calcMode='linear' repeatCount='indefinite' /%3e%3canimate attributeName='fill-opacity' from='0.5' to='0.5' begin='0s' dur='0.8s' values='.5;1;.5' calcMode='linear' repeatCount='indefinite' /%3e%3c/circle%3e%3ccircle cx='105' cy='15' r='15'%3e%3canimate attributeName='r' from='15' to='15' begin='0s' dur='0.8s' values='15;9;15' calcMode='linear' repeatCount='indefinite' /%3e%3canimate attributeName='fill-opacity' from='1' to='1' begin='0s' dur='0.8s' values='1;.5;1' calcMode='linear' repeatCount='indefinite' /%3e%3c/circle%3e%3c/svg%3e ");
}
</style>
</head>
<body>
<video-js id="myPlayerID"
data-video-id="4457254747001"
data-account="1752604059001"
data-player="S10RYv9QG"
data-embed="default"
data-application-id
class="video-js"
controls
width="800" height="451"></video-js>
<script src="https://players.brightcove.net/1752604059001/S10RYv9QG_default/index.min.js"></script>
<script type="text/javascript">
videojs.getPlayer('myPlayerID').ready(function () {
// Create variables and new div, anchor and image for download icon
var myPlayer = this,
videoName,
totalRenditions,
mp4Ara = [],
highestQuality,
spacer,
newElement = document.createElement('div'),
newLink = document.createElement('a');
myPlayer.on('loadstart', function () {
//Reinitialize array of MP4 renditions in case used with playlist
//This prevents the array having a cumulative list for all videos in playlist
mp4Ara = [];
// +++ Get video name and the MP4 renditions +++
videoName = myPlayer.mediainfo['name'];
videoName = removeSpaces(videoName);
rendtionsAra = myPlayer.mediainfo.sources;
totalRenditions = rendtionsAra.length;
// +++ Loop over videos and extract only MP4 versions +++
for (var i = 0; i < totalRenditions; i++) {
if (rendtionsAra[i].container === "MP4" && rendtionsAra[i].hasOwnProperty('src')) {
mp4Ara.push(rendtionsAra[i]);
};
};
// +++ Sort the renditions from highest to lowest on size+++
mp4Ara.sort(function (a, b) {
return b.size - a.size;
});
// +++ Extract the highest rendition +++
highestQuality = mp4Ara[0].src;
// +++ Build the download image element +++
newElement.className = 'vjs-control downloadStyle';
newLink.href = highestQuality;
newLink.title = 'Download ' + myPlayer.mediainfo.name;
// +++ On image click call the download function +++
newLink.onclick = function (event) {
// The link could be right-clicked for download as...
event.preventDefault();
if (newElement.classList.contains('downloading')) {
// Do nothing if already downloading.
return;
}
newElement.classList.add('downloading');
newLink.title = 'Downloading ' + myPlayer.mediainfo.name;
// The download function forces download by the browsers
// NOT opening the video in a new window/tab
var x = new XMLHttpRequest();
x.open("GET", highestQuality, true);
x.responseType = 'blob';
x.onload = function (e) {
newElement.textContent = '';
newElement.classList.remove('downloading');
newLink.title = 'Download ' + myPlayer.mediainfo.name;
download(x.response, videoName, "video/mp4");
}
x.onprogress = function (event) {
var progress = Math.floor(event.loaded / (event.total / 100));
newElement.textContent = progress + '%';
newLink.title = 'Downloading ' + myPlayer.mediainfo.name + ' - ' + progress + '%';
}
x.send();
}
newElement.appendChild(newLink);
// +++ Place the download image +++
// Get a handle on the spacer element
spacer = myPlayer.controlBar.customControlSpacer.el();
// Set the content of the spacer to be right justified
spacer.setAttribute("style", "justify-content: flex-end;");
// Place the new element in the spacer
spacer.appendChild(newElement);
})
/*
* remove spaces from a string
* @param {String} str string to process
* @return {String} trimmed string
*/
function removeSpaces(str) {
// remove spaces and periods
str = str.replace(/\s/g, '');
str = str.replaceAll('.', '');
return str;
}
});
//download.js v4.2, by dandavis; 2008-2016. [CCBY2] see http://danml.com/download.html for tests/usage
// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
// v4 adds AMD/UMD, commonJS, and plain browser support
// v4.1 adds url download capability via solo URL argument (same domain/CORS only)
// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
// https://github.com/rndme/download
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.download = factory();
}
}(this, function () {
return function download(data, strFileName, strMimeType) {
var self = window, // this script is only for browsers anyway...
defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads
mimeType = strMimeType || defaultMime,
payload = data,
url = !strFileName && !strMimeType && payload,
anchor = document.createElement("a"),
toString = function (a) {
return String(a);
},
myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString),
fileName = strFileName || "download",
blob,
reader;
myBlob = myBlob.call ? myBlob.bind(self) : Blob;
if (String(this) === "true") { //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
payload = [payload, mimeType];
mimeType = payload[0];
payload = payload[1];
}
if (url && url.length < 2048) { // if no filename and no mime, assume a url was passed as the only argument
fileName = url.split("/").pop().split("?")[0];
anchor.href = url; // assign href prop to temp anchor
if (anchor.href.indexOf(url) !== -1) { // if the browser determines that it's a potentially valid url path:
var ajax = new XMLHttpRequest();
ajax.open("GET", url, true);
ajax.responseType = 'blob';
ajax.onload = function (e) {
download(e.target.response, fileName, defaultMime);
};
setTimeout(function () {
ajax.send();
}, 0); // allows setting custom ajax headers using the return:
return ajax;
} // end if valid url?
} // end if url?
//go ahead and download dataURLs right away
if (/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)) {
if (payload.length > (1024 * 1024 * 1.999) && myBlob !== toString) {
payload = dataUrlToBlob(payload);
mimeType = payload.type || defaultMime;
} else {
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
navigator.msSaveBlob(dataUrlToBlob(payload), fileName) :
saver(payload); // everyone else can save dataURLs un-processed
}
} //end if dataURL passed?
blob = payload instanceof myBlob ?
payload :
new myBlob([payload], {
type: mimeType
});
function dataUrlToBlob(strUrl) {
var parts = strUrl.split(/[:;,]/),
type = parts[1],
decoder = parts[2] == "base64" ? atob : decodeURIComponent,
binData = decoder(parts.pop()),
mx = binData.length,
i = 0,
uiArr = new Uint8Array(mx);
for (i; i < mx; ++i) uiArr[i] = binData.charCodeAt(i);
return new myBlob([uiArr], {
type: type
});
}
function saver(url, winMode) {
if ('download' in anchor) { //html5 A[download]
anchor.href = url;
anchor.setAttribute("download", fileName);
anchor.className = "download-js-link";
anchor.innerHTML = "downloading...";
anchor.style.display = "none";
document.body.appendChild(anchor);
setTimeout(function () {
anchor.click();
document.body.removeChild(anchor);
if (winMode === true) {
setTimeout(function () {
self.URL.revokeObjectURL(anchor.href);
}, 250);
}
}, 66);
return true;
}
// handle non-a[download] safari as best we can:
if (/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
url = url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
if (!window.open(url)) { // popup blocked, offer direct download:
if (confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")) {
location.href = url;
}
}
return true;
}
//do iframe dataURL download (old ch+FF):
var f = document.createElement("iframe");
document.body.appendChild(f);
if (!winMode) { // force a mime that will download:
url = "data:" + url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
}
f.src = url;
setTimeout(function () {
document.body.removeChild(f);
}, 333);
} //end saver
if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
return navigator.msSaveBlob(blob, fileName);
}
if (self.URL) { // simple fast and modern way using Blob and URL:
saver(self.URL.createObjectURL(blob), true);
} else {
// handle non-Blob()+non-URL browsers:
if (typeof blob === "string" || blob.constructor === toString) {
try {
return saver("data:" + mimeType + ";base64," + self.btoa(blob));
} catch (y) {
return saver("data:" + mimeType + "," + encodeURIComponent(blob));
}
}
// Blob but not URL support:
reader = new FileReader();
reader.onload = function (e) {
saver(this.result);
};
reader.readAsDataURL(blob);
}
return true;
}; /* end download() */
}));
</script>
</body>
</html>