clipper/backend/media/youtube_test.go

89 lines
2.0 KiB
Go
Raw Normal View History

package media_test
import (
"testing"
"git.netflux.io/rob/clipper/media"
youtubev2 "github.com/kkdai/youtube/v2"
"github.com/stretchr/testify/assert"
)
2021-10-28 01:23:45 +00:00
func TestFilterAudio(t *testing.T) {
formats := []youtubev2.Format{
{
MimeType: `audio/webm; codecs="opus"`,
ContentLength: 38573,
AudioChannels: 1,
AudioSampleRate: "16000",
},
{
MimeType: `audio/webm; codecs="opus"`,
ContentLength: 39458,
AudioChannels: 2,
AudioSampleRate: "16000",
},
{
MimeType: `audio/mp4; codecs="mp4a.40.2"`,
ContentLength: 118394,
AudioChannels: 1,
AudioSampleRate: "48000",
},
{
MimeType: `audio/webm; codecs="opus"`,
ContentLength: 127393,
AudioChannels: 2,
2021-09-24 05:37:27 +00:00
AudioSampleRate: "48000",
},
{
MimeType: `audio/webm; codecs="opus"`,
ContentLength: 123245,
AudioChannels: 2,
2021-09-24 05:37:27 +00:00
AudioSampleRate: "48000",
},
}
2021-10-28 01:23:45 +00:00
sortedFormats := media.FilterYoutubeAudio(formats)
assert.Equal(t, formats[1], sortedFormats[0])
assert.Equal(t, formats[4], sortedFormats[1])
assert.Equal(t, formats[3], sortedFormats[2])
assert.Equal(t, formats[0], sortedFormats[3])
assert.Equal(t, formats[2], sortedFormats[4])
}
2021-10-28 01:23:45 +00:00
func TestFilterVideo(t *testing.T) {
formats := []youtubev2.Format{
{
MimeType: `audio/webm; codecs="opus"`,
QualityLabel: "120p",
FPS: 30,
ContentLength: 39402,
},
{
MimeType: `video/mp4; codecs="avc1.42001E, mp4a.40.2"`,
QualityLabel: "240p",
FPS: 30,
ContentLength: 40353,
},
{
MimeType: `video/mp4; codecs="avc1.42001E, mp4a.40.2"`,
QualityLabel: "720p",
FPS: 30,
ContentLength: 393103,
},
{
MimeType: `video/mp4; codecs="avc1.42001E, mp4a.40.2"`,
QualityLabel: "360p",
FPS: 0,
ContentLength: 20403,
},
}
2021-10-28 01:23:45 +00:00
sortedFormats := media.FilterYoutubeVideo(formats)
assert.Len(t, sortedFormats, 3)
assert.Equal(t, formats[1], sortedFormats[0])
assert.Equal(t, formats[2], sortedFormats[1])
assert.Equal(t, formats[0], sortedFormats[2])
}