-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
112 lines (105 loc) · 3.36 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
<html>
<head>
<title>torrentify!</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <!-- load bootstrap via CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <!-- load jquery via CDN -->
<style>
.container {
width: 500px;
}
</style>
</head>
<body>
<div class="container center-block text-center">
<h2>Torrentify!</h2>
<ol style="width: 250px; margin-left: auto; margin-right: auto;">
<li>Enter URL to file</li>
<li>Torrentify!</li>
<li>Download torrent</li>
</ol>
<div id="name-group" class="form-group">
<label for="url">URL to file</label>
<input type="text" class="form-control" name="url"
placeholder="http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz">
</div>
<div class="row center-block">
<div class="col-xs-6">
<button type="submit" style="width:100%" class="btn btn-primary" id="torrentify">Torrentify!</button>
</div>
<div class="col-xs-6">
<a><button type="submit" style="width:100%" class="btn btn-primary disabled" id="download">Download Torrent!</button></a>
</div>
</div>
<br/>
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
</div>
<div class="">
</div>
</div>
</div>
</body>
<script>
url = null;
basename = null;
poll = null;
failures = 0;
max_failures = 9;
safe_b64encode = function(s) {
new_s = btoa(s);
new_s = new_s.replace(/\+/g, "-");
new_s = new_s.replace(/\//g, "_");
new_s = new_s.replace(/=/g, "");
return(new_s);
}
poll_status = function() {
$.get('query.php', {'url': url}).done(function(data) {
data = JSON.parse(data);
console.log(data);
if (data['status']!='ERROR'){
current = parseInt(data.progress.split('/')[0]);
total = parseInt(data.progress.split('/')[1]);
percentage = current/total * 100;
$('.progress-bar').css('width', (percentage)+'%').attr('aria-valuenow', percentage);
if (percentage==100) {
$('.progress-bar').text('Done! Click "Download Torrent!"');
} else {
$('.progress-bar').text(data['progress'] + ' bytes processed.');
}
if (current==total) {
clearInterval(poll);
$('#torrentify').removeClass('disabled');
$('#download').removeClass('disabled');
$("a").attr("href", "torrents/" + safe_b64encode(url) + "/" + basename + ".torrent");
console.log('done!');
}
} else if (failures < max_failures) {
console.log("Trying again...");
failures += 1;
} else {
clearInterval(poll);
alert("Bad URL!");
$('#torrentify').removeClass('disabled');
}
});
}
$(document).ready(function() {
// form submission
$('#torrentify').click(function(event) {
$('.form-group').removeClass('has-error');
$('.help-block').remove();
url = $.trim($('input[name=url]').val());
basename = url.split("/").slice(-1)[0];
failures = 0;
$.get('create.php', {'url': url});
$('.progress-bar').css('width', '0%').attr('aria-valuenow', 0);
$('.progress-bar').text('');
setTimeout(function(){
$('#torrentify').addClass('disabled');
// begin polling
poll = setInterval(poll_status, 500);
}, 2000);
});
});
</script>
</html>