-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
167 lines (132 loc) · 5.8 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Download video/audio</title>
<!-- Bootstrap core CSS -->
<link href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="text-center">
<div class="form-signin" style="width: 630px; margin: auto; margin-top: 50px;">
<h1 class="h3 mb-3 font-weight-normal">Download video/audio(s)</h1>
<label for="inputUrls" class="sr-only">Youtube (or not) Url(s)</label>
<textarea id="inputUrls" name="urls" class="form-control" placeholder="Youtube (or not) Url(s)" required autofocus></textarea>
<div class="checkbox mb-3 mt-2">
<label><input type="checkbox" name="onlyAudio" value="true" /> Only audio</label>
| <label><input type="checkbox" name="ignorePlaylists" value="true" checked /> Ignore Playlists</label>
| <label><input type="checkbox" name="autoBrowserDownload" value="true" /> Auto Browser Download</label>
| <label>Video Quality <select name="videoQuality">
<option value="best">Best</option>
<option value="fhd" selected>Full HD</option>
<option value="hd">HD</option>
</select></label>
</div>
<button class="btn btn-lg btn-primary btn-block" id="submit">Download</button>
<div id="list" style="margin-top: 30px">
<table style="display: none" class="table">
<tr><th>Urls</th><th>Status</th><th>Actions</th></tr>
</table>
</div>
</div>
<script type="text/javascript">
// Sorry, I did random code and I don't really not what I do
// It works on GG Chrome ahah, we're wishing for the best
const textarea = document.querySelector('#inputUrls')
const scrollOffsetDiff = Math.abs(textarea.scrollHeight - textarea.offsetHeight)
textarea.style.minHeight = textarea.offsetHeight + 'px'
document.querySelector('input[name="onlyAudio"]').onchange = function() {
document.querySelector('select[name="videoQuality"]').disabled = this.checked
}
textarea.oninput = () => {
textarea.style.height = (textarea.scrollHeight + scrollOffsetDiff) + 'px'
}
async function refreshList() {
const response = await fetch('/downloads')
if (!response.ok) {
throw new Error(await response.text())
}
const downloads = await response.json()
const list = document.querySelector('#list table')
const tbody = list.querySelector('tbody')
if (!downloads.length) {
list.style.display = 'none'
return
}
const header = tbody.querySelector('tr')
tbody.innerHTML = ''
tbody.append(header)
downloads.forEach(download => {
const tr = document.createElement('tr')
tbody.append(tr)
const urls = document.createElement('td')
urls.innerText = download.urls.join(', ')
// Yes, very ugly !
urls.innerHTML = urls.innerHTML.replace(/, /g, '<br/>')
tr.append(urls)
const status = document.createElement('td')
status.innerText = download.status
tr.append(status)
const actions = document.createElement('td')
if (!['DONE', 'CANCELED'].includes(download.status)) {
const cancelAction = document.createElement('button')
cancelAction.innerText = 'Cancel'
actions.append(cancelAction)
cancelAction.classList.add('btn')
cancelAction.onclick = async () => {
await fetch('/cancel/' + download.uid)
setTimeout(refreshList, 100)
}
}
if (download.status === 'READY') {
const downloadAction = document.createElement('button')
downloadAction.innerText = 'Download'
actions.append(downloadAction)
const href = '/download/' + download.uid
downloadAction.style.marginTop = '5px'
downloadAction.classList.add('btn')
downloadAction.classList.add('btn-primary')
downloadAction.onclick = () => {
window.location.href = href
setTimeout(refreshList, 100)
}
if (download.autoBrowserDownload) {
setTimeout(() => {
window.location.href = href
setTimeout(refreshList, 100)
}, 100)
}
}
tr.append(actions)
})
list.style.display = 'table'
}
refreshList()
function resetSubmitable() {
document.querySelector('#inputUrls').value = ''
}
setInterval(refreshList, 1000 * 10)
document.querySelector('#submit').onclick = async function () {
const urls = document.querySelector('#inputUrls').value.split('\n').map(v => v.trim()).filter(v => v)
const onlyAudio = document.querySelector('input[name="onlyAudio"]').checked
const ignorePlaylists = document.querySelector('input[name="ignorePlaylists"]').checked
const autoBrowserDownload = document.querySelector('input[name="autoBrowserDownload"]').checked
const videoQuality = document.querySelector('select[name="videoQuality"]').value
try {
const response = await fetch('/download', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ urls, onlyAudio, ignorePlaylists, autoBrowserDownload, videoQuality })
})
if (!response.ok) {
throw new Error(await response.text())
}
refreshList()
resetSubmitable()
} catch (e) {
alert(e.toString())
}
}
</script>
</body>
</html>