17 Commits

Author SHA1 Message Date
474ed43067 Update youtube-dl from 2021.06.06 to 2021.12.17
Release notes https://github.com/ytdl-org/youtube-dl/releases/tag/2021.12.17
2021-12-17 16:12:50 +00:00
30a347dec9 Merge pull request #97 from wader/bump-golang-1.17.5
Update golang from 1.17.4 to 1.17.5
2021-12-10 17:33:36 +01:00
3389e34b7f Update golang from 1.17.4 to 1.17.5
Release notes https://golang.org/doc/devel/release.html
2021-12-10 16:13:10 +00:00
6e39b2fb4b Merge pull request #96 from wader/bump-golang-1.17.4
Update golang from 1.17.3 to 1.17.4
2021-12-04 17:22:47 +01:00
37811576e7 Update golang from 1.17.3 to 1.17.4
Release notes https://golang.org/doc/devel/release.html
2021-12-04 16:12:07 +00:00
87011aa92b Merge pull request #95 from wader/bump-golang-1.17.3
Update golang from 1.17.2 to 1.17.3
2021-11-05 17:31:41 +01:00
233195dd0d Update golang from 1.17.2 to 1.17.3
Release notes https://golang.org/doc/devel/release.html
2021-11-05 16:16:28 +00:00
6e31f063cf Merge pull request #94 from wader/bump-golang-1.17.2
Update golang from 1.17.1 to 1.17.2
2021-10-13 22:22:59 +02:00
41933f0a2b Update golang from 1.17.1 to 1.17.2
Release notes https://golang.org/doc/devel/release.html
2021-10-08 16:11:47 +00:00
d0e3a70ce5 Merge pull request #93 from wader/bump-golang-1.17.1
Update golang from 1.17.0 to 1.17.1
2021-09-10 18:29:37 +02:00
012408bb52 Update golang from 1.17.0 to 1.17.1
Release notes https://golang.org/doc/devel/release.html
2021-09-10 16:11:35 +00:00
c4f0e4cc71 Merge pull request #92 from wader/bump-golang-1.17.0
Update golang from 1.16.7 to 1.17.0
2021-08-17 23:02:18 +02:00
0c48cc0631 Update golang from 1.16.7 to 1.17.0
Release notes https://golang.org/doc/devel/release.html

golang 1.17 base image now uses bullseye
Add python-is-python3 to make python3 default
2021-08-17 22:50:59 +02:00
b5714b7c0b Merge pull request #91 from wader/bump-golang-1.16.7
Update golang from 1.16.6 to 1.16.7
2021-08-06 09:18:54 -07:00
abc93ced75 Update golang from 1.16.6 to 1.16.7
Release notes https://golang.org/doc/devel/release.html
2021-08-06 16:14:15 +00:00
e085ca9cef Merge pull request #90 from wader/bump-golang-1.16.6
Update golang from 1.16.5 to 1.16.6
2021-07-13 11:15:57 -07:00
d159914696 Update golang from 1.16.5 to 1.16.6
Release notes https://golang.org/doc/devel/release.html
2021-07-13 16:14:35 +00:00
3 changed files with 32 additions and 52 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)
} }
} }