ytdl-web/app/models/video.go

47 lines
982 B
Go
Raw Permalink Normal View History

2023-08-14 18:14:08 -04:00
package models
import (
"go.fifitido.net/ytdl-web/pkg/ytdl/metadata"
)
type Video struct {
Meta *metadata.Metadata
Formats []metadata.Format
OtherFormats []metadata.Format
}
2023-08-14 18:14:08 -04:00
func GetVideosFromMetadata(meta *metadata.Metadata) []Video {
2023-05-23 19:35:52 -04:00
if meta.IsPlaylist() {
videos := make([]Video, 0, len(meta.Entries))
for _, entry := range meta.Entries {
videos = append(videos, GetVideosFromMetadata(&entry)...)
}
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]
}
return []Video{
{
Meta: meta,
Formats: formats,
OtherFormats: otherFormats,
},
}
}