Update bootstrap, format html files, remove samber/lo dep
This commit is contained in:
parent
06ba575c42
commit
74ea23add9
|
@ -8,7 +8,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/viper"
|
||||
"go.fifitido.net/ytdl-web/app"
|
||||
"go.fifitido.net/ytdl-web/app/models"
|
||||
|
@ -138,10 +137,15 @@ func (c *DownloadController) ProxyDownload(w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
|
||||
video := videos[index]
|
||||
format, ok := lo.Find(video.Formats, func(format metadata.Format) bool {
|
||||
return format.FormatID == formatId
|
||||
})
|
||||
if !ok {
|
||||
|
||||
var format *metadata.Format
|
||||
for _, f := range video.Formats {
|
||||
if f.FormatID == formatId {
|
||||
format = &f
|
||||
break
|
||||
}
|
||||
}
|
||||
if format == nil {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,25 +1,36 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"github.com/samber/lo"
|
||||
"go.fifitido.net/ytdl-web/pkg/ytdl/metadata"
|
||||
)
|
||||
|
||||
type Video struct {
|
||||
Meta *metadata.Metadata
|
||||
Formats []metadata.Format
|
||||
OtherFormats []metadata.Format
|
||||
}
|
||||
|
||||
func GetVideosFromMetadata(meta *metadata.Metadata) []Video {
|
||||
if meta.IsPlaylist() {
|
||||
return lo.Map(meta.Entries, func(video metadata.Metadata, _ int) Video {
|
||||
return GetVideosFromMetadata(&video)[0]
|
||||
})
|
||||
videos := make([]Video, 0, len(meta.Entries))
|
||||
|
||||
for _, entry := range meta.Entries {
|
||||
videos = append(videos, GetVideosFromMetadata(&entry)...)
|
||||
}
|
||||
|
||||
formats := lo.Filter(meta.Formats, func(item metadata.Format, _ int) bool {
|
||||
return item.ACodec != "none" && item.VCodec != "none" && item.Protocol != "m3u8_native"
|
||||
})
|
||||
return videos
|
||||
}
|
||||
|
||||
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 {
|
||||
formats[i], formats[j] = formats[j], formats[i]
|
||||
|
@ -29,6 +40,7 @@ func GetVideosFromMetadata(meta *metadata.Metadata) []Video {
|
|||
{
|
||||
Meta: meta,
|
||||
Formats: formats,
|
||||
OtherFormats: otherFormats,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,47 +2,31 @@
|
|||
<h1>Download Video</h1>
|
||||
<h2 class="fs-4 text-muted text-center">{{.Meta.Title}}</h2>
|
||||
<p style="font-size: 0.85rem">{{.Url}}</p>
|
||||
<a
|
||||
href="{{.BasePath}}/"
|
||||
hx-get="{{.BasePath}}/"
|
||||
hx-trigger="click"
|
||||
hx-target="#main-content"
|
||||
class="btn btn-secondary btn-sm mt-3"
|
||||
style="width: 30rem; max-width: 100%"
|
||||
>
|
||||
<a href="{{.BasePath}}/" 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
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{$root := .}} {{range $vidIndex, $video := .Videos}} {{if not (eq $vidIndex
|
||||
0)}}
|
||||
{{$root := .}}
|
||||
{{range $vidIndex, $video := .Videos}}
|
||||
{{if not (eq $vidIndex 0)}}
|
||||
<hr class="mt-5" />
|
||||
{{end}}
|
||||
<div class="d-flex flex-column flex-lg-row justify-content-center gap-5 mt-5">
|
||||
<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 class="downloads flex-lg-grow-1">
|
||||
{{range $index, $format := $video.Formats}}
|
||||
<div style="font-size: smaller">{{$format.Format}}</div>
|
||||
<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
|
||||
href="{{$format.Url}}"
|
||||
>
|
||||
<a class="btn btn-primary flex-grow-1" download="{{$root.Meta.ID}}-{{$format.Resolution}}.{{$format.Ext}}" P
|
||||
href="{{$format.Url}}">
|
||||
Download (direct)
|
||||
</a>
|
||||
<a
|
||||
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}}"
|
||||
>
|
||||
<a 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)
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -5,48 +5,21 @@
|
|||
with more features and fixes.
|
||||
<br />
|
||||
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>
|
||||
|
||||
<form
|
||||
hx-get="{{.BasePath}}/download"
|
||||
hx-trigger="submit"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML"
|
||||
>
|
||||
<form hx-get="{{.BasePath}}/download" hx-trigger="submit" hx-target="#main-content" hx-swap="innerHTML">
|
||||
<div class="mb-3">
|
||||
<label for="url" class="form-label visually-hidden">Url</label>
|
||||
<div class="input-group">
|
||||
<input
|
||||
type="url"
|
||||
name="url"
|
||||
id="url"
|
||||
class="form-control"
|
||||
required
|
||||
placeholder="Enter url here then click download"
|
||||
/>
|
||||
<input type="url" name="url" id="url" class="form-control" required
|
||||
placeholder="Enter url here then click download" />
|
||||
{{if .IsSecure}}
|
||||
<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"
|
||||
/>
|
||||
<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>
|
||||
</button>
|
||||
{{end}}
|
||||
|
@ -55,10 +28,7 @@
|
|||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Download
|
||||
<div
|
||||
class="spinner-border spinner-border-sm htmx-indicator ms-1"
|
||||
role="status"
|
||||
>
|
||||
<div class="spinner-border spinner-border-sm htmx-indicator ms-1" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</button>
|
||||
|
@ -70,19 +40,10 @@
|
|||
<span>{{.Error.Message}}</span>
|
||||
|
||||
{{if .Error.RetryUrl}}
|
||||
<button
|
||||
class="btn btn-link btn-sm pt-0 lh-base text-decoration-none"
|
||||
hx-get="/download"
|
||||
hx-trigger="click"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML"
|
||||
hx-vals='{"url": "{{.Error.RetryUrl}}"}'
|
||||
>
|
||||
<button class="btn btn-link btn-sm pt-0 lh-base text-decoration-none" 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>
|
||||
<div
|
||||
class="spinner-border spinner-border-sm htmx-indicator ms-1"
|
||||
role="status"
|
||||
>
|
||||
<div class="spinner-border spinner-border-sm htmx-indicator ms-1" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</button>
|
||||
|
|
|
@ -1,43 +1,23 @@
|
|||
<!doctype html>
|
||||
<html lang="en" class="h-100">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>YTDL Web</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css"
|
||||
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>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastr@2.1.4/build/toastr.min.css"
|
||||
integrity="sha256-R91pD48xW+oHbpJYGn5xR0Q7tMhH4xOrWn1QqMRINtA=" 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"
|
||||
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>
|
||||
#toast-container>div {
|
||||
-moz-box-shadow: none !important;
|
||||
|
@ -91,4 +71,5 @@
|
|||
htmx.onLoad(setupPaste);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -5,9 +5,7 @@
|
|||
<div class="d-flex gap-1 align-items-baseline">
|
||||
Version:
|
||||
<span class="text-muted">{{.Version}}</span>
|
||||
<span class="text-muted text-nowrap" style="font-size: smaller"
|
||||
>(Build: {{.Build}})</span
|
||||
>
|
||||
<span class="text-muted text-nowrap" style="font-size: smaller">(Build: {{.Build}})</span>
|
||||
</div>
|
||||
<div class="d-flex gap-1 align-items-baseline text-nowrap">
|
||||
yt-dlp version: <span class="text-muted">{{.BinaryVersion}}</span>
|
||||
|
|
1
go.mod
1
go.mod
|
@ -7,7 +7,6 @@ require (
|
|||
github.com/dgraph-io/badger/v2 v2.2007.4
|
||||
github.com/go-chi/chi/v5 v5.0.10
|
||||
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/viper v1.10.0
|
||||
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
|
||||
|
|
2
go.sum
2
go.sum
|
@ -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/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/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 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
|
|
Loading…
Reference in New Issue