2022-06-14 15:33:34 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2022-06-29 10:35:43 -04:00
|
|
|
<title>Youtube Downloader UI</title>
|
2022-06-14 15:33:34 -04:00
|
|
|
<!-- Diable favicon requests: https://stackoverflow.com/a/13416784 -->
|
|
|
|
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
2022-06-29 10:35:43 -04:00
|
|
|
<script>
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
2022-06-29 17:50:31 -04:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
progressElems = document.querySelectorAll(".ytprogress")
|
|
|
|
progressElems.forEach(function(item) {
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
|
|
|
|
item.innerText = item.dataset.ytid
|
|
|
|
ytid = item.dataset.ytid
|
2022-06-29 10:35:43 -04:00
|
|
|
|
2022-06-29 17:50:31 -04:00
|
|
|
// https://stackoverflow.com/a/47472874
|
|
|
|
var url = new URL("/ws/" + ytid, window.location.href);
|
|
|
|
url.protocol = url.protocol.replace('http', 'ws');
|
2022-06-29 10:35:43 -04:00
|
|
|
|
2022-06-29 17:50:31 -04:00
|
|
|
let socket = new WebSocket(url.href)
|
|
|
|
socket.onmessage = function(event) {
|
|
|
|
item.innerHTML = event.data
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
pendingTitles = document.querySelectorAll(".yttitle")
|
|
|
|
pendingTitles.forEach(function(item) {
|
|
|
|
ytid = item.dataset.ytid
|
|
|
|
fetch("/title/" + ytid).then(function(response) {
|
|
|
|
if(response.ok) {
|
|
|
|
return response.text().then(function(text) {
|
|
|
|
item.innerText = text
|
|
|
|
})
|
|
|
|
}
|
|
|
|
console.log("Response not ok")
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
2022-06-29 10:35:43 -04:00
|
|
|
</script>
|
2022-06-14 15:33:34 -04:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<form method="POST" action="/">
|
|
|
|
<input type="text" name="youtube_url">
|
|
|
|
<input type="submit" value="Ask">
|
|
|
|
</form>
|
|
|
|
<table>
|
|
|
|
<caption>Vidoes</caption>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Date</th>
|
|
|
|
<th>URL</th>
|
|
|
|
<th>Title</th>
|
|
|
|
<th>Link</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{{ range .Items }}
|
|
|
|
<tr>
|
|
|
|
<td>{{ .Date }}</td>
|
|
|
|
<td>{{ .URL }}</td>
|
2022-06-29 17:50:31 -04:00
|
|
|
<td>
|
|
|
|
{{ if eq .Title "Loading" }}
|
|
|
|
<span class="yttitle" data-ytid="{{.Id}}">Loading...</span>
|
|
|
|
{{ else }}
|
|
|
|
{{ .Title }}
|
|
|
|
{{ end }}
|
|
|
|
</td>
|
2022-06-14 15:33:34 -04:00
|
|
|
<td>
|
|
|
|
{{ if eq .Status "Done" }}
|
2022-06-14 21:17:40 -04:00
|
|
|
<a target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
|
2022-06-28 23:02:53 -04:00
|
|
|
{{ else if eq .Status "InProgress" }}
|
2022-06-29 10:35:43 -04:00
|
|
|
<span class="ytprogress" data-ytid="{{.Id}}">In Progress</span>
|
2022-06-14 15:33:34 -04:00
|
|
|
{{ else }}
|
|
|
|
{{ .Status }}
|
|
|
|
{{ end }}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{{ end }}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</body>
|
|
|
|
</html>
|