Update bootstrap, format html files, remove samber/lo dep

This commit is contained in:
Evan Fiordeliso 2024-02-17 11:19:10 -05:00
parent 06ba575c42
commit 74ea23add9
9 changed files with 130 additions and 193 deletions

View File

@ -8,7 +8,6 @@ import (
"sync" "sync"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/samber/lo"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.fifitido.net/ytdl-web/app" "go.fifitido.net/ytdl-web/app"
"go.fifitido.net/ytdl-web/app/models" "go.fifitido.net/ytdl-web/app/models"
@ -138,10 +137,15 @@ func (c *DownloadController) ProxyDownload(w http.ResponseWriter, r *http.Reques
} }
video := videos[index] video := videos[index]
format, ok := lo.Find(video.Formats, func(format metadata.Format) bool {
return format.FormatID == formatId var format *metadata.Format
}) for _, f := range video.Formats {
if !ok { if f.FormatID == formatId {
format = &f
break
}
}
if format == nil {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return return
} }

View File

@ -1,25 +1,36 @@
package models package models
import ( import (
"github.com/samber/lo"
"go.fifitido.net/ytdl-web/pkg/ytdl/metadata" "go.fifitido.net/ytdl-web/pkg/ytdl/metadata"
) )
type Video struct { type Video struct {
Meta *metadata.Metadata Meta *metadata.Metadata
Formats []metadata.Format Formats []metadata.Format
OtherFormats []metadata.Format
} }
func GetVideosFromMetadata(meta *metadata.Metadata) []Video { func GetVideosFromMetadata(meta *metadata.Metadata) []Video {
if meta.IsPlaylist() { if meta.IsPlaylist() {
return lo.Map(meta.Entries, func(video metadata.Metadata, _ int) Video { videos := make([]Video, 0, len(meta.Entries))
return GetVideosFromMetadata(&video)[0]
}) for _, entry := range meta.Entries {
videos = append(videos, GetVideosFromMetadata(&entry)...)
} }
formats := lo.Filter(meta.Formats, func(item metadata.Format, _ int) bool { return videos
return item.ACodec != "none" && item.VCodec != "none" && item.Protocol != "m3u8_native" }
})
formats := []metadata.Format{}
otherFormats := []metadata.Format{}
for _, format := range meta.Formats {
if format.ACodec != "none" && format.VCodec != "none" && format.Protocol != "m3u8_native" {
formats = append(formats, format)
} else {
otherFormats = append(otherFormats, format)
}
}
for i, j := 0, len(formats)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(formats)-1; i < j; i, j = i+1, j-1 {
formats[i], formats[j] = formats[j], formats[i] formats[i], formats[j] = formats[j], formats[i]
@ -29,6 +40,7 @@ func GetVideosFromMetadata(meta *metadata.Metadata) []Video {
{ {
Meta: meta, Meta: meta,
Formats: formats, Formats: formats,
OtherFormats: otherFormats,
}, },
} }
} }

View File

@ -2,47 +2,31 @@
<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 <a href="{{.BasePath}}/" hx-get="{{.BasePath}}/" hx-trigger="click" hx-target="#main-content"
href="{{.BasePath}}/" class="btn btn-secondary btn-sm mt-3" style="width: 30rem; max-width: 100%">
hx-get="{{.BasePath}}/"
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> </a>
</div> </div>
{{$root := .}} {{range $vidIndex, $video := .Videos}} {{if not (eq $vidIndex {{$root := .}}
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 <img src="{{.Meta.Thumbnail}}" alt="{{.Meta.Title}}" style="max-height: 25rem; max-width: 100%; margin: 0 auto" />
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 <a class="btn btn-primary flex-grow-1" download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}" P
class="btn btn-primary flex-grow-1" href="{{$format.Url}}">
download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}"
P
href="{{$format.Url}}"
>
Download (direct) Download (direct)
</a> </a>
<a <a class="btn btn-primary flex-grow-1" download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}"
class="btn btn-primary flex-grow-1" href="{{$root.BasePath}}/download/proxy?url={{queryEscape $root.Url}}&format={{$format.FormatID}}&index={{$vidIndex}}">
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

@ -5,48 +5,21 @@
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" <a href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">here</a>.
>here</a
>.
</p> </p>
<form <form hx-get="{{.BasePath}}/download" hx-trigger="submit" hx-target="#main-content" hx-swap="innerHTML">
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 <input type="url" name="url" id="url" class="form-control" required
type="url" placeholder="Enter url here then click download" />
name="url"
id="url"
class="form-control"
required
placeholder="Enter url here then click download"
/>
{{if .IsSecure}} {{if .IsSecure}}
<button <button id="paste-button" class="btn btn-outline-secondary" type="button" title="Paste">
id="paste-button" <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
class="btn btn-outline-secondary" style="width: 1.5rem; height: 1.5rem">
type="button" <path stroke-linecap="round" stroke-linejoin="round"
title="Paste" 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
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>
{{end}} {{end}}
@ -55,10 +28,7 @@
<div class="d-grid"> <div class="d-grid">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">
Download Download
<div <div class="spinner-border spinner-border-sm htmx-indicator ms-1" role="status">
class="spinner-border spinner-border-sm htmx-indicator ms-1"
role="status"
>
<span class="visually-hidden">Loading...</span> <span class="visually-hidden">Loading...</span>
</div> </div>
</button> </button>
@ -70,19 +40,10 @@
<span>{{.Error.Message}}</span> <span>{{.Error.Message}}</span>
{{if .Error.RetryUrl}} {{if .Error.RetryUrl}}
<button <button class="btn btn-link btn-sm pt-0 lh-base text-decoration-none" hx-get="/download" hx-trigger="click"
class="btn btn-link btn-sm pt-0 lh-base text-decoration-none" hx-target="#main-content" hx-swap="innerHTML" hx-vals='{"url": "{{.Error.RetryUrl}}"}'>
hx-get="/download"
hx-trigger="click"
hx-target="#main-content"
hx-swap="innerHTML"
hx-vals='{"url": "{{.Error.RetryUrl}}"}'
>
<span class="text-decoration-underline">Try Again</span> <span class="text-decoration-underline">Try Again</span>
<div <div class="spinner-border spinner-border-sm htmx-indicator ms-1" role="status">
class="spinner-border spinner-border-sm htmx-indicator ms-1"
role="status"
>
<span class="visually-hidden">Loading...</span> <span class="visually-hidden">Loading...</span>
</div> </div>
</button> </button>

View File

@ -1,45 +1,25 @@
<!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.2/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-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" 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.2/dist/js/bootstrap.bundle.min.js"
/> integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" 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" <script src="https://cdn.jsdelivr.net/npm/htmx.org@1.9.4/dist/htmx.min.js"
/> integrity="sha256-XIivRAE99i/eil5P31JNihaDSiix0V40rgmUrCfNTH4=" crossorigin="anonymous"></script>
<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;
@ -60,9 +40,9 @@
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 "partials/navbar" .}} {{template "partials/navbar" .}}
<main id="main-content" class="container my-5">{{yield}}</main> <main id="main-content" class="container my-5">{{yield}}</main>
@ -90,5 +70,6 @@
htmx.onLoad(setupPaste); htmx.onLoad(setupPaste);
</script> </script>
</body> </body>
</html> </html>

View File

@ -5,9 +5,7 @@
<div class="d-flex gap-1 align-items-baseline"> <div class="d-flex gap-1 align-items-baseline">
Version: Version:
<span class="text-muted">{{.Version}}</span> <span class="text-muted">{{.Version}}</span>
<span class="text-muted text-nowrap" style="font-size: smaller" <span class="text-muted text-nowrap" style="font-size: smaller">(Build: {{.Build}})</span>
>(Build: {{.Build}})</span
>
</div> </div>
<div class="d-flex gap-1 align-items-baseline text-nowrap"> <div class="d-flex gap-1 align-items-baseline text-nowrap">
yt-dlp version: <span class="text-muted">{{.BinaryVersion}}</span> yt-dlp version: <span class="text-muted">{{.BinaryVersion}}</span>

1
go.mod
View File

@ -7,7 +7,6 @@ require (
github.com/dgraph-io/badger/v2 v2.2007.4 github.com/dgraph-io/badger/v2 v2.2007.4
github.com/go-chi/chi/v5 v5.0.10 github.com/go-chi/chi/v5 v5.0.10
github.com/htfy96/reformism v0.0.0-20160819020323-e5bfca398e73 github.com/htfy96/reformism v0.0.0-20160819020323-e5bfca398e73
github.com/samber/lo v1.38.1
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.10.0 github.com/spf13/viper v1.10.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53

2
go.sum
View File

@ -72,8 +72,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=