owncast/core/storageproviders/local.go
Gabe Kangas 1b053ffd1b
Simplify HLS storage paths (#1393)
* Remove private vs public HLS paths and add a HLS controller. Closes #875

* Use http.ServeFile instead
2021-09-12 11:32:42 -07:00

58 lines
1.6 KiB
Go

package storageproviders
import (
"time"
log "github.com/sirupsen/logrus"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/transcoder"
)
// LocalStorage represents an instance of the local storage provider for HLS video.
type LocalStorage struct {
}
// Cleanup old public HLS content every N min from the webroot.
var _onlineCleanupTicker *time.Ticker
// Setup configures this storage provider.
func (s *LocalStorage) Setup() error {
// NOTE: This cleanup timer will have to be disabled to support recordings in the future
// as all HLS segments have to be publicly available on disk to keep a recording of them.
_onlineCleanupTicker = time.NewTicker(1 * time.Minute)
go func() {
for range _onlineCleanupTicker.C {
transcoder.CleanupOldContent(config.HLSStoragePath)
}
}()
return nil
}
// SegmentWritten is called when a single segment of video is written.
func (s *LocalStorage) SegmentWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Warnln(err)
}
}
// VariantPlaylistWritten is called when a variant hls playlist is written.
func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Errorln(err)
return
}
}
// MasterPlaylistWritten is called when the master hls playlist is written.
func (s *LocalStorage) MasterPlaylistWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Warnln(err)
}
}
// Save will save a local filepath using the storage provider.
func (s *LocalStorage) Save(filePath string, retryCount int) (string, error) {
return filePath, nil
}