Renamed rewriteRemotePlaylist (#3313)

* Add support for remote serving endpoint on local storage

* Renamed rewriteRemotePlaylist
This commit is contained in:
Tom Funken 2023-09-22 02:58:02 +02:00 committed by GitHub
parent 75dcd6c0a6
commit e375ea232a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -13,7 +13,9 @@ import (
)
// LocalStorage represents an instance of the local storage provider for HLS video.
type LocalStorage struct{}
type LocalStorage struct {
host string
}
// NewLocalStorage returns a new LocalStorage instance.
func NewLocalStorage() *LocalStorage {
@ -22,6 +24,7 @@ func NewLocalStorage() *LocalStorage {
// Setup configures this storage provider.
func (s *LocalStorage) Setup() error {
s.host = data.GetVideoServingEndpoint()
return nil
}
@ -42,8 +45,16 @@ func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
// 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)
// If we're using a remote serving endpoint, we need to rewrite the master playlist
if s.host != "" {
if err := rewritePlaylistLocations(localFilePath, s.host, ""); err != nil {
log.Warnln(err)
}
} else {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Warnln(err)
}
}
}

View File

@ -12,8 +12,8 @@ import (
log "github.com/sirupsen/logrus"
)
// rewriteRemotePlaylist will take a local playlist and rewrite it to have absolute URLs to remote locations.
func rewriteRemotePlaylist(localFilePath, remoteServingEndpoint, pathPrefix string) error {
// rewritePlaylistLocations will take a local playlist and rewrite it to have absolute URLs to a specified location.
func rewritePlaylistLocations(localFilePath, remoteServingEndpoint, pathPrefix string) error {
f, err := os.Open(localFilePath) // nolint
if err != nil {
log.Fatalln(err)

View File

@ -136,7 +136,7 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) {
// MasterPlaylistWritten is called when the master hls playlist is written.
func (s *S3Storage) MasterPlaylistWritten(localFilePath string) {
// Rewrite the playlist to use absolute remote S3 URLs
if err := rewriteRemotePlaylist(localFilePath, s.host, s.s3PathPrefix); err != nil {
if err := rewritePlaylistLocations(localFilePath, s.host, s.s3PathPrefix); err != nil {
log.Warnln(err)
}
}