Make setting save location paths optional

This commit is contained in:
Gabe Kangas 2020-07-13 14:45:54 -07:00
parent d51901e191
commit 44806d1a8e
6 changed files with 34 additions and 22 deletions

View file

@ -1,5 +1,3 @@
publicHLSPath: webroot/hls
privateHLSPath: hls
webServerPort: 8080
instanceDetails:

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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()

View file

@ -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))
}

View file

@ -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)