-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
202 lines (176 loc) · 7.48 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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet/less" type="text/css" href="/style/normalize.less" />
<link rel="stylesheet/less" type="text/css" href="/style/main.less" />
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.3.1/less.min.js"></script>
</head>
<body>
<header>
<div class="logo" data-title="SubSearch">
</div>
<div class="menu">
</div>
<div class="support">
Made with <span class="heart"></span>
</div>
</header>
<main>
<section class="drop" data-title="Drop any number of video files here. click to search"></section>
<section class="thumbnails">
<ul>
</ul>
</section>
</main>
<footer></footer>
<script src="/script/$.js"></script>
<script src="/script/ClassIE.min.js"></script>
<script src="/script/pako.js"></script>
<script src="/script/xml2json.js"></script>
<script src="/script/jszip.js"></script>
<script src="/script/opensubtitles.js"></script>
<script>
var x2js = new X2JS();
var extensions = ['mp4', 'avi', 'mkv', 'mov', 'm4p', 'mpg', 'mpeg', '3gp', 'm2v'];
var items = [];
function prevent(e) {
if(e.preventDefault) {
e.preventDefault();
}
if(e.stopPropagation) {
e.stopPropagation();
}
}
var thumbnails = {};
thumbnails.ul = $('.thumbnails > ul');
thumbnails.draw = function (item) {
var remove = document.createElement('div');
remove.appendChild(document.createTextNode('x'));
remove.setAttribute('class','remove');
var thumbnail = document.createElement('li');
thumbnail.setAttribute('id',item.hash);
thumbnail.appendChild(remove);
thumbnail.appendChild(document.createTextNode(item.name));
thumbnails.ul.appendChild(thumbnail);
};
document.on('dragenter', prevent).on('dragover', prevent).on('drop', prevent);
$('.drop').on('drop', function (e) {
var dropped = e.target.files || e.dataTransfer.files;
for(var i = 0; i < dropped.length; i++) {
if(extensions.indexOf(dropped[i].name.substring(dropped[i].name.lastIndexOf('.')+1)) > -1) {
window.os.hash(dropped[i], function (file, hash) {
for(var j = 0; j < items.length; j++) {
if(items[j].hash === hash) {
alert(items[j].name + ' already added :)');
return false;
}
}
thumbnails.draw(items[items.push({
name: file.name,
size: file.size,
hash: hash
}) - 1]);
});
} else {
alert(dropped[i].name + ' does not have a valid extension :)');
}
}
prevent(e);
});
$('.drop').on('click',function(e) {
window.os.methods.login({ callback: function(login) {
if(!login.error) {
search();
}
}});
});
function search() {
window.os.methods.search({
languages: ['dan','eng'],
items: items,
callback: function(search) {
var subtitles = x2js.xml2json(search.parsed).methodResponse.params.param.value.struct.member[1].value;
if(subtitles.boolean && subtitles.boolean === "0") {
alert("No subtitles found :(");
return false;
}
subtitles = subtitles.array.data.value;
for (var s = 0; s < subtitles.length; s++) {
var subtitle = subtitles[s].struct;
var proper = {};
for (var m = 0; m < subtitle.member.length; m++) {
var member = subtitle.member[m];
proper[member.name] = member.value.string;
}
for (var i = 0; i < items.length; i++) {
if(items[i].hash === proper.MovieHash) {
if(items[i].subtitles === undefined) {
items[i].subtitles = [];
}
items[i].subtitles.push(proper);
break;
}
}
}
}
});
}
//window.os.methods.download({items: [{ id: '1953757678'}], callback:function(a,b) { console.log(a); console.log(b);}});
function order_subtitles() {
/* find out which of the searched subtitles we actually want to download, since we get many subtitles for the same file */
//-2 = force false
//-1 = prefer false
//0 = dont care
//1 = prefer true
//2 = force true
var parameters = {
Hearing_impaired: 1,
languages: ['dan','eng'],
format: 'srt'
};
for(var i = 0; i < items.length; i++) {
items[i].subtitles.sort(function(a,b) {
var language_value = parameters.languages.indexOf(a.SubLanguageID) - parameters.languages.indexOf(b.SubLanguageID);
if(language_value === 0) {
//same language, so we continue in the tiered sorting
var hearing_impaired_value = parseInt(a.SubHearingImpaired,10) - parseInt(b.SubHearingImpaired,10);
if(parameters.Hearing_impaired === 0) {
//next tier
}
return parameters.Hearing_impaired < 0 ? -hearing_impaired_value : hearing_impaired_value;
}
return language_value;
});
}
}
function download(downloads) {
/* download subtitles,
decode base64, gzip decompress(inflate), substring to indexOf(1) to remove any crap in start of string,
convert string into a blob of data, add data to zip.
download zip
*/
window.os.methods.download({
items: indata,
callback: download
});
}
$('.thumbnails').on('click',function(e) {
if(e.srcElement.classList.contains('remove')) {
var thumbnail = e.srcElement.parentElement;
var hash = thumbnail.id;
for(var i = 0; i < items.length; i++) {
if(items[i].hash === hash) {
if(confirm('Are you sure you want to remove this item?')) {
items.splice(i,1);
thumbnail.parentElement.removeChild(thumbnail);
}
prevent(e);
return;
}
}
}
});
</script>
</body>
</html>