Add HTMX
This commit is contained in:
parent
ad39db4aac
commit
3030588ffd
|
@ -20,6 +20,7 @@ type routes struct {
|
||||||
|
|
||||||
func (r *routes) Register(app *fiber.App) {
|
func (r *routes) Register(app *fiber.App) {
|
||||||
app.Get("/", r.IndexHandler)
|
app.Get("/", r.IndexHandler)
|
||||||
|
app.Get("/home", r.HomeHandler)
|
||||||
app.Get("/download", r.DownloadHandler)
|
app.Get("/download", r.DownloadHandler)
|
||||||
app.Head("/download/proxy", r.DownloadProxyHandler)
|
app.Head("/download/proxy", r.DownloadProxyHandler)
|
||||||
app.Get("/download/proxy", r.DownloadProxyHandler)
|
app.Get("/download/proxy", r.DownloadProxyHandler)
|
||||||
|
@ -35,6 +36,13 @@ func (r *routes) IndexHandler(c *fiber.Ctx) error {
|
||||||
}, "views/layouts/main")
|
}, "views/layouts/main")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *routes) HomeHandler(c *fiber.Ctx) error {
|
||||||
|
return c.Render("views/index", fiber.Map{
|
||||||
|
"BasePath": viper.GetString("base_path"),
|
||||||
|
"Flash": flash.Get(c),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (r *routes) DownloadHandler(c *fiber.Ctx) error {
|
func (r *routes) DownloadHandler(c *fiber.Ctx) error {
|
||||||
urlBytes, err := url.QueryUnescape(c.Query("url"))
|
urlBytes, err := url.QueryUnescape(c.Query("url"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,14 +68,11 @@ func (r *routes) DownloadHandler(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Render("views/download", fiber.Map{
|
return c.Render("views/download", fiber.Map{
|
||||||
"BasePath": viper.GetString("base_path"),
|
"BasePath": viper.GetString("base_path"),
|
||||||
"Url": url,
|
"Url": url,
|
||||||
"Meta": meta,
|
"Meta": meta,
|
||||||
"Videos": GetVideos(meta),
|
"Videos": GetVideos(meta),
|
||||||
"Version": version.Version,
|
})
|
||||||
"Build": version.Build,
|
|
||||||
"YtdlpVersion": r.ytdl.Version,
|
|
||||||
}, "views/layouts/main")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *routes) DownloadProxyHandler(c *fiber.Ctx) error {
|
func (r *routes) DownloadProxyHandler(c *fiber.Ctx) error {
|
||||||
|
|
|
@ -2,35 +2,50 @@
|
||||||
<h1>Download Video</h1>
|
<h1>Download Video</h1>
|
||||||
<h2 class="fs-4 text-muted text-center">{{.Meta.Title}}</h2>
|
<h2 class="fs-4 text-muted text-center">{{.Meta.Title}}</h2>
|
||||||
<p style="font-size: 0.85rem">{{.Url}}</p>
|
<p style="font-size: 0.85rem">{{.Url}}</p>
|
||||||
<a href="{{.BasePath}}/" class="btn btn-secondary btn-sm mt-3" style="width: 30rem; max-width: 100%">
|
<button
|
||||||
|
hx-get="{{.BasePath}}/home"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#main-content"
|
||||||
|
class="btn btn-secondary btn-sm mt-3"
|
||||||
|
style="width: 30rem; max-width: 100%"
|
||||||
|
>
|
||||||
Download Another Video
|
Download Another Video
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{$root := .}}
|
{{$root := .}} {{range $vidIndex, $video := .Videos}} {{if not (eq $vidIndex
|
||||||
|
0)}}
|
||||||
{{range $vidIndex, $video := .Videos}}
|
|
||||||
{{if not (eq $vidIndex 0)}}
|
|
||||||
<hr class="mt-5" />
|
<hr class="mt-5" />
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="d-flex flex-column flex-lg-row justify-content-center gap-5 mt-5">
|
<div class="d-flex flex-column flex-lg-row justify-content-center gap-5 mt-5">
|
||||||
<div class="d-flex justify-content-center">
|
<div class="d-flex justify-content-center">
|
||||||
<img src="{{.Meta.Thumbnail}}" alt="{{.Meta.Title}}" style="max-height: 25rem; max-width: 100%; margin: 0 auto;" />
|
<img
|
||||||
|
src="{{.Meta.Thumbnail}}"
|
||||||
|
alt="{{.Meta.Title}}"
|
||||||
|
style="max-height: 25rem; max-width: 100%; margin: 0 auto"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="downloads flex-lg-grow-1">
|
<div class="downloads flex-lg-grow-1">
|
||||||
{{range $index, $format := $video.Formats}}
|
{{range $index, $format := $video.Formats}}
|
||||||
<div style="font-size: smaller">{{$format.Format}}</div>
|
<div style="font-size: smaller">{{$format.Format}}</div>
|
||||||
<div class="flex-grow-1 d-flex gap-3">
|
<div class="flex-grow-1 d-flex gap-3">
|
||||||
<a class="btn btn-primary flex-grow-1" download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}" P
|
<a
|
||||||
href="{{$format.Url}}">
|
class="btn btn-primary flex-grow-1"
|
||||||
|
download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}"
|
||||||
|
P
|
||||||
|
href="{{$format.Url}}"
|
||||||
|
>
|
||||||
Download (direct)
|
Download (direct)
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-primary flex-grow-1" download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}"
|
<a
|
||||||
href="{{$root.BasePath}}/download/proxy?url={{queryEscape $root.Url}}&format={{$format.FormatID}}&index={{$vidIndex}}">
|
class="btn btn-primary flex-grow-1"
|
||||||
|
download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}"
|
||||||
|
href="{{$root.BasePath}}/download/proxy?url={{queryEscape $root.Url}}&format={{$format.FormatID}}&index={{$vidIndex}}"
|
||||||
|
>
|
||||||
Download (proxied)
|
Download (proxied)
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -1,32 +1,67 @@
|
||||||
<h1 class="text-center">YTDL Web</h1>
|
<h1 class="text-center">YTDL Web</h1>
|
||||||
<p class="text-center mb-5">
|
<p class="text-center mb-5">
|
||||||
Download videos from over a thousand websites with the help of
|
Download videos from over a thousand websites with the help of
|
||||||
<a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a>,
|
<a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a>, a fork of youtube-dl
|
||||||
a fork of youtube-dl with more features and fixes.
|
with more features and fixes.
|
||||||
<br />
|
<br />
|
||||||
View a complete list of supported websites
|
View a complete list of supported websites
|
||||||
<a href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">here</a>.
|
<a href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md"
|
||||||
|
>here</a
|
||||||
|
>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form action="{{.BasePath}}/download" method="get">
|
<form
|
||||||
|
hx-get="{{.BasePath}}/download"
|
||||||
|
hx-trigger="submit"
|
||||||
|
hx-target="#main-content"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="url" class="form-label visually-hidden">Url</label>
|
<label for="url" class="form-label visually-hidden">Url</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="url" name="url" id="url" class="form-control" required
|
<input
|
||||||
placeholder="Enter url here then click download" />
|
type="url"
|
||||||
<button id="paste-button" class="btn btn-outline-secondary" type="button" title="Paste">
|
name="url"
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
|
id="url"
|
||||||
style="width: 1.5rem; height: 1.5rem">
|
class="form-control"
|
||||||
<path stroke-linecap="round" stroke-linejoin="round"
|
required
|
||||||
d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184" />
|
placeholder="Enter url here then click download"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
id="paste-button"
|
||||||
|
class="btn btn-outline-secondary"
|
||||||
|
type="button"
|
||||||
|
title="Paste"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width="1.5"
|
||||||
|
stroke="currentColor"
|
||||||
|
style="width: 1.5rem; height: 1.5rem"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-grid">
|
<div class="d-grid">
|
||||||
<button type="submit" class="btn btn-primary">Download</button>
|
<button type="submit" class="btn btn-primary">
|
||||||
|
Download
|
||||||
|
<div
|
||||||
|
class="spinner-border spinner-border-sm htmx-indicator ms-1"
|
||||||
|
role="status"
|
||||||
|
>
|
||||||
|
<span class="visually-hidden">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{{if .Flash}}
|
{{if .Flash}}
|
||||||
<div class="alert alert-danger mt-4" role="" alert>{{.Flash.message}}</div>
|
<div class="alert alert-danger mt-4" role="" alert>{{.Flash.message}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,63 +1,84 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" class="h-100">
|
<html lang="en" class="h-100">
|
||||||
|
<head>
|
||||||
<head>
|
<meta charset="UTF-8" />
|
||||||
<meta charset="UTF-8" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<title>YTDL Web</title>
|
||||||
<title>YTDL Web</title>
|
<link
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
|
||||||
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous" />
|
rel="stylesheet"
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css"
|
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
|
||||||
integrity="sha256-R91pD48xW+oHbpJYGn5xR0Q7tMhH4xOrWn1QqMRINtA=" crossorigin="anonymous" />
|
crossorigin="anonymous"
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"
|
/>
|
||||||
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"
|
<link
|
||||||
defer></script>
|
rel="stylesheet"
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js" defer></script>
|
href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css"
|
||||||
<script src="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.js"
|
integrity="sha256-R91pD48xW+oHbpJYGn5xR0Q7tMhH4xOrWn1QqMRINtA="
|
||||||
integrity="sha256-Hgwq1OBpJ276HUP9H3VJkSv9ZCGRGQN+JldPJ8pNcUM=" crossorigin="anonymous" defer></script>
|
crossorigin="anonymous"
|
||||||
<style>
|
/>
|
||||||
#toast-container>div {
|
<script
|
||||||
-moz-box-shadow: none !important;
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"
|
||||||
-webkit-box-shadow: none !important;
|
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
|
||||||
box-shadow: none !important;
|
crossorigin="anonymous"
|
||||||
-ms-filter: none;
|
defer
|
||||||
filter: none;
|
></script>
|
||||||
opacity: 1;
|
<script
|
||||||
}
|
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"
|
||||||
|
defer
|
||||||
.downloads {
|
></script>
|
||||||
display: grid;
|
<script
|
||||||
grid-template-columns: minmax(auto, max-content) auto;
|
src="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.js"
|
||||||
gap: 1.5rem;
|
integrity="sha256-Hgwq1OBpJ276HUP9H3VJkSv9ZCGRGQN+JldPJ8pNcUM="
|
||||||
align-items: center;
|
crossorigin="anonymous"
|
||||||
}
|
defer
|
||||||
|
></script>
|
||||||
.see-more-btn,
|
<script
|
||||||
.collapse {
|
src="https://cdn.jsdelivr.net/npm/htmx.org@1.9.4/dist/htmx.min.js"
|
||||||
grid-column: span 2;
|
integrity="sha256-XIivRAE99i/eil5P31JNihaDSiix0V40rgmUrCfNTH4="
|
||||||
}
|
crossorigin="anonymous"
|
||||||
</style>
|
></script>
|
||||||
</head>
|
<style>
|
||||||
|
#toast-container > div {
|
||||||
<body class="d-flex flex-column h-100" data-bs-theme="dark">
|
-moz-box-shadow: none !important;
|
||||||
<div class="flex-shrink-0">
|
-webkit-box-shadow: none !important;
|
||||||
{{template "views/partials/navbar" .}}
|
box-shadow: none !important;
|
||||||
<main class="container my-5">{{embed}}</main>
|
-ms-filter: none;
|
||||||
</div>
|
filter: none;
|
||||||
{{template "views/partials/footer" .}}
|
opacity: 1;
|
||||||
<script>
|
|
||||||
const pasteButton = document.getElementById("paste-button");
|
|
||||||
const urlField = document.getElementById("url");
|
|
||||||
pasteButton.addEventListener("click", async () => {
|
|
||||||
try {
|
|
||||||
const text = await navigator.clipboard.readText();
|
|
||||||
urlField.value = text;
|
|
||||||
} catch (error) {
|
|
||||||
toastr.error("Failed to paste url from clipboard.");
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
.downloads {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(auto, max-content) auto;
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.see-more-btn,
|
||||||
|
.collapse {
|
||||||
|
grid-column: span 2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="d-flex flex-column h-100" data-bs-theme="dark">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
{{template "views/partials/navbar" .}}
|
||||||
|
<main id="main-content" class="container my-5">{{embed}}</main>
|
||||||
|
</div>
|
||||||
|
{{template "views/partials/footer" .}}
|
||||||
|
<script>
|
||||||
|
const pasteButton = document.getElementById("paste-button");
|
||||||
|
const urlField = document.getElementById("url");
|
||||||
|
pasteButton.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
const text = await navigator.clipboard.readText();
|
||||||
|
urlField.value = text;
|
||||||
|
} catch (error) {
|
||||||
|
toastr.error("Failed to paste url from clipboard.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue