Compare commits
50 Commits
bump-golan
...
master
Author | SHA1 | Date | |
---|---|---|---|
cb39bec3a6 | |||
1815e33339 | |||
646859b4c1 | |||
55e7486f50 | |||
506804ebb3 | |||
cafbe3c1a9 | |||
63a707e70a | |||
c84fe2feb6 | |||
24cc3575e4 | |||
1a1941ca29 | |||
faa303a45c | |||
b534e45a9c | |||
e8e101773e | |||
2ce13a3453 | |||
33e26ae818 | |||
940ca8b439 | |||
8ebc956d58 | |||
fe2e84d624 | |||
4749af12f9 | |||
b80c451351 | |||
63dcb4b7f5 | |||
56b36e04e0 | |||
2623ce39cc | |||
a8a0daa240 | |||
5e1bb9940f | |||
736ec471fb | |||
f902ca5cee | |||
ce1d7dd3a4 | |||
d51f319f36 | |||
f16338a0be | |||
bb47becd77 | |||
137b17daf1 | |||
1b8fc57051 | |||
7f2cc0f2b4 | |||
eb679c5ee1 | |||
c71ec4178b | |||
24655e2ef8 | |||
74ed4258b3 | |||
3d96f632e1 | |||
eb9555dbed | |||
fed2a6ab45 | |||
945bbd6026 | |||
d104f30286 | |||
a623bde37b | |||
90467bcf8a | |||
d47fecba92 | |||
65804d5c0f | |||
95037e2caf | |||
346cfb47a0 | |||
3abe5ae66a |
@ -1,9 +1,9 @@
|
|||||||
# 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.22.6
|
ARG GOLANG_VERSION=1.23.4
|
||||||
# bump: yt-dlp /YT_DLP=([\d.-]+)/ https://github.com/yt-dlp/yt-dlp.git|/^\d/|sort
|
# bump: yt-dlp /YT_DLP=([\d.-]+)/ https://github.com/yt-dlp/yt-dlp.git|/^\d/|sort
|
||||||
# bump: yt-dlp link "Release notes" https://github.com/yt-dlp/yt-dlp/releases/tag/$LATEST
|
# bump: yt-dlp link "Release notes" https://github.com/yt-dlp/yt-dlp/releases/tag/$LATEST
|
||||||
ARG YT_DLP=2024.08.06
|
ARG YT_DLP=2025.01.12
|
||||||
|
|
||||||
FROM golang:$GOLANG_VERSION AS base
|
FROM golang:$GOLANG_VERSION AS base
|
||||||
ARG YT_DLP
|
ARG YT_DLP
|
||||||
|
@ -4,7 +4,7 @@ Go wrapper for
|
|||||||
[youtube-dl](https://github.com/ytdl-org/youtube-dl) and
|
[youtube-dl](https://github.com/ytdl-org/youtube-dl) and
|
||||||
[yt-dlp](https://github.com/yt-dlp/yt-dlp).
|
[yt-dlp](https://github.com/yt-dlp/yt-dlp).
|
||||||
Currently only tested and developed using yt-dlp.
|
Currently only tested and developed using yt-dlp.
|
||||||
API documentation can be found at [godoc.org](https://pkg.go.dev/github.com/wader/goutubedl?tab=doc).
|
API documentation can be found at [godoc.org](https://pkg.go.dev/gitea.kaz62.ru/dilap54/goutubedl?tab=doc).
|
||||||
|
|
||||||
See [yt-dlp documentation](https://github.com/yt-dlp/yt-dlp) for how to
|
See [yt-dlp documentation](https://github.com/yt-dlp/yt-dlp) for how to
|
||||||
install and what is recommended to install in addition to yt-dl.
|
install and what is recommended to install in addition to yt-dl.
|
||||||
@ -27,7 +27,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wader/goutubedl"
|
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/wader/goutubedl"
|
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/wader/goutubedl"
|
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dumpFlag = flag.Bool("J", false, "Dump JSON")
|
var dumpFlag = flag.Bool("J", false, "Dump JSON")
|
||||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module github.com/wader/goutubedl
|
module gitea.kaz62.ru/dilap54/goutubedl
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
|
94
goutubedl.go
94
goutubedl.go
@ -132,8 +132,9 @@ type Info struct {
|
|||||||
ThumbnailBytes []byte `json:"-"`
|
ThumbnailBytes []byte `json:"-"`
|
||||||
Thumbnails []Thumbnail `json:"thumbnails"`
|
Thumbnails []Thumbnail `json:"thumbnails"`
|
||||||
|
|
||||||
Formats []Format `json:"formats"`
|
Formats []Format `json:"formats"`
|
||||||
Subtitles map[string][]Subtitle `json:"subtitles"`
|
Subtitles map[string][]Subtitle `json:"subtitles"`
|
||||||
|
AutomaticCaptions map[string][]*Caption `json:"automatic_captions"`
|
||||||
|
|
||||||
// Playlist entries if _type is playlist
|
// Playlist entries if _type is playlist
|
||||||
Entries []Info `json:"entries"`
|
Entries []Info `json:"entries"`
|
||||||
@ -183,6 +184,14 @@ type Subtitle struct {
|
|||||||
Bytes []byte `json:"-"`
|
Bytes []byte `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Caption struct {
|
||||||
|
Ext string `json:"ext"`
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Bytes []byte `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
func (f Format) String() string {
|
func (f Format) String() string {
|
||||||
return fmt.Sprintf("%s:%s:%s abr:%f vbr:%f tbr:%f",
|
return fmt.Sprintf("%s:%s:%s abr:%f vbr:%f tbr:%f",
|
||||||
f.FormatID,
|
f.FormatID,
|
||||||
@ -217,21 +226,29 @@ var TypeFromString = map[string]Type{
|
|||||||
|
|
||||||
// Options for New()
|
// Options for New()
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Type Type
|
Type Type
|
||||||
PlaylistStart uint // --playlist-start
|
PlaylistStart uint // --playlist-start
|
||||||
PlaylistEnd uint // --playlist-end
|
PlaylistEnd uint // --playlist-end
|
||||||
Downloader string // --downloader
|
Downloader string // --downloader
|
||||||
DownloadThumbnail bool
|
DownloadThumbnail bool
|
||||||
DownloadSubtitles bool
|
DownloadSubtitles bool
|
||||||
DownloadSections string // --download-sections
|
DownloadSubtitlesLang []string
|
||||||
|
DownloadSubtitlesFormat string
|
||||||
|
DownloadSections string // --download-sections
|
||||||
|
Impersonate string // --impersonate
|
||||||
|
|
||||||
ProxyUrl string // --proxy URL http://host:port or socks5://host:port
|
ProxyUrl string // --proxy URL http://host:port or socks5://host:port
|
||||||
UseIPV4 bool // -4 Make all connections via IPv4
|
UseIPV4 bool // -4 Make all connections via IPv4
|
||||||
|
Cookies string // --cookies FILE
|
||||||
CookiesFromBrowser string // --cookies-from-browser BROWSER[:FOLDER]
|
CookiesFromBrowser string // --cookies-from-browser BROWSER[:FOLDER]
|
||||||
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
|
||||||
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)
|
||||||
MergeOutputFormat string // --merge-output-format
|
MergeOutputFormat string // --merge-output-format
|
||||||
SortingFormat string // --format-sort
|
SortingFormat string // --format-sort
|
||||||
|
ExtractorArgs string // --extractor-args
|
||||||
|
InfoArgs []string
|
||||||
|
DownloadArgs []string
|
||||||
|
|
||||||
// Set to true if you don't want to use the result.Info structure after the goutubedl.New() call,
|
// Set to true if you don't want to use the result.Info structure after the goutubedl.New() call,
|
||||||
// so the given URL will be downloaded in a single pass in the DownloadResult.Download() call.
|
// so the given URL will be downloaded in a single pass in the DownloadResult.Download() call.
|
||||||
@ -330,10 +347,26 @@ func infoFromURL(
|
|||||||
cmd.Args = append(cmd.Args, "--downloader", options.Downloader)
|
cmd.Args = append(cmd.Args, "--downloader", options.Downloader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Impersonate != "" {
|
||||||
|
cmd.Args = append(cmd.Args, "--impersonate", options.Impersonate)
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Cookies != "" {
|
||||||
|
cmd.Args = append(cmd.Args, "--cookies", options.Cookies)
|
||||||
|
}
|
||||||
|
|
||||||
if options.CookiesFromBrowser != "" {
|
if options.CookiesFromBrowser != "" {
|
||||||
cmd.Args = append(cmd.Args, "--cookies-from-browser", options.CookiesFromBrowser)
|
cmd.Args = append(cmd.Args, "--cookies-from-browser", options.CookiesFromBrowser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.ExtractorArgs != "" {
|
||||||
|
cmd.Args = append(cmd.Args,
|
||||||
|
"--extractor-args", options.ExtractorArgs,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Args = append(cmd.Args, options.InfoArgs...)
|
||||||
|
|
||||||
switch options.Type {
|
switch options.Type {
|
||||||
case TypePlaylist, TypeChannel:
|
case TypePlaylist, TypeChannel:
|
||||||
cmd.Args = append(cmd.Args, "--yes-playlist")
|
cmd.Args = append(cmd.Args, "--yes-playlist")
|
||||||
@ -454,6 +487,31 @@ func infoFromURL(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, lang := range options.DownloadSubtitlesLang {
|
||||||
|
if _, ok := info.AutomaticCaptions[lang]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, caption := range info.AutomaticCaptions[lang] {
|
||||||
|
if options.DownloadSubtitlesFormat != "" && caption.Ext != options.DownloadSubtitlesFormat {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, respErr := get(caption.URL)
|
||||||
|
if respErr == nil {
|
||||||
|
buf, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
options.DebugLog.Print("err", "download captions "+caption.URL, err)
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
|
caption.Bytes = buf
|
||||||
|
} else {
|
||||||
|
options.DebugLog.Print("err", "download captions "+caption.URL, respErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if options.DownloadSubtitles {
|
if options.DownloadSubtitles {
|
||||||
for _, subtitles := range info.Subtitles {
|
for _, subtitles := range info.Subtitles {
|
||||||
for i, subtitle := range subtitles {
|
for i, subtitle := range subtitles {
|
||||||
@ -522,6 +580,8 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DownloadOptions struct {
|
type DownloadOptions struct {
|
||||||
|
AudioFormats string // --audio-formats Download audio using formats (best, aac, alac, flac, m4a, mp3, opus, vorbis, wav)
|
||||||
|
DownloadAudioOnly bool // -x Download audio only from video
|
||||||
// Download format matched by filter (usually a format id or quality designator).
|
// Download format matched by filter (usually a format id or quality designator).
|
||||||
// If filter is empty, then youtube-dl will use its default format selector.
|
// If filter is empty, then youtube-dl will use its default format selector.
|
||||||
Filter string
|
Filter string
|
||||||
@ -623,6 +683,14 @@ func (result Result) DownloadWithOptions(
|
|||||||
cmd.Args = append(cmd.Args, "--playlist-items", fmt.Sprint(options.PlaylistIndex))
|
cmd.Args = append(cmd.Args, "--playlist-items", fmt.Sprint(options.PlaylistIndex))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.DownloadAudioOnly {
|
||||||
|
cmd.Args = append(cmd.Args, "-x")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.AudioFormats != "" {
|
||||||
|
cmd.Args = append(cmd.Args, "--audio-format", options.AudioFormats)
|
||||||
|
}
|
||||||
|
|
||||||
if result.Options.ProxyUrl != "" {
|
if result.Options.ProxyUrl != "" {
|
||||||
cmd.Args = append(cmd.Args, "--proxy", result.Options.ProxyUrl)
|
cmd.Args = append(cmd.Args, "--proxy", result.Options.ProxyUrl)
|
||||||
}
|
}
|
||||||
@ -651,6 +719,14 @@ func (result Result) DownloadWithOptions(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.Options.ExtractorArgs != "" {
|
||||||
|
cmd.Args = append(cmd.Args,
|
||||||
|
"--extractor-args", result.Options.ExtractorArgs,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Args = append(cmd.Args, result.Options.DownloadArgs...)
|
||||||
|
|
||||||
cmd.Dir = tempPath
|
cmd.Dir = tempPath
|
||||||
var stdoutW io.WriteCloser
|
var stdoutW io.WriteCloser
|
||||||
var stderrW io.WriteCloser
|
var stderrW io.WriteCloser
|
||||||
|
@ -16,13 +16,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||||
"github.com/fortytw2/leaktest"
|
"github.com/fortytw2/leaktest"
|
||||||
"github.com/wader/goutubedl"
|
|
||||||
"github.com/wader/osleaktest"
|
"github.com/wader/osleaktest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
testVideoRawURL = "https://vimeo.com/454525548"
|
||||||
playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
||||||
channelRawURL = "https://www.youtube.com/channel/UCHDm-DKoMyJxKVgwGmuTaQA"
|
channelRawURL = "https://www.youtube.com/channel/UCHDm-DKoMyJxKVgwGmuTaQA"
|
||||||
subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
|
subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
|
||||||
@ -139,7 +139,7 @@ func TestParseInfo(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"https://soundcloud.com/avalonemerson/avalon-emerson-live-at-printworks-london-march-2017", "Avalon Emerson Live at Printworks London 2017"},
|
{"https://soundcloud.com/avalonemerson/avalon-emerson-live-at-printworks-london-march-2017", "Avalon Emerson Live at Printworks London 2017"},
|
||||||
{"https://www.infoq.com/presentations/Simple-Made-Easy", "Simple Made Easy - InfoQ"},
|
{"https://www.infoq.com/presentations/Simple-Made-Easy", "Simple Made Easy - InfoQ"},
|
||||||
{"https://www.youtube.com/watch?v=uVYWQJ5BB_w", "A Radiolab Producer on the Making of a Podcast"},
|
{"https://vimeo.com/454525548", "Sample Video - 3 minutemp4.mp4"},
|
||||||
} {
|
} {
|
||||||
t.Run(c.url, func(t *testing.T) {
|
t.Run(c.url, func(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
@ -221,6 +221,8 @@ func TestPlaylist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestChannel(t *testing.T) {
|
func TestChannel(t *testing.T) {
|
||||||
|
t.Skip("skip youtube for now")
|
||||||
|
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(
|
ydlResult, ydlResultErr := goutubedl.New(
|
||||||
@ -267,6 +269,8 @@ func TestUnsupportedURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlaylistWithPrivateVideo(t *testing.T) {
|
func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||||
|
t.Skip("skip youtube for now")
|
||||||
|
|
||||||
defer leaktest.Check(t)()
|
defer leaktest.Check(t)()
|
||||||
|
|
||||||
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
||||||
@ -287,6 +291,8 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSubtitles(t *testing.T) {
|
func TestSubtitles(t *testing.T) {
|
||||||
|
t.Skip("skip youtube for now")
|
||||||
|
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(
|
ydlResult, ydlResultErr := goutubedl.New(
|
||||||
@ -332,7 +338,7 @@ func TestDownloadSections(t *testing.T) {
|
|||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(
|
ydlResult, ydlResultErr := goutubedl.New(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
"https://www.youtube.com/watch?v=OyuL5biOQ94",
|
"https://vimeo.com/454525548",
|
||||||
goutubedl.Options{
|
goutubedl.Options{
|
||||||
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
||||||
})
|
})
|
||||||
@ -343,7 +349,7 @@ func TestDownloadSections(t *testing.T) {
|
|||||||
if ydlResultErr != nil {
|
if ydlResultErr != nil {
|
||||||
t.Errorf("failed to download: %s", ydlResultErr)
|
t.Errorf("failed to download: %s", ydlResultErr)
|
||||||
}
|
}
|
||||||
dr, err := ydlResult.Download(context.Background(), "best")
|
dr, err := ydlResult.Download(context.Background(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -554,6 +560,8 @@ func TestDownloadPlaylistEntry(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatDownloadError(t *testing.T) {
|
func TestFormatDownloadError(t *testing.T) {
|
||||||
|
t.Skip("test URL broken")
|
||||||
|
|
||||||
defer leaktest.Check(t)()
|
defer leaktest.Check(t)()
|
||||||
|
|
||||||
ydl, ydlErr := goutubedl.New(
|
ydl, ydlErr := goutubedl.New(
|
||||||
|
Reference in New Issue
Block a user