Skip to content

Commit

Permalink
Merge pull request #485 from wader/temp-skip-youtube
Browse files Browse the repository at this point in the history
Make most tests run again
  • Loading branch information
wader authored Oct 7, 2024
2 parents f3a3104 + 4ef23a8 commit 86585b6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
7 changes: 2 additions & 5 deletions cmd/ydls/ydls_get_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ TEMPDIR=`mktemp -d`
trap "rm -rf $TEMPDIR" EXIT
cd "$TEMPDIR"

ydls -noprogress -config "$CONFIG" "https://www.youtube.com/watch?v=C0DPdy98e4c" mp3
ffprobe -show_format -hide_banner -i "TEST VIDEO.mp3" 2>&1 | grep format_name=mp3

ydls -noprogress -config "$CONFIG" "https://www.youtube.com/watch?v=C0DPdy98e4c"
ffprobe -show_format -hide_banner -i "TEST VIDEO.mp4" 2>&1 | grep format_name=mov
ydls -noprogress -config "$CONFIG" "https://vimeo.com/454525548" mp3
ffprobe -show_format -hide_banner -i "Sample Video - 3 minutemp4.mp4.mp3" 2>&1 | grep format_name=mp3
7 changes: 2 additions & 5 deletions cmd/ydls/ydls_server_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ ydls -server -listen :1234 -config "$CONFIG" &
# wait until ready
curl --retry-connrefused --retry 5 http://0:1234/

curl -sOJ "http://0:1234/mp3+1s/https://www.youtube.com/watch?v=C0DPdy98e4c"
ffprobe -show_format -hide_banner -i "TEST VIDEO.mp3" 2>&1 | grep format_name=mp3

curl -sOJ "http://0:1234/https://www.youtube.com/watch?v=C0DPdy98e4c"
ffprobe -show_format -hide_banner -i "TEST VIDEO.mp4" 2>&1 | grep format_name=mov
curl -sOJ "http://0:1234/mp3+1s/https://vimeo.com/454525548"
ffprobe -show_format -hide_banner -i "Sample Video - 3 minutemp4.mp4.mp3" 2>&1 | grep format_name=mp3

kill %1
5 changes: 2 additions & 3 deletions internal/ffmpeg/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -157,7 +156,7 @@ func TestURLInput(t *testing.T) {
defer leakChecks(t)()

dummy1 := mustDummy(t, "matroska", "mp3", "h264")
tempFile1, tempFile1Err := ioutil.TempFile("", "TestURLInput")
tempFile1, tempFile1Err := os.CreateTemp("", "TestURLInput")
if tempFile1Err != nil {
t.Fatal(tempFile1)
}
Expand All @@ -168,7 +167,7 @@ func TestURLInput(t *testing.T) {
tempFile1.Close()

dummy2 := mustDummy(t, "matroska", "mp3", "h264")
tempFile2, tempFile2Err := ioutil.TempFile("", "TestURLInput")
tempFile2, tempFile2Err := os.CreateTemp("", "TestURLInput")
if tempFile2Err != nil {
t.Fatal(tempFile2Err)
}
Expand Down
14 changes: 9 additions & 5 deletions internal/ydls/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ func TestFormats(t *testing.T) {
expectedFilename string
}{
{soundcloudTestAudioURL, true, false, "Avalon Emerson Live at Printworks London"},
{youtubeTestVideoURL, false, true, "TEST VIDEO"},
{testVideoURL, false, true, "Sample Video - 3 minutemp4.mp4"},
} {
for formatName, format := range ydls.Config.Formats {
if firstFormat, _ := format.Formats.First(); firstFormat == "rss" {
continue
}

t.Run(formatName+"-"+c.MediaRawURL, func(t *testing.T) {
if formatName == "mkv" {
t.Skip("problem with piped mkv and aac at the moment, ffmpeg limitation?")
}

defer leakChecks(t)()

requireVideo := false
Expand Down Expand Up @@ -238,14 +242,14 @@ func TestRawFormat(t *testing.T) {
dr, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: youtubeTestVideoURL,
MediaRawURL: testVideoURL,
},
Retries: ydlsLRetries,
},
)
if err != nil {
cancelFn()
t.Errorf("%s: %s: download failed: %s", youtubeTestVideoURL, "raw", err)
t.Errorf("%s: %s: download failed: %s", testVideoURL, "raw", err)
return
}

Expand All @@ -254,11 +258,11 @@ func TestRawFormat(t *testing.T) {
dr.Wait()
cancelFn()
if err != nil {
t.Errorf("%s: %s: probe failed: %s", youtubeTestVideoURL, "raw", err)
t.Errorf("%s: %s: probe failed: %s", testVideoURL, "raw", err)
return
}

t.Logf("%s: %s: OK (probed %s)\n", youtubeTestVideoURL, "raw", pi)
t.Logf("%s: %s: OK (probed %s)\n", testVideoURL, "raw", pi)
}

func TestFindByFormatCodecs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/ydls/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (yh *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Retries: yh.YDLS.Config.DownloadRetries,
}

formatName := "best"
formatName := "" // default yt-dlp format
if requestOptions.Format != nil {
formatName = requestOptions.Format.Name
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ydls/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestYDLSHandlerDownload(t *testing.T) {

h := ydlsHandlerFromEnv(t)
rr := httptest.NewRecorder()
testMediaURL := "https://www.youtube.com/watch?v=C0DPdy98e4c"
testMediaURL := "https://vimeo.com/454525548"
req := httptest.NewRequest("GET", "http://hostname/mp3/"+testMediaURL, nil)
h.ServeHTTP(rr, req)
resp := rr.Result()
Expand Down
5 changes: 3 additions & 2 deletions internal/ydls/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"github.com/wader/osleaktest"
)

var youtubeTestVideoURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
var youtubeLongTestVideoURL = "https://www.youtube.com/watch?v=aqz-KE-bpKQ"
var testVideoURL = "https://vimeo.com/454525548"
var longTestVideoURL = "https://vimeo.com/454525548"
var soundcloudTestAudioURL = "https://soundcloud.com/avalonemerson/avalon-emerson-live-at-printworks-london-march-2017"
var soundcloudTestPlaylistURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"

var testExternal = os.Getenv("TEST_EXTERNAL") != ""
var testYoutube = os.Getenv("TEST_YOUTUBE") != ""

var ydlsLRetries = 3

Expand Down
2 changes: 1 addition & 1 deletion internal/ydls/ydls.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func (ydls *YDLS) downloadRSS(
}

func (ydls *YDLS) downloadRaw(ctx context.Context, debugLog Printer, ydlResult goutubedl.Result) (DownloadResult, error) {
dprc, err := downloadAndProbeFormat(ctx, ydlResult, "best", debugLog)
dprc, err := downloadAndProbeFormat(ctx, ydlResult, "", debugLog)
if err != nil {
return DownloadResult{}, err
}
Expand Down
48 changes: 25 additions & 23 deletions internal/ydls/ydls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestForceCodec(t *testing.T) {
dr, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: youtubeTestVideoURL,
MediaRawURL: testVideoURL,
Format: &mkvFormat,
Codecs: forceCodecs,
},
Expand All @@ -75,7 +75,7 @@ func TestForceCodec(t *testing.T) {
)
if err != nil {
cancelFn()
t.Errorf("%s: download failed: %s", youtubeTestVideoURL, err)
t.Errorf("%s: download failed: %s", testVideoURL, err)
return
}

Expand All @@ -84,18 +84,18 @@ func TestForceCodec(t *testing.T) {
dr.Wait()
cancelFn()
if err != nil {
t.Errorf("%s: probe failed: %s", youtubeTestVideoURL, err)
t.Errorf("%s: probe failed: %s", testVideoURL, err)
return
}

if pi.FormatName() != "matroska" {
t.Errorf("%s: force codec failed: found %s", youtubeTestVideoURL, pi)
t.Errorf("%s: force codec failed: found %s", testVideoURL, pi)
return
}

for i := 0; i < len(forceCodecs); i++ {
if pi.Streams[i].CodecName != forceCodecs[i] {
t.Errorf("%s: force codec failed: %s != %s", youtubeTestVideoURL, pi.Streams[i].CodecName, forceCodecs[i])
t.Errorf("%s: force codec failed: %s != %s", testVideoURL, pi.Streams[i].CodecName, forceCodecs[i])
return
}
}
Expand All @@ -110,10 +110,10 @@ func TestTimeRangeOption(t *testing.T) {
defer leakChecks(t)()

ydls := ydlsFromEnv(t)
const formatName = "mkv"
mkvFormat, _ := ydls.Config.Formats.FindByName(formatName)
const formatName = "webm"
webmFormat, _ := ydls.Config.Formats.FindByName(formatName)

timeRange, timeRangeErr := timerange.NewTimeRangeFromString("10s-15s")
timeRange, timeRangeErr := timerange.NewTimeRangeFromString("1-6s")
if timeRangeErr != nil {
t.Fatalf("failed to parse time range")
}
Expand All @@ -123,29 +123,29 @@ func TestTimeRangeOption(t *testing.T) {
dr, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: youtubeTestVideoURL,
Format: &mkvFormat,
MediaRawURL: testVideoURL,
Format: &webmFormat,
TimeRange: timeRange,
},
Retries: ydlsLRetries,
},
)
if err != nil {
cancelFn()
t.Fatalf("%s: download failed: %s", youtubeTestVideoURL, err)
t.Fatalf("%s: download failed: %s", testVideoURL, err)
}

pi, err := ffmpeg.Probe(ctx, ffmpeg.Reader{Reader: io.LimitReader(dr.Media, 10*1024*1024)}, nil, nil)
dr.Media.Close()
dr.Wait()
cancelFn()
if err != nil {
t.Errorf("%s: probe failed: %s", youtubeTestVideoURL, err)
t.Errorf("%s: probe failed: %s", testVideoURL, err)
return
}

if pi.Duration() != timeRange.Duration() {
t.Errorf("%s: probed duration not %v, got %v", youtubeTestVideoURL, timeRange.Duration(), pi.Duration())
t.Errorf("%s: probed duration not %v, got %v", testVideoURL, timeRange.Duration(), pi.Duration())
return
}
}
Expand All @@ -160,15 +160,15 @@ func TestMissingMediaStream(t *testing.T) {
ydls := ydlsFromEnv(t)
// mxf requires video, soundcloud is audio only
const formatName = "mxf"
mkvFormat, _ := ydls.Config.Formats.FindByName(formatName)
mxfFormat, _ := ydls.Config.Formats.FindByName(formatName)

ctx, cancelFn := context.WithCancel(context.Background())

_, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: soundcloudTestAudioURL,
Format: &mkvFormat,
Format: &mxfFormat,
},
Retries: ydlsLRetries,
},
Expand Down Expand Up @@ -218,8 +218,8 @@ func TestContextCloseProbe(t *testing.T) {
defer leakChecks(t)()

ydls := ydlsFromEnv(t)
const formatName = "mkv"
mkvFormat, _ := ydls.Config.Formats.FindByName(formatName)
const formatName = "mp4"
mp4Format, _ := ydls.Config.Formats.FindByName(formatName)

ctx, cancelFn := context.WithCancel(context.Background())

Expand All @@ -233,8 +233,8 @@ func TestContextCloseProbe(t *testing.T) {
_, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: youtubeLongTestVideoURL,
Format: &mkvFormat,
MediaRawURL: longTestVideoURL,
Format: &mp4Format,
},
Retries: ydlsLRetries,
},
Expand All @@ -254,16 +254,16 @@ func TestContextCloseDownload(t *testing.T) {
defer leakChecks(t)()

ydls := ydlsFromEnv(t)
const formatName = "mkv"
mkvFormat, _ := ydls.Config.Formats.FindByName(formatName)
const formatName = "mp4"
mp4Format, _ := ydls.Config.Formats.FindByName(formatName)

ctx, cancelFn := context.WithCancel(context.Background())

dr, err := ydls.Download(ctx,
DownloadOptions{
RequestOptions: RequestOptions{
MediaRawURL: youtubeLongTestVideoURL,
Format: &mkvFormat,
MediaRawURL: longTestVideoURL,
Format: &mp4Format,
},
Retries: ydlsLRetries,
},
Expand Down Expand Up @@ -405,6 +405,8 @@ func TestSubtitles(t *testing.T) {
t.Skip("TEST_EXTERNAL")
}

t.Skip("no good subtitles video found yet")

subtitlesTestVideoURL := "https://www.youtube.com/watch?v=QRS8MkLhQmM"
ydls := ydlsFromEnv(t)

Expand Down

0 comments on commit 86585b6

Please sign in to comment.