47 lines
982 B
Go
47 lines
982 B
Go
package models
|
|
|
|
import (
|
|
"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() {
|
|
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,
|
|
},
|
|
}
|
|
}
|