Compare commits
1 Commits
master
...
bump-golan
Author | SHA1 | Date | |
---|---|---|---|
40fcd69601 |
@ -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.23.4
|
||||
ARG GOLANG_VERSION=1.23.0
|
||||
# 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=2025.01.12
|
||||
ARG YT_DLP=2024.08.06
|
||||
|
||||
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/gitea.kaz62.ru/dilap54/goutubedl?tab=doc).
|
||||
API documentation can be found at [godoc.org](https://pkg.go.dev/github.com/wader/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"
|
||||
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
"github.com/wader/goutubedl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
"github.com/wader/goutubedl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
||||
"github.com/wader/goutubedl"
|
||||
)
|
||||
|
||||
var dumpFlag = flag.Bool("J", false, "Dump JSON")
|
||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module gitea.kaz62.ru/dilap54/goutubedl
|
||||
module github.com/wader/goutubedl
|
||||
|
||||
go 1.12
|
||||
|
||||
|
94
goutubedl.go
94
goutubedl.go
@ -132,9 +132,8 @@ type Info struct {
|
||||
ThumbnailBytes []byte `json:"-"`
|
||||
Thumbnails []Thumbnail `json:"thumbnails"`
|
||||
|
||||
Formats []Format `json:"formats"`
|
||||
Subtitles map[string][]Subtitle `json:"subtitles"`
|
||||
AutomaticCaptions map[string][]*Caption `json:"automatic_captions"`
|
||||
Formats []Format `json:"formats"`
|
||||
Subtitles map[string][]Subtitle `json:"subtitles"`
|
||||
|
||||
// Playlist entries if _type is playlist
|
||||
Entries []Info `json:"entries"`
|
||||
@ -184,14 +183,6 @@ 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,
|
||||
@ -226,29 +217,21 @@ 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
|
||||
DownloadSubtitlesLang []string
|
||||
DownloadSubtitlesFormat string
|
||||
DownloadSections string // --download-sections
|
||||
Impersonate string // --impersonate
|
||||
|
||||
Type Type
|
||||
PlaylistStart uint // --playlist-start
|
||||
PlaylistEnd uint // --playlist-end
|
||||
Downloader string // --downloader
|
||||
DownloadThumbnail bool
|
||||
DownloadSubtitles bool
|
||||
DownloadSections string // --download-sections
|
||||
ProxyUrl string // --proxy URL http://host:port or socks5://host:port
|
||||
UseIPV4 bool // -4 Make all connections via IPv4
|
||||
Cookies string // --cookies FILE
|
||||
CookiesFromBrowser string // --cookies-from-browser BROWSER[:FOLDER]
|
||||
DebugLog Printer
|
||||
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)
|
||||
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.
|
||||
@ -347,26 +330,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)
|
||||
}
|
||||
|
||||
if 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 {
|
||||
case TypePlaylist, TypeChannel:
|
||||
cmd.Args = append(cmd.Args, "--yes-playlist")
|
||||
@ -487,31 +454,6 @@ 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 {
|
||||
@ -580,8 +522,6 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
||||
}
|
||||
|
||||
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).
|
||||
// If filter is empty, then youtube-dl will use its default format selector.
|
||||
Filter string
|
||||
@ -683,14 +623,6 @@ func (result Result) DownloadWithOptions(
|
||||
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 != "" {
|
||||
cmd.Args = append(cmd.Args, "--proxy", result.Options.ProxyUrl)
|
||||
}
|
||||
@ -719,14 +651,6 @@ 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://vimeo.com/454525548"
|
||||
testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
||||
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://vimeo.com/454525548", "Sample Video - 3 minutemp4.mp4"},
|
||||
{"https://www.youtube.com/watch?v=uVYWQJ5BB_w", "A Radiolab Producer on the Making of a Podcast"},
|
||||
} {
|
||||
t.Run(c.url, func(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
@ -221,8 +221,6 @@ func TestPlaylist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChannel(t *testing.T) {
|
||||
t.Skip("skip youtube for now")
|
||||
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
@ -269,8 +267,6 @@ 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"
|
||||
@ -291,8 +287,6 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubtitles(t *testing.T) {
|
||||
t.Skip("skip youtube for now")
|
||||
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
@ -338,7 +332,7 @@ func TestDownloadSections(t *testing.T) {
|
||||
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
context.Background(),
|
||||
"https://vimeo.com/454525548",
|
||||
"https://www.youtube.com/watch?v=OyuL5biOQ94",
|
||||
goutubedl.Options{
|
||||
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
||||
})
|
||||
@ -349,7 +343,7 @@ func TestDownloadSections(t *testing.T) {
|
||||
if ydlResultErr != nil {
|
||||
t.Errorf("failed to download: %s", ydlResultErr)
|
||||
}
|
||||
dr, err := ydlResult.Download(context.Background(), "")
|
||||
dr, err := ydlResult.Download(context.Background(), "best")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -560,8 +554,6 @@ 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