This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.js
executable file
·221 lines (221 loc) · 7.71 KB
/
docs.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
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
"use strict";
var videoPlayer, audioPlayer, currentMode, embedMode, currentPlayer;
$(document).ready(function() {
videoPlayer = ".video .js-media-player";
audioPlayer = ".audio .js-media-player";
function init() {
resetVar();
$(".video, .audio, .track").hide();
defaultStatus();
$(".btn--url").on("mouseenter click", function() {
$("input[type=text]").focus();
});
$(".btn").mouseleave(function() {
$("input").blur();
});
$("#up").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
}
function resetVar() {
currentMode = null;
embedMode = null;
currentPlayer = null;
}
function setupPlayer(player) {
return plyr.setup(player, {
iconUrl: './plyr.svg',
tooltips: true,
volume: 10,
seekTime: 3,
captions: {
defaultActive: true
},
debug: true
})[0];
}
function killPlayer()
{
currentPlayer.pause();
$("input").blur();
$("." + currentMode).hide();
currentPlayer.destroy();
}
function defaultStatus() {
$("#status").text("Subtitle option will be available after video is selected");
}
function loadingSourceStatus() {
$("#status").text("Loading " + currentMode + "... This might take a while, and your browser might freeze or crash");
}
function readySourceStatus() {
$("#status").text("Your " + currentMode + " is ready!");
setTimeout(defaultStatus, 10000);
}
function loadingTrackStatus() {
$("#status").text("Loading subtitle... You might encounter sync problem while playing");
}
function readyTrackStatus() {
$("#status").text("Subtitle is ready!");
setTimeout(defaultStatus, 10000);
}
function showPlayer(source) {
if (embedMode !== null) {
currentPlayer.source({
type: currentMode,
sources: [{
src: source,
type: embedMode
}]
});
} else {
currentPlayer.source({
type: currentMode,
sources: [{
src: source
}]
});
}
$("." + currentMode).show();
}
function videoMode() {
currentMode = "video";
currentPlayer = setupPlayer(videoPlayer);
currentPlayer.on("loadstart", function() {
$(".track").show();
readySourceStatus();
});
}
function videoEmbedMode(videoSite) {
embedMode = videoSite;
videoMode();
}
function audioMode() {
currentMode = "audio";
currentPlayer = setupPlayer(audioPlayer);
currentPlayer.on("loadstart", function() {
readySourceStatus();
});
}
$(document).keydown(function(event) {
if ($("input:focus").length == 0 && currentMode !== null) {
switch(event.which) {
case 8: //backspace or delete
currentPlayer.toggleMute();
return false;
case 9: //tab
if (currentMode == "video") {
currentPlayer.toggleCaptions();
}
return false;
case 13: //enter
if (currentMode == "video") {
currentPlayer.toggleFullscreen();
}
return false;
case 27: //esc
currentPlayer.restart();
return false;
case 32: //spacebar
currentPlayer.togglePlay();
return false;
case 37: //left arrow
currentPlayer.rewind();
return false;
case 38: //up arrow
currentPlayer.setVolume(currentPlayer.media.volume * 10 + 1);
return false;
case 39: //right arrow
currentPlayer.forward();
return false;
case 40: //down arrow
currentPlayer.setVolume(currentPlayer.media.volume * 10 - 1);
return false;
}
}
});
$("input[type=file][name=source]").change(function() {
var source = this.files[0];
if (source !== undefined) {
if (currentMode !== null) {
killPlayer();
resetVar();
}
if (source.type.match(/^video/) !== null) {
videoMode();
} else if (source.type.match(/^audio/) !== null) {
audioMode();
}
if (currentMode !== null) {
$("input[type=text][name=source]").val("");
loadingSourceStatus();
var reader = new FileReader();
reader.onload = function(event) {
showPlayer(event.target.result);
}
reader.readAsDataURL(source);
} else {
$("#status").text("Not supported format... Officially support MP4, WEBM, MP3, WAV and OGG formats");
setTimeout(defaultStatus, 5000);
}
}
});
$("input[type=text][name=source]").change(function() {
var source = $(this).val();
if (source !== undefined && source.length > 0) {
if (currentMode !== null) {
killPlayer();
resetVar();
}
if (source.match(/^(\w|-){11}$/) !== null) {
videoEmbedMode("youtube");
} else if (source.match(/^(\d)$/) !== null) {
videoEmbedMode("vimeo");
} else if (source.match(/\.(mp4|webm|ogv)$/) !== null) {
videoMode();
} else if (source.match(/\.(mp3|wav|ogg)$/) !== null) {
audioMode();
}
if (currentMode !== null) {
loadingSourceStatus();
setTimeout(function() {
showPlayer(source);
}, 1000);
} else {
$("#status").text("Not supported service or format... Officially support YouTube, Vimeo, MP4, WEBM, MP3 and OGG formats");
setTimeout(defaultStatus, 5000);
}
}
});
$("input[name=track]").change(function() {
var track = this.files[0];
if (track !== undefined) {
if (track.name.match(/\.(ass|ssa|srt|vtt)/) !== null) {
loadingTrackStatus();
var reader = new FileReader(), webvtt;
reader.onload = function(event) {
if (track.name.match(/\.(vtt)/) !== null) {
webvtt = event.target.result.replace(/\r?\n|\r|\n/g, "\r\n");
}
else
{
webvtt = webvtt_subtitler(track.name.substr((~-track.name.lastIndexOf(".") >>> 0) + 2), event.target.result);
}
console.log(webvtt);
currentPlayer.source({
tracks: [{
src: "data:text/vtt;base64," + window.btoa(webvtt),
default: true
}]
});
}
reader.readAsText(track);
readyTrackStatus();
} else {
$("#status").text("Not supported format... Officially support ASS, SSA, SRT and VTT formats");
setTimeout(defaultStatus, 5000);
}
}
});
init();
});