ytui/templates/index.html

120 lines
6.3 KiB
HTML
Raw Normal View History

2022-06-14 15:33:34 -04:00
<!DOCTYPE html>
<html>
<head>
2022-07-14 14:39:59 -04:00
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
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-07-14 14:39:59 -04:00
<link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet" >
2022-06-29 10:35:43 -04:00
<script>
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
2022-07-14 14:39:59 -04:00
window.addEventListener('DOMContentLoaded', () => {
progressElems = document.querySelectorAll("[data-ytstatus=progress")
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-07-14 14:39:59 -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-07-14 14:39:59 -04:00
let socket = new WebSocket(url.href)
socket.onmessage = function(event) {
item.innerHTML = event.data
}
socket.onclose = function(event) {
window.location.reload();
}
});
2022-06-29 17:50:31 -04:00
2022-07-14 14:39:59 -04:00
pendingTitles = document.querySelectorAll("[data-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>
2022-07-14 14:39:59 -04:00
<h1 class="text-center"> {{ .Foo }} </h1>
<div class="container">
<div class="row my-4 text-center">
<form method="POST" action="/">
<input class="col-md-8 h-100" placeholder="Enter video link" type="text" name="youtube_url">
<input class="btn btn-outline-primary mx-2" type="submit" value="Download">
</form>
</div>
<div class="row row-cols-1 row-cols-md-3 row-cols-lg-4 m-4 g-3">
{{ range .Items }}
<div class="col my-2">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">
{{ if eq .Title "Loading" }}
<span data-yttitle="" data-ytid="{{.Id}}">Loading...</span>
{{ else }}
{{ .Title }}
{{ end }}
</h5>
<h6 class="card-subtitle mb-2 text-muted">On {{ .Date }}</h6>
<a href="{{ .URL }}" class="card-link d-block mb-2">Youtube Link</a>
{{ if eq .Status "Done" }}
<a class="btn btn-primary w-100" target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
{{ else if eq .Status "InProgress" }}
<span class="border border-info w-100 text-center d-block" data-ytstatus="progress" data-ytid="{{.Id}}">In Progress</span>
{{ else }}
<span class="border border-danger w-100 text-center d-block"> {{ .Status }} </span>
{{ end }}
</div>
</div>
</div>
{{ end }}
</div>
<table>
<caption>All 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>
<td>
{{ if eq .Title "Loading" }}
<span data-yttitle="" data-ytid="{{.Id}}">Loading...</span>
{{ else }}
{{ .Title }}
{{ end }}
</td>
<td>
{{ if eq .Status "Done" }}
<a target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
{{ else if eq .Status "InProgress" }}
<span data-ytstatus="progress" data-ytid="{{.Id}}">In Progress</span>
{{ else }}
{{ .Status }}
{{ end }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
2022-06-14 15:33:34 -04:00
</body>
</html>