89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package media_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.netflux.io/rob/clipper/media"
|
|
youtubev2 "github.com/kkdai/youtube/v2"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSortAudio(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,
|
|
AudioSampleRate: "48000",
|
|
},
|
|
{
|
|
MimeType: `audio/webm; codecs="opus"`,
|
|
ContentLength: 123245,
|
|
AudioChannels: 2,
|
|
AudioSampleRate: "48000",
|
|
},
|
|
}
|
|
|
|
sortedFormats := media.SortYoutubeAudio(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])
|
|
}
|
|
|
|
func TestSortVideo(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,
|
|
},
|
|
}
|
|
|
|
sortedFormats := media.SortYoutubeVideo(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])
|
|
}
|