This commit is contained in:
45
goutubedl.go
45
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,13 @@ type Subtitle struct {
|
|||||||
Bytes []byte `json:"-"`
|
Bytes []byte `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Caption struct {
|
||||||
|
Ext string `json:"ext"`
|
||||||
|
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,14 +225,15 @@ 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
|
||||||
Impersonate string // --impersonate
|
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
|
||||||
@ -476,6 +485,22 @@ func infoFromURL(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, lang := range options.DownloadSubtitlesLang {
|
||||||
|
if _, ok := info.AutomaticCaptions[lang]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, caption := range info.AutomaticCaptions[lang] {
|
||||||
|
resp, respErr := get(caption.URL)
|
||||||
|
if respErr == nil {
|
||||||
|
buf, _ := io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
caption.Bytes = buf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
Reference in New Issue
Block a user