clipper/backend/media/youtube_test.go

117 lines
2.5 KiB
Go
Raw Permalink 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])
}
2021-11-21 19:43:40 +00:00
func TestSortThumbnails(t *testing.T) {
thumbnails := []youtubev2.Thumbnail{
{
Width: 250,
Height: 100,
},
{
Width: 1920,
Height: 1080,
},
{
Width: 50,
Height: 33,
},
{
Width: 75,
Height: 51,
},
}
media.SortYoutubeThumbnails(thumbnails)
assert.Equal(t, uint(250), thumbnails[0].Width)
assert.Equal(t, uint(1920), thumbnails[1].Width)
assert.Equal(t, uint(50), thumbnails[2].Width)
assert.Equal(t, uint(75), thumbnails[3].Width)
}