package views import ( "fmt" "go.fifitido.net/ytdl-web/pkg/ytdl/metadata" ) type DownloadsViewModel struct { Url string Meta *metadata.Metadata } templ videoFormatView(vm *DownloadsViewModel, vidIndex int, format metadata.Format, label string) { {{ filename := fmt.Sprintf("%s-%s.%s", vm.Meta.ID, format.Resolution, format.Ext) }}
{ label }
// Workaround for browsers that use the content of the link as the filename { filename } Download (proxied)
} templ videoView(vm *DownloadsViewModel, index int, video *VideoViewModel) { if index != 0 {
}
{{ thumbnail := video.Meta.Thumbnail thumbnailAlt := video.Meta.ID if video.Meta.Title != nil { thumbnailAlt = *video.Meta.Title } }} if thumbnail != nil {
{
}
for _, format := range video.Formats { @videoFormatView(vm, index, format, format.Format) }
if len(video.OtherFormats) > 0 { {{ collapseId := fmt.Sprintf("collapse-%s-%d", vm.Meta.ID, index) }}
for _, format := range video.OtherFormats { {{ label := fmt.Sprintf("ext: %s, resolution: %s, filesize: %d, note: %s", format.Ext, format.Resolution, format.Filesize, format.FormatNote) }} @videoFormatView(vm, index, format, label) }
} } css downloads() { display: grid; grid-template-columns: minmax(auto, max-content) auto; gap: 1.5rem; align-items: center; } css fullWidth() { grid-column: span 2; } templ Downloads(vm *DownloadsViewModel) { {{ videos := GetVideosFromMetadata(vm.Meta) }} @Layout() {

Download Video

{ *vm.Meta.Title }

{ vm.Url }

Download Another Video
for index, video := range videos { @videoView(vm, index, video) } } }