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