2023-08-12 23:27:11 -04:00
|
|
|
package app
|
2023-04-15 12:38:33 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/samber/lo"
|
2023-05-23 18:44:05 -04:00
|
|
|
"go.fifitido.net/ytdl-web/ytdl/metadata"
|
2023-04-15 12:38:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Video struct {
|
2023-05-23 18:44:05 -04:00
|
|
|
Meta *metadata.Metadata
|
|
|
|
Formats []metadata.Format
|
2023-04-15 12:38:33 -04:00
|
|
|
}
|
|
|
|
|
2023-05-23 18:44:05 -04:00
|
|
|
func GetVideos(meta *metadata.Metadata) []Video {
|
2023-05-23 19:35:52 -04:00
|
|
|
if meta.IsPlaylist() {
|
2023-05-23 18:44:05 -04:00
|
|
|
return lo.Map(meta.Entries, func(video metadata.Metadata, _ int) Video {
|
|
|
|
return GetVideos(&video)[0]
|
2023-04-15 12:38:33 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:44:05 -04:00
|
|
|
formats := lo.Filter(meta.Formats, func(item metadata.Format, _ int) bool {
|
2023-04-15 12:38:33 -04:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|