diff --git a/config-example.yaml b/config-example.yaml index 026befb47..a01af771a 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -1,5 +1,3 @@ -publicHLSPath: webroot/hls -privateHLSPath: hls webServerPort: 8080 instanceDetails: diff --git a/config/config.go b/config/config.go index 71910b3ea..665802052 100644 --- a/config/config.go +++ b/config/config.go @@ -164,6 +164,22 @@ func (c *config) GetVideoSegmentSecondsLength() int { return 4 } +func (c *config) GetPublicHLSSavePath() string { + if c.PublicHLSPath != "" { + return c.PublicHLSPath + } + + return "webroot/hls" +} + +func (c *config) GetPrivateHLSSavePath() string { + if c.PrivateHLSPath != "" { + return c.PrivateHLSPath + } + + return "hls" +} + //Load tries to load the configuration file func Load(filePath string, versionInfo string) error { Config = new(config) diff --git a/core/core.go b/core/core.go index 3469f0627..1047a9dd6 100644 --- a/core/core.go +++ b/core/core.go @@ -60,10 +60,10 @@ func resetDirectories() { log.Trace("Resetting file directories to a clean slate.") // Wipe the public, web-accessible hls data directory - os.RemoveAll(config.Config.PublicHLSPath) - os.RemoveAll(config.Config.PrivateHLSPath) - os.MkdirAll(config.Config.PublicHLSPath, 0777) - os.MkdirAll(config.Config.PrivateHLSPath, 0777) + os.RemoveAll(config.Config.GetPublicHLSSavePath()) + os.RemoveAll(config.Config.GetPrivateHLSSavePath()) + os.MkdirAll(config.Config.GetPublicHLSSavePath(), 0777) + os.MkdirAll(config.Config.GetPrivateHLSSavePath(), 0777) // Remove the previous thumbnail os.Remove("webroot/thumbnail.jpg") @@ -71,11 +71,11 @@ func resetDirectories() { // Create private hls data dirs if len(config.Config.VideoSettings.StreamQualities) != 0 { for index := range config.Config.VideoSettings.StreamQualities { - os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(index)), 0777) - os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(index)), 0777) + os.MkdirAll(path.Join(config.Config.GetPrivateHLSSavePath(), strconv.Itoa(index)), 0777) + os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(index)), 0777) } } else { - os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(0)), 0777) - os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(0)), 0777) + os.MkdirAll(path.Join(config.Config.GetPrivateHLSSavePath(), strconv.Itoa(0)), 0777) + os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(0)), 0777) } } diff --git a/core/ffmpeg/transcoder.go b/core/ffmpeg/transcoder.go index c7bb649f0..fd4643fd0 100644 --- a/core/ffmpeg/transcoder.go +++ b/core/ffmpeg/transcoder.go @@ -179,15 +179,15 @@ func NewTranscoder() Transcoder { var outputPath string if config.Config.S3.Enabled || config.Config.IPFS.Enabled { // Segments are not available via the local HTTP server - outputPath = config.Config.PrivateHLSPath + outputPath = config.Config.GetPrivateHLSSavePath() } else { // Segments are available via the local HTTP server - outputPath = config.Config.PublicHLSPath + outputPath = config.Config.GetPublicHLSSavePath() } transcoder.segmentOutputPath = outputPath // Playlists are available via the local HTTP server - transcoder.playlistOutputPath = config.Config.PublicHLSPath + transcoder.playlistOutputPath = config.Config.GetPublicHLSSavePath() transcoder.input = utils.GetTemporaryPipePath() transcoder.segmentLengthSeconds = config.Config.GetVideoSegmentSecondsLength() diff --git a/core/playlist/monitor.go b/core/playlist/monitor.go index a010ba420..cba85dc89 100644 --- a/core/playlist/monitor.go +++ b/core/playlist/monitor.go @@ -26,7 +26,7 @@ var ( func StartVideoContentMonitor(storage models.ChunkStorageProvider) error { _storage = storage - pathToMonitor := config.Config.PrivateHLSPath + pathToMonitor := config.Config.GetPrivateHLSSavePath() // Create at least one structure to store the segments for the different stream variants variants = make([]models.Variant, len(config.Config.VideoSettings.StreamQualities)) @@ -66,8 +66,8 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error { // fmt.Println(event.Op, relativePath) // Handle updates to the master playlist by copying it to webroot - if relativePath == path.Join(config.Config.PrivateHLSPath, "stream.m3u8") { - utils.Copy(event.Path, path.Join(config.Config.PublicHLSPath, "stream.m3u8")) + if relativePath == path.Join(config.Config.GetPrivateHLSSavePath(), "stream.m3u8") { + utils.Copy(event.Path, path.Join(config.Config.GetPublicHLSSavePath(), "stream.m3u8")) } else if filepath.Ext(event.Path) == ".m3u8" { // Handle updates to playlists, but not the master playlist @@ -82,7 +82,7 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error { newObjectPathChannel := make(chan string, 1) go func() { - newObjectPath, err := storage.Save(path.Join(config.Config.PrivateHLSPath, segment.RelativeUploadPath), 0) + newObjectPath, err := storage.Save(path.Join(config.Config.GetPrivateHLSSavePath(), segment.RelativeUploadPath), 0) if err != nil { log.Errorln("failed to save the file to the chunk storage.", err) } @@ -153,9 +153,7 @@ func updateVariantPlaylist(fullPath string) error { } playlistString := string(playlistBytes) - // fmt.Println("Rewriting playlist", relativePath, "to", path.Join(config.Config.PublicHLSPath, relativePath)) - playlistString = _storage.GenerateRemotePlaylist(playlistString, variant) - return WritePlaylist(playlistString, path.Join(config.Config.PublicHLSPath, relativePath)) + return WritePlaylist(playlistString, path.Join(config.Config.GetPublicHLSSavePath(), relativePath)) } diff --git a/core/status.go b/core/status.go index d7c1c535b..2eaebb15b 100644 --- a/core/status.go +++ b/core/status.go @@ -34,9 +34,9 @@ func SetStreamAsConnected() { _stats.SessionMaxViewerCount = 0 } - chunkPath := config.Config.PublicHLSPath + chunkPath := config.Config.GetPublicHLSSavePath() if usingExternalStorage { - chunkPath = config.Config.PrivateHLSPath + chunkPath = config.Config.GetPrivateHLSSavePath() } ffmpeg.StartThumbnailGenerator(chunkPath, config.Config.VideoSettings.HighestQualityStreamIndex)