Compare commits
43 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 |
@ -1,9 +1,9 @@
|
||||
# bump: golang /GOLANG_VERSION=([\d.]+)/ docker:golang|^1
|
||||
# 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 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
|
||||
ARG YT_DLP
|
||||
|
@ -4,7 +4,7 @@ Go wrapper for
|
||||
[youtube-dl](https://github.com/ytdl-org/youtube-dl) and
|
||||
[yt-dlp](https://github.com/yt-dlp/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
|
||||
install and what is recommended to install in addition to yt-dl.
|
||||
@ -27,7 +27,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/wader/goutubedl"
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/wader/goutubedl"
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/wader/goutubedl"
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
|
78
goutubedl.go
78
goutubedl.go
@ -132,8 +132,9 @@ type Info struct {
|
||||
ThumbnailBytes []byte `json:"-"`
|
||||
Thumbnails []Thumbnail `json:"thumbnails"`
|
||||
|
||||
Formats []Format `json:"formats"`
|
||||
Subtitles map[string][]Subtitle `json:"subtitles"`
|
||||
Formats []Format `json:"formats"`
|
||||
Subtitles map[string][]Subtitle `json:"subtitles"`
|
||||
AutomaticCaptions map[string][]*Caption `json:"automatic_captions"`
|
||||
|
||||
// Playlist entries if _type is playlist
|
||||
Entries []Info `json:"entries"`
|
||||
@ -183,6 +184,14 @@ type Subtitle struct {
|
||||
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 {
|
||||
return fmt.Sprintf("%s:%s:%s abr:%f vbr:%f tbr:%f",
|
||||
f.FormatID,
|
||||
@ -217,13 +226,16 @@ var TypeFromString = map[string]Type{
|
||||
|
||||
// Options for New()
|
||||
type Options struct {
|
||||
Type Type
|
||||
PlaylistStart uint // --playlist-start
|
||||
PlaylistEnd uint // --playlist-end
|
||||
Downloader string // --downloader
|
||||
DownloadThumbnail bool
|
||||
DownloadSubtitles bool
|
||||
DownloadSections string // --download-sections
|
||||
Type Type
|
||||
PlaylistStart uint // --playlist-start
|
||||
PlaylistEnd uint // --playlist-end
|
||||
Downloader string // --downloader
|
||||
DownloadThumbnail bool
|
||||
DownloadSubtitles bool
|
||||
DownloadSubtitlesLang []string
|
||||
DownloadSubtitlesFormat string
|
||||
DownloadSections string // --download-sections
|
||||
Impersonate string // --impersonate
|
||||
|
||||
ProxyUrl string // --proxy URL http://host:port or socks5://host:port
|
||||
UseIPV4 bool // -4 Make all connections via IPv4
|
||||
@ -234,6 +246,9 @@ type Options struct {
|
||||
HTTPClient *http.Client // Client for download thumbnail and subtitles (nil use http.DefaultClient)
|
||||
MergeOutputFormat string // --merge-output-format
|
||||
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,
|
||||
// so the given URL will be downloaded in a single pass in the DownloadResult.Download() call.
|
||||
@ -332,6 +347,10 @@ func infoFromURL(
|
||||
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)
|
||||
}
|
||||
@ -340,6 +359,14 @@ func infoFromURL(
|
||||
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 {
|
||||
case TypePlaylist, TypeChannel:
|
||||
cmd.Args = append(cmd.Args, "--yes-playlist")
|
||||
@ -460,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 {
|
||||
for _, subtitles := range info.Subtitles {
|
||||
for i, subtitle := range subtitles {
|
||||
@ -667,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
|
||||
var stdoutW io.WriteCloser
|
||||
var stderrW io.WriteCloser
|
||||
|
@ -16,13 +16,13 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
"github.com/fortytw2/leaktest"
|
||||
"github.com/wader/goutubedl"
|
||||
"github.com/wader/osleaktest"
|
||||
)
|
||||
|
||||
const (
|
||||
testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
||||
testVideoRawURL = "https://vimeo.com/454525548"
|
||||
playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
||||
channelRawURL = "https://www.youtube.com/channel/UCHDm-DKoMyJxKVgwGmuTaQA"
|
||||
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://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) {
|
||||
defer leakChecks(t)()
|
||||
@ -221,6 +221,8 @@ func TestPlaylist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChannel(t *testing.T) {
|
||||
t.Skip("skip youtube for now")
|
||||
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
@ -267,6 +269,8 @@ func TestUnsupportedURL(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||
t.Skip("skip youtube for now")
|
||||
|
||||
defer leaktest.Check(t)()
|
||||
|
||||
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
||||
@ -287,6 +291,8 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubtitles(t *testing.T) {
|
||||
t.Skip("skip youtube for now")
|
||||
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
@ -332,7 +338,7 @@ func TestDownloadSections(t *testing.T) {
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
context.Background(),
|
||||
"https://www.youtube.com/watch?v=OyuL5biOQ94",
|
||||
"https://vimeo.com/454525548",
|
||||
goutubedl.Options{
|
||||
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
||||
})
|
||||
@ -343,7 +349,7 @@ func TestDownloadSections(t *testing.T) {
|
||||
if ydlResultErr != nil {
|
||||
t.Errorf("failed to download: %s", ydlResultErr)
|
||||
}
|
||||
dr, err := ydlResult.Download(context.Background(), "best")
|
||||
dr, err := ydlResult.Download(context.Background(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -554,6 +560,8 @@ func TestDownloadPlaylistEntry(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatDownloadError(t *testing.T) {
|
||||
t.Skip("test URL broken")
|
||||
|
||||
defer leaktest.Check(t)()
|
||||
|
||||
ydl, ydlErr := goutubedl.New(
|
||||
|
Reference in New Issue
Block a user