Compare commits
1 Commits
master
...
bump-golan
Author | SHA1 | Date | |
---|---|---|---|
d3f32f5956 |
@ -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.23.4
|
ARG GOLANG_VERSION=1.23.1
|
||||||
# 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=2025.01.12
|
ARG YT_DLP=2024.08.06
|
||||||
|
|
||||||
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/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
|
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"
|
||||||
|
|
||||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
"github.com/wader/goutubedl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
"github.com/wader/goutubedl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"gitea.kaz62.ru/dilap54/goutubedl"
|
"github.com/wader/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 gitea.kaz62.ru/dilap54/goutubedl
|
module github.com/wader/goutubedl
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
|
78
goutubedl.go
78
goutubedl.go
@ -132,9 +132,8 @@ 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"`
|
||||||
@ -184,14 +183,6 @@ 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,
|
||||||
@ -226,16 +217,13 @@ 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
|
||||||
DownloadSubtitlesLang []string
|
DownloadSections string // --download-sections
|
||||||
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
|
||||||
@ -246,9 +234,6 @@ type Options struct {
|
|||||||
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.
|
||||||
@ -347,10 +332,6 @@ 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 != "" {
|
if options.Cookies != "" {
|
||||||
cmd.Args = append(cmd.Args, "--cookies", options.Cookies)
|
cmd.Args = append(cmd.Args, "--cookies", options.Cookies)
|
||||||
}
|
}
|
||||||
@ -359,14 +340,6 @@ func infoFromURL(
|
|||||||
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")
|
||||||
@ -487,31 +460,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 {
|
if options.DownloadSubtitles {
|
||||||
for _, subtitles := range info.Subtitles {
|
for _, subtitles := range info.Subtitles {
|
||||||
for i, subtitle := range subtitles {
|
for i, subtitle := range subtitles {
|
||||||
@ -719,14 +667,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
|
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://vimeo.com/454525548"
|
testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
||||||
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://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) {
|
t.Run(c.url, func(t *testing.T) {
|
||||||
defer leakChecks(t)()
|
defer leakChecks(t)()
|
||||||
@ -221,8 +221,6 @@ 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(
|
||||||
@ -269,8 +267,6 @@ 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"
|
||||||
@ -291,8 +287,6 @@ 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(
|
||||||
@ -338,7 +332,7 @@ func TestDownloadSections(t *testing.T) {
|
|||||||
|
|
||||||
ydlResult, ydlResultErr := goutubedl.New(
|
ydlResult, ydlResultErr := goutubedl.New(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
"https://vimeo.com/454525548",
|
"https://www.youtube.com/watch?v=OyuL5biOQ94",
|
||||||
goutubedl.Options{
|
goutubedl.Options{
|
||||||
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
DownloadSections: fmt.Sprintf("*0:0-0:%d", duration),
|
||||||
})
|
})
|
||||||
@ -349,7 +343,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(), "")
|
dr, err := ydlResult.Download(context.Background(), "best")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -560,8 +554,6 @@ 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