Compare commits
17 Commits
httpchunks
...
bump-youtu
Author | SHA1 | Date | |
---|---|---|---|
474ed43067 | |||
30a347dec9 | |||
3389e34b7f | |||
6e39b2fb4b | |||
37811576e7 | |||
87011aa92b | |||
233195dd0d | |||
6e31f063cf | |||
41933f0a2b | |||
d0e3a70ce5 | |||
012408bb52 | |||
c4f0e4cc71 | |||
0c48cc0631 | |||
b5714b7c0b | |||
abc93ced75 | |||
e085ca9cef | |||
d159914696 |
11
Dockerfile
11
Dockerfile
@ -1,17 +1,22 @@
|
|||||||
# bump: golang /GOLANG_VERSION=([\d.]+)/ docker:golang|^1
|
# bump: golang /GOLANG_VERSION=([\d.]+)/ docker:golang|^1
|
||||||
# bump: golang link "Release notes" https://golang.org/doc/devel/release.html
|
# bump: golang link "Release notes" https://golang.org/doc/devel/release.html
|
||||||
ARG GOLANG_VERSION=1.16.5
|
ARG GOLANG_VERSION=1.17.5
|
||||||
# bump: youtube-dl /YDL_VERSION=([\d.]+)/ https://github.com/ytdl-org/youtube-dl.git|/^\d/|sort
|
# bump: youtube-dl /YDL_VERSION=([\d.]+)/ https://github.com/ytdl-org/youtube-dl.git|/^\d/|sort
|
||||||
# bump: youtube-dl link "Release notes" https://github.com/ytdl-org/youtube-dl/releases/tag/$LATEST
|
# bump: youtube-dl link "Release notes" https://github.com/ytdl-org/youtube-dl/releases/tag/$LATEST
|
||||||
ARG YDL_VERSION=2021.06.06
|
ARG YDL_VERSION=2021.12.17
|
||||||
|
|
||||||
FROM golang:$GOLANG_VERSION
|
FROM golang:$GOLANG_VERSION AS base
|
||||||
ARG YDL_VERSION
|
ARG YDL_VERSION
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
|
apt-get update -q && \
|
||||||
|
apt-get install -y -q python-is-python3 && \
|
||||||
curl -L -o /usr/local/bin/youtube-dl https://yt-dl.org/downloads/$YDL_VERSION/youtube-dl && \
|
curl -L -o /usr/local/bin/youtube-dl https://yt-dl.org/downloads/$YDL_VERSION/youtube-dl && \
|
||||||
chmod a+x /usr/local/bin/youtube-dl
|
chmod a+x /usr/local/bin/youtube-dl
|
||||||
|
|
||||||
|
FROM base AS dev
|
||||||
|
|
||||||
|
FROM base
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.* *.go ./
|
COPY go.* *.go ./
|
||||||
COPY cmd cmd
|
COPY cmd cmd
|
||||||
|
10
goutubedl.go
10
goutubedl.go
@ -208,7 +208,6 @@ type Options struct {
|
|||||||
DownloadSubtitles bool
|
DownloadSubtitles bool
|
||||||
DebugLog Printer
|
DebugLog Printer
|
||||||
StderrFn func(cmd *exec.Cmd) io.Writer // if not nil, function to get Writer for stderr
|
StderrFn func(cmd *exec.Cmd) io.Writer // if not nil, function to get Writer for stderr
|
||||||
HTTPChunkSize uint // --http-chunk-size
|
|
||||||
HTTPClient *http.Client // Client for download thumbnail and subtitles (nil use http.DefaultClient)
|
HTTPClient *http.Client // Client for download thumbnail and subtitles (nil use http.DefaultClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,9 +454,6 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
|||||||
if !result.Info.Direct {
|
if !result.Info.Direct {
|
||||||
cmd.Args = append(cmd.Args, "-f", filter)
|
cmd.Args = append(cmd.Args, "-f", filter)
|
||||||
}
|
}
|
||||||
if result.Options.HTTPChunkSize != 0 {
|
|
||||||
cmd.Args = append(cmd.Args, "--http-chunk-size", fmt.Sprintf("%d", result.Options.HTTPChunkSize))
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Dir = tempPath
|
cmd.Dir = tempPath
|
||||||
var w io.WriteCloser
|
var w io.WriteCloser
|
||||||
@ -476,16 +472,14 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var waitErr error
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
waitErr = cmd.Wait()
|
cmd.Wait()
|
||||||
w.Close()
|
w.Close()
|
||||||
os.RemoveAll(tempPath)
|
os.RemoveAll(tempPath)
|
||||||
close(dr.waitCh)
|
close(dr.waitCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return dr, waitErr
|
return dr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dr *DownloadResult) Read(p []byte) (n int, err error) {
|
func (dr *DownloadResult) Read(p []byte) (n int, err error) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package goutubedl_test
|
package goutubedl
|
||||||
|
|
||||||
// TODO: currently the tests only run on linux as they use osleaktest which only
|
// TODO: currently the tests only run on linux as they use osleaktest which only
|
||||||
// has linux support
|
// has linux support
|
||||||
@ -14,7 +14,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fortytw2/leaktest"
|
"github.com/fortytw2/leaktest"
|
||||||
"github.com/wader/goutubedl"
|
|
||||||
"github.com/wader/osleaktest"
|
"github.com/wader/osleaktest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,10 +33,10 @@ func leakChecks(t *testing.T) func() {
|
|||||||
|
|
||||||
func TestBinaryNotPath(t *testing.T) {
|
func TestBinaryNotPath(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
defer func(orig string) { goutubedl.Path = orig }(goutubedl.Path)
|
defer func(orig string) { Path = orig }(Path)
|
||||||
goutubedl.Path = "/non-existing"
|
Path = "/non-existing"
|
||||||
|
|
||||||
_, versionErr := goutubedl.Version(context.Background())
|
_, versionErr := Version(context.Background())
|
||||||
if versionErr == nil || !strings.Contains(versionErr.Error(), "no such file or directory") {
|
if versionErr == nil || !strings.Contains(versionErr.Error(), "no such file or directory") {
|
||||||
t.Fatalf("err should be nil 'no such file or directory': %v", versionErr)
|
t.Fatalf("err should be nil 'no such file or directory': %v", versionErr)
|
||||||
}
|
}
|
||||||
@ -47,7 +46,7 @@ func TestVersion(t *testing.T) {
|
|||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
versionRe := regexp.MustCompile(`^\d{4}\.\d{2}.\d{2}.*$`)
|
versionRe := regexp.MustCompile(`^\d{4}\.\d{2}.\d{2}.*$`)
|
||||||
version, versionErr := goutubedl.Version(context.Background())
|
version, versionErr := Version(context.Background())
|
||||||
|
|
||||||
if versionErr != nil {
|
if versionErr != nil {
|
||||||
t.Fatalf("err: %s", versionErr)
|
t.Fatalf("err: %s", versionErr)
|
||||||
@ -58,21 +57,15 @@ func TestVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDownload(t *testing.T, rawURL string, optionsFn func(options *goutubedl.Options)) {
|
func TestDownload(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
stderrBuf := &bytes.Buffer{}
|
stderrBuf := &bytes.Buffer{}
|
||||||
|
r, err := New(context.Background(), testVideoRawURL, Options{
|
||||||
options := goutubedl.Options{
|
|
||||||
StderrFn: func(cmd *exec.Cmd) io.Writer {
|
StderrFn: func(cmd *exec.Cmd) io.Writer {
|
||||||
return stderrBuf
|
return stderrBuf
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
if optionsFn != nil {
|
|
||||||
optionsFn(&options)
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := goutubedl.New(context.Background(), rawURL, options)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -100,18 +93,6 @@ func testDownload(t *testing.T, rawURL string, optionsFn func(options *goutubedl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDownload(t *testing.T) {
|
|
||||||
defer leakChecks(t)()
|
|
||||||
testDownload(t, testVideoRawURL, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHTTPChunkSize(t *testing.T) {
|
|
||||||
defer leakChecks(t)()
|
|
||||||
testDownload(t, testVideoRawURL, func(options *goutubedl.Options) {
|
|
||||||
options.HTTPChunkSize = 1000000
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseInfo(t *testing.T) {
|
func TestParseInfo(t *testing.T) {
|
||||||
for _, c := range []struct {
|
for _, c := range []struct {
|
||||||
url string
|
url string
|
||||||
@ -125,7 +106,7 @@ func TestParseInfo(t *testing.T) {
|
|||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
ctx, cancelFn := context.WithCancel(context.Background())
|
ctx, cancelFn := context.WithCancel(context.Background())
|
||||||
ydlResult, err := goutubedl.New(ctx, c.url, goutubedl.Options{
|
ydlResult, err := New(ctx, c.url, Options{
|
||||||
DownloadThumbnail: true,
|
DownloadThumbnail: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -175,8 +156,8 @@ func TestParseInfo(t *testing.T) {
|
|||||||
func TestPlaylist(t *testing.T) {
|
func TestPlaylist(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
ydlResult, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||||
Type: goutubedl.TypePlaylist,
|
Type: TypePlaylist,
|
||||||
DownloadThumbnail: false,
|
DownloadThumbnail: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -203,7 +184,7 @@ func TestPlaylist(t *testing.T) {
|
|||||||
func TestTestUnsupportedURL(t *testing.T) {
|
func TestTestUnsupportedURL(t *testing.T) {
|
||||||
defer leaktest.Check(t)()
|
defer leaktest.Check(t)()
|
||||||
|
|
||||||
_, ydlResultErr := goutubedl.New(context.Background(), "https://www.google.com", goutubedl.Options{})
|
_, ydlResultErr := New(context.Background(), "https://www.google.com", Options{})
|
||||||
if ydlResultErr == nil {
|
if ydlResultErr == nil {
|
||||||
t.Errorf("expected unsupported url")
|
t.Errorf("expected unsupported url")
|
||||||
}
|
}
|
||||||
@ -218,8 +199,8 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
|||||||
defer leaktest.Check(t)()
|
defer leaktest.Check(t)()
|
||||||
|
|
||||||
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
||||||
ydlResult, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
ydlResult, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||||
Type: goutubedl.TypePlaylist,
|
Type: TypePlaylist,
|
||||||
DownloadThumbnail: false,
|
DownloadThumbnail: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -237,10 +218,10 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
|||||||
func TestSubtitles(t *testing.T) {
|
func TestSubtitles(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(
|
ydlResult, ydlResultErr := New(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
subtitlesTestVideoRawURL,
|
subtitlesTestVideoRawURL,
|
||||||
goutubedl.Options{
|
Options{
|
||||||
DownloadSubtitles: true,
|
DownloadSubtitles: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -269,11 +250,11 @@ func TestSubtitles(t *testing.T) {
|
|||||||
func TestErrorNotAPlaylist(t *testing.T) {
|
func TestErrorNotAPlaylist(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
_, ydlResultErr := goutubedl.New(context.Background(), testVideoRawURL, goutubedl.Options{
|
_, ydlResultErr := New(context.Background(), testVideoRawURL, Options{
|
||||||
Type: goutubedl.TypePlaylist,
|
Type: TypePlaylist,
|
||||||
DownloadThumbnail: false,
|
DownloadThumbnail: false,
|
||||||
})
|
})
|
||||||
if ydlResultErr != goutubedl.ErrNotAPlaylist {
|
if ydlResultErr != ErrNotAPlaylist {
|
||||||
t.Errorf("expected is playlist error, got %s", ydlResultErr)
|
t.Errorf("expected is playlist error, got %s", ydlResultErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,11 +262,11 @@ func TestErrorNotAPlaylist(t *testing.T) {
|
|||||||
func TestErrorNotASingleEntry(t *testing.T) {
|
func TestErrorNotASingleEntry(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
_, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
_, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||||
Type: goutubedl.TypeSingle,
|
Type: TypeSingle,
|
||||||
DownloadThumbnail: false,
|
DownloadThumbnail: false,
|
||||||
})
|
})
|
||||||
if ydlResultErr != goutubedl.ErrNotASingleEntry {
|
if ydlResultErr != ErrNotASingleEntry {
|
||||||
t.Errorf("expected is single entry error, got %s", ydlResultErr)
|
t.Errorf("expected is single entry error, got %s", ydlResultErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user