2023-08-14 18:14:08 -04:00
|
|
|
package models
|
2023-04-15 12:38:33 -04:00
|
|
|
|
|
|
|
import (
|
2023-08-14 18:16:42 -04:00
|
|
|
"go.fifitido.net/ytdl-web/pkg/ytdl/metadata"
|
2023-04-15 12:38:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Video struct {
|
2024-02-17 11:19:10 -05:00
|
|
|
Meta *metadata.Metadata
|
|
|
|
Formats []metadata.Format
|
|
|
|
OtherFormats []metadata.Format
|
2023-04-15 12:38:33 -04:00
|
|
|
}
|
|
|
|
|
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() {
|
2024-02-17 11:19:10 -05:00
|
|
|
videos := make([]Video, 0, len(meta.Entries))
|
|
|
|
|
|
|
|
for _, entry := range meta.Entries {
|
|
|
|
videos = append(videos, GetVideosFromMetadata(&entry)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return videos
|
2023-04-15 12:38:33 -04:00
|
|
|
}
|
|
|
|
|
2024-02-17 11:19:10 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 12:38:33 -04:00
|
|
|
|
|
|
|
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{
|
|
|
|
{
|
2024-02-17 11:19:10 -05:00
|
|
|
Meta: meta,
|
|
|
|
Formats: formats,
|
|
|
|
OtherFormats: otherFormats,
|
2023-04-15 12:38:33 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|