mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added InitVideo() function to initialize Format.Video.Chunklist
This commit is contained in:
parent
685dbc622e
commit
758b9b59c8
1 changed files with 22 additions and 0 deletions
22
format.go
22
format.go
|
|
@ -34,6 +34,28 @@ type Format struct {
|
|||
Subtitles []*Subtitle
|
||||
}
|
||||
|
||||
// InitVideo initializes the Format.Video completely.
|
||||
// The Format.Video.Chunklist pointer is, by default, nil because an additional
|
||||
// request must be made to receive its content. The request is not made when
|
||||
// initializing a Format struct because it would probably cause an intense overhead
|
||||
// since Format.Video.Chunklist is only used sometimes
|
||||
func (f *Format) InitVideo() error {
|
||||
if f.Video.Chunklist == nil {
|
||||
resp, err := f.crunchy.Client.Get(f.Video.URI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
playlist, _, err := m3u8.DecodeFrom(resp.Body, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.Video.Chunklist = playlist.(*m3u8.MediaPlaylist)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Format) Download(downloader Downloader) error {
|
||||
if _, err := os.Stat(downloader.Filename); err == nil && !downloader.IgnoreExisting {
|
||||
return fmt.Errorf("file %s already exists", downloader.Filename)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue