Remove custom paths and add constants (#216)
This commit is contained in:
23
core/core.go
23
core/core.go
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -56,8 +57,8 @@ func Start() error {
|
||||
|
||||
func createInitialOfflineState() error {
|
||||
// Provide default files
|
||||
if !utils.DoesFileExists("webroot/thumbnail.jpg") {
|
||||
if err := utils.Copy("static/logo.png", "webroot/thumbnail.jpg"); err != nil {
|
||||
if !utils.DoesFileExists(filepath.Join(config.WebRoot, "thumbnail.jpg")) {
|
||||
if err := utils.Copy("static/logo.png", filepath.Join(config.WebRoot, "thumbnail.jpg")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -93,22 +94,22 @@ func resetDirectories() {
|
||||
log.Trace("Resetting file directories to a clean slate.")
|
||||
|
||||
// Wipe the public, web-accessible hls data directory
|
||||
os.RemoveAll(config.Config.GetPublicHLSSavePath())
|
||||
os.RemoveAll(config.Config.GetPrivateHLSSavePath())
|
||||
os.MkdirAll(config.Config.GetPublicHLSSavePath(), 0777)
|
||||
os.MkdirAll(config.Config.GetPrivateHLSSavePath(), 0777)
|
||||
os.RemoveAll(config.PublicHLSStoragePath)
|
||||
os.RemoveAll(config.PrivateHLSStoragePath)
|
||||
os.MkdirAll(config.PublicHLSStoragePath, 0777)
|
||||
os.MkdirAll(config.PrivateHLSStoragePath, 0777)
|
||||
|
||||
// Remove the previous thumbnail
|
||||
os.Remove("webroot/thumbnail.jpg")
|
||||
os.Remove(filepath.Join(config.WebRoot, "thumbnail.jpg"))
|
||||
|
||||
// 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.GetPrivateHLSSavePath(), strconv.Itoa(index)), 0777)
|
||||
os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(index)), 0777)
|
||||
os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777)
|
||||
os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(index)), 0777)
|
||||
}
|
||||
} else {
|
||||
os.MkdirAll(path.Join(config.Config.GetPrivateHLSSavePath(), strconv.Itoa(0)), 0777)
|
||||
os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(0)), 0777)
|
||||
os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)), 0777)
|
||||
os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)), 0777)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ func StartThumbnailGenerator(chunkPath string, variantIndex int) {
|
||||
|
||||
func fireThumbnailGenerator(chunkPath string, variantIndex int) error {
|
||||
// JPG takes less time to encode than PNG
|
||||
outputFile := path.Join("webroot", "thumbnail.jpg")
|
||||
previewGifFile := path.Join("webroot", "preview.gif")
|
||||
outputFile := path.Join(config.WebRoot, "thumbnail.jpg")
|
||||
previewGifFile := path.Join(config.WebRoot, "preview.gif")
|
||||
|
||||
framePath := path.Join(chunkPath, strconv.Itoa(variantIndex))
|
||||
files, err := ioutil.ReadDir(framePath)
|
||||
|
||||
@@ -188,15 +188,15 @@ func NewTranscoder() Transcoder {
|
||||
var outputPath string
|
||||
if config.Config.S3.Enabled {
|
||||
// Segments are not available via the local HTTP server
|
||||
outputPath = config.Config.GetPrivateHLSSavePath()
|
||||
outputPath = config.PrivateHLSStoragePath
|
||||
} else {
|
||||
// Segments are available via the local HTTP server
|
||||
outputPath = config.Config.GetPublicHLSSavePath()
|
||||
outputPath = config.PublicHLSStoragePath
|
||||
}
|
||||
|
||||
transcoder.segmentOutputPath = outputPath
|
||||
// Playlists are available via the local HTTP server
|
||||
transcoder.playlistOutputPath = config.Config.GetPublicHLSSavePath()
|
||||
transcoder.playlistOutputPath = config.PublicHLSStoragePath
|
||||
|
||||
transcoder.input = utils.GetTemporaryPipePath()
|
||||
transcoder.segmentLengthSeconds = config.Config.GetVideoSegmentSecondsLength()
|
||||
|
||||
@@ -26,7 +26,7 @@ var (
|
||||
func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
||||
_storage = storage
|
||||
|
||||
pathToMonitor := config.Config.GetPrivateHLSSavePath()
|
||||
pathToMonitor := config.PrivateHLSStoragePath
|
||||
|
||||
// Create at least one structure to store the segments for the different stream variants
|
||||
variants = make([]models.Variant, len(config.Config.VideoSettings.StreamQualities))
|
||||
@@ -63,11 +63,9 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
||||
continue
|
||||
}
|
||||
|
||||
// fmt.Println(event.Op, relativePath)
|
||||
|
||||
// Handle updates to the master playlist by copying it to webroot
|
||||
if relativePath == path.Join(config.Config.GetPrivateHLSSavePath(), "stream.m3u8") {
|
||||
utils.Copy(event.Path, path.Join(config.Config.GetPublicHLSSavePath(), "stream.m3u8"))
|
||||
if relativePath == path.Join(config.PrivateHLSStoragePath, "stream.m3u8") {
|
||||
utils.Copy(event.Path, path.Join(config.PublicHLSStoragePath, "stream.m3u8"))
|
||||
|
||||
} else if filepath.Ext(event.Path) == ".m3u8" {
|
||||
// Handle updates to playlists, but not the master playlist
|
||||
@@ -82,7 +80,7 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
||||
|
||||
newObjectPathChannel := make(chan string, 1)
|
||||
go func() {
|
||||
newObjectPath, err := storage.Save(path.Join(config.Config.GetPrivateHLSSavePath(), segment.RelativeUploadPath), 0)
|
||||
newObjectPath, err := storage.Save(path.Join(config.PrivateHLSStoragePath, segment.RelativeUploadPath), 0)
|
||||
if err != nil {
|
||||
log.Errorln("failed to save the file to the chunk storage.", err)
|
||||
}
|
||||
@@ -155,5 +153,5 @@ func updateVariantPlaylist(fullPath string) error {
|
||||
playlistString := string(playlistBytes)
|
||||
playlistString = _storage.GenerateRemotePlaylist(playlistString, variant)
|
||||
|
||||
return WritePlaylist(playlistString, path.Join(config.Config.GetPublicHLSSavePath(), relativePath))
|
||||
return WritePlaylist(playlistString, path.Join(config.PublicHLSStoragePath, relativePath))
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ func SetStreamAsConnected() {
|
||||
_stats.LastConnectTime = utils.NullTime{time.Now(), true}
|
||||
_stats.LastDisconnectTime = utils.NullTime{time.Now(), false}
|
||||
|
||||
chunkPath := config.Config.GetPublicHLSSavePath()
|
||||
chunkPath := config.PublicHLSStoragePath
|
||||
if usingExternalStorage {
|
||||
chunkPath = config.Config.GetPrivateHLSSavePath()
|
||||
chunkPath = config.PrivateHLSStoragePath
|
||||
}
|
||||
|
||||
if _yp != nil {
|
||||
|
||||
@@ -28,7 +28,7 @@ type S3Storage struct {
|
||||
s3Bucket string
|
||||
s3AccessKey string
|
||||
s3Secret string
|
||||
s3ACL string
|
||||
s3ACL string
|
||||
}
|
||||
|
||||
//Setup sets up the s3 storage for saving the video to s3
|
||||
@@ -94,7 +94,7 @@ func (s *S3Storage) GenerateRemotePlaylist(playlist string, variant models.Varia
|
||||
if fullRemotePath == nil {
|
||||
line = ""
|
||||
} else if s.s3ServingEndpoint != "" {
|
||||
line = fmt.Sprintf("%s/%s/%s", s.s3ServingEndpoint, config.Config.GetPrivateHLSSavePath(), fullRemotePath.RelativeUploadPath)
|
||||
line = fmt.Sprintf("%s/%s/%s", s.s3ServingEndpoint, config.PrivateHLSStoragePath, fullRemotePath.RelativeUploadPath)
|
||||
} else {
|
||||
line = fullRemotePath.RemoteID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user