This commit is contained in:
25
goutubedl.go
25
goutubedl.go
@ -134,6 +134,7 @@ type Info struct {
|
||||
|
||||
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,13 @@ type Subtitle struct {
|
||||
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 {
|
||||
return fmt.Sprintf("%s:%s:%s abr:%f vbr:%f tbr:%f",
|
||||
f.FormatID,
|
||||
@ -223,6 +231,7 @@ type Options struct {
|
||||
Downloader string // --downloader
|
||||
DownloadThumbnail bool
|
||||
DownloadSubtitles bool
|
||||
DownloadSubtitlesLang []string
|
||||
DownloadSections string // --download-sections
|
||||
Impersonate string // --impersonate
|
||||
|
||||
@ -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 {
|
||||
for _, subtitles := range info.Subtitles {
|
||||
for i, subtitle := range subtitles {
|
||||
|
Reference in New Issue
Block a user