35 lines
685 B
Go
35 lines
685 B
Go
package web
|
|
|
|
import (
|
|
"github.com/samber/lo"
|
|
"go.fifitido.net/ytdl-web/ytdl"
|
|
)
|
|
|
|
type Video struct {
|
|
Meta ytdl.Metadata
|
|
Formats []ytdl.Format
|
|
}
|
|
|
|
func GetVideos(meta ytdl.Metadata) []Video {
|
|
if meta.Type == "playlist" {
|
|
return lo.Map(meta.Entries, func(video ytdl.Metadata, _ int) Video {
|
|
return GetVideos(video)[0]
|
|
})
|
|
}
|
|
|
|
formats := lo.Filter(meta.Formats, func(item ytdl.Format, _ int) bool {
|
|
return item.ACodec != "none" && item.VCodec != "none" && item.Protocol != "m3u8_native"
|
|
})
|
|
|
|
for i, j := 0, len(formats)-1; i < j; i, j = i+1, j-1 {
|
|
formats[i], formats[j] = formats[j], formats[i]
|
|
}
|
|
|
|
return []Video{
|
|
{
|
|
Meta: meta,
|
|
Formats: formats,
|
|
},
|
|
}
|
|
}
|