This commit is contained in:
Evan Fiordeliso 2023-08-12 21:09:22 -04:00
parent ad39db4aac
commit 3030588ffd
4 changed files with 168 additions and 92 deletions

View File

@ -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 {
@ -64,10 +72,7 @@ func (r *routes) DownloadHandler(c *fiber.Ctx) error {
"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 {

View File

@ -2,31 +2,46 @@
<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>

View File

@ -1,30 +1,65 @@
<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>

View File

@ -1,23 +1,45 @@
<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" <link
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous" /> href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css" rel="stylesheet"
integrity="sha256-R91pD48xW+oHbpJYGn5xR0Q7tMhH4xOrWn1QqMRINtA=" crossorigin="anonymous" /> integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous" />
defer></script> <link
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js" defer></script> rel="stylesheet"
<script src="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.js" href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css"
integrity="sha256-Hgwq1OBpJ276HUP9H3VJkSv9ZCGRGQN+JldPJ8pNcUM=" crossorigin="anonymous" defer></script> integrity="sha256-R91pD48xW+oHbpJYGn5xR0Q7tMhH4xOrWn1QqMRINtA="
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"
defer
></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"
defer
></script>
<script
src="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.js"
integrity="sha256-Hgwq1OBpJ276HUP9H3VJkSv9ZCGRGQN+JldPJ8pNcUM="
crossorigin="anonymous"
defer
></script>
<script
src="https://cdn.jsdelivr.net/npm/htmx.org@1.9.4/dist/htmx.min.js"
integrity="sha256-XIivRAE99i/eil5P31JNihaDSiix0V40rgmUrCfNTH4="
crossorigin="anonymous"
></script>
<style> <style>
#toast-container>div { #toast-container > div {
-moz-box-shadow: none !important; -moz-box-shadow: none !important;
-webkit-box-shadow: none !important; -webkit-box-shadow: none !important;
box-shadow: none !important; box-shadow: none !important;
@ -38,12 +60,12 @@
grid-column: span 2; grid-column: span 2;
} }
</style> </style>
</head> </head>
<body class="d-flex flex-column h-100" data-bs-theme="dark"> <body class="d-flex flex-column h-100" data-bs-theme="dark">
<div class="flex-shrink-0"> <div class="flex-shrink-0">
{{template "views/partials/navbar" .}} {{template "views/partials/navbar" .}}
<main class="container my-5">{{embed}}</main> <main id="main-content" class="container my-5">{{embed}}</main>
</div> </div>
{{template "views/partials/footer" .}} {{template "views/partials/footer" .}}
<script> <script>
@ -58,6 +80,5 @@
} }
}); });
</script> </script>
</body> </body>
</html> </html>