2022-08-31 19:56:06 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-09-01 15:16:56 -04:00
|
|
|
"log"
|
|
|
|
"path/filepath"
|
2022-09-01 00:17:29 -04:00
|
|
|
"time"
|
|
|
|
|
2022-08-31 19:56:06 -04:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"git.metaunix.net/BitGoblin/adept/config"
|
|
|
|
"git.metaunix.net/BitGoblin/adept/transcoder"
|
2022-09-01 15:16:56 -04:00
|
|
|
"git.metaunix.net/BitGoblin/adept/util"
|
2022-08-31 19:56:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
config.LoadConfig()
|
|
|
|
|
2022-08-31 22:41:05 -04:00
|
|
|
r := transcoder.NewRepository(viper.GetString("transcoder.repository"))
|
|
|
|
|
2022-09-01 00:17:29 -04:00
|
|
|
// main program loop - runs infinitely until externally terminated
|
|
|
|
for {
|
|
|
|
ingestFiles := r.SearchIngest()
|
|
|
|
|
2022-09-01 15:16:56 -04:00
|
|
|
if len(ingestFiles) < 1 {
|
|
|
|
log.Println("There were no files found in ingest to transcode; skipping run.")
|
|
|
|
} else {
|
|
|
|
for _, i := range ingestFiles {
|
|
|
|
// check if the file is open in another program (e.g. still being written to)
|
|
|
|
if util.IsFileLocked(filepath.Join(viper.GetString("transcoder.repository"), "ingest", i.Name())) {
|
|
|
|
log.Printf("%s appears to be open in another program; skipping it for this run.", i.Name())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// archive file
|
|
|
|
r.ArchiveFile(i.Name())
|
|
|
|
// transcode file
|
|
|
|
transcoder.Transcode(i.Name())
|
|
|
|
// clean up source file
|
|
|
|
r.CleanupFile(i.Name())
|
|
|
|
}
|
2022-09-01 00:17:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// sleep for X minutes - specified in the adept.toml config file
|
|
|
|
interval := viper.GetInt("transcoder.interval")
|
|
|
|
time.Sleep(time.Duration(interval) * time.Minute)
|
2022-08-31 22:41:05 -04:00
|
|
|
}
|
2022-08-31 19:56:06 -04:00
|
|
|
}
|