ytui/templates/index.html

80 lines
3.8 KiB
HTML
Raw Permalink 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">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' data: ;">
2022-07-14 16:13:27 -04:00
<title>{{ $.Title }}</title>
2022-06-14 15:33:34 -04:00
<!-- Diable favicon requests: https://stackoverflow.com/a/13416784 -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<link href="assets/bootstrap.min.css" rel="stylesheet" >
2022-06-29 10:35:43 -04:00
<script>
2022-07-14 14:39:59 -04:00
window.addEventListener('DOMContentLoaded', () => {
progressElems = document.querySelectorAll("[data-ytstatus=progress]")
progressElems.forEach(item => {
// https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
let ytid = item.innerText = item.dataset.ytid
2022-06-29 10:35:43 -04:00
// https://stackoverflow.com/a/47472874
let url = new URL("/ws/" + ytid, window.location.href);
url.protocol = url.protocol.replace('http', 'ws');
2022-06-29 10:35:43 -04:00
let socket = new WebSocket(url.href)
socket.onmessage = event => item.innerText = event.data
socket.onclose = () => window.location.reload()
});
2022-06-29 17:50:31 -04:00
pendingTitles = document.querySelectorAll("[data-yttitle]")
pendingTitles.forEach(async item => {
let ytid = item.dataset.ytid
let resp = await fetch("/title/" + ytid)
if(resp.ok) {
let text = await resp.text()
item.innerText = text
} else {
console.log("Response not ok: ", response)
}
})
})
2022-06-29 10:35:43 -04:00
</script>
<script src="assets/bootstrap.min.js" defer></script>
2022-06-14 15:33:34 -04:00
</head>
<body>
<h1 class="text-center">{{ $.Title }}</h1>
2022-07-14 14:39:59 -04:00
<div class="container">
<div class="row my-4 text-center">
<form method="post" action="/">
2022-07-14 14:39:59 -04:00
<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>
2022-07-14 16:22:06 -04:00
<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>
2022-07-14 14:39:59 -04:00
{{ else }}
2022-07-14 16:22:06 -04:00
{{ .Title }}
2022-07-14 14:39:59 -04:00
{{ end }}
2022-07-14 16:22:06 -04:00
</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>
2022-07-14 14:39:59 -04:00
{{ if eq .Status "Done" }}
2022-07-14 16:22:06 -04:00
<a class="btn btn-primary w-100" target="_blank" href="{{ $.VidoesUrl }}/{{ .FileName }}">Watch</a>
2022-07-14 14:39:59 -04:00
{{ else if eq .Status "InProgress" }}
2022-07-14 16:22:06 -04:00
<span class="border border-info w-100 text-center d-block" data-ytstatus="progress" data-ytid="{{.Id}}">In Progress</span>
2022-07-14 14:39:59 -04:00
{{ else }}
<span class="border border-danger w-100 text-center d-block">{{ .Status }}</span>
2022-07-14 14:39:59 -04:00
{{ end }}
2022-07-14 16:22:06 -04:00
</div>
</div>
</div>
{{ end }}
</div>
2022-07-14 14:39:59 -04:00
</div>
2022-06-14 15:33:34 -04:00
</body>
</html>