diff --git a/adept.go b/adept.go index 9403105..fa44153 100644 --- a/adept.go +++ b/adept.go @@ -1,6 +1,8 @@ package main import ( + "time" + "github.com/spf13/viper" "git.metaunix.net/BitGoblin/adept/config" @@ -12,13 +14,21 @@ func main() { r := transcoder.NewRepository(viper.GetString("transcoder.repository")) - ingestFiles := r.SearchIngest() - for _, i := range ingestFiles { - // archive file - r.ArchiveFile(i.Name()) - // transcode file - transcoder.Transcode(i.Name()) - // clean up source file - r.CleanupFile(i.Name()) + // main program loop - runs infinitely until externally terminated + for { + ingestFiles := r.SearchIngest() + + for _, i := range ingestFiles { + // archive file + r.ArchiveFile(i.Name()) + // transcode file + transcoder.Transcode(i.Name()) + // clean up source file + r.CleanupFile(i.Name()) + } + + // sleep for X minutes - specified in the adept.toml config file + interval := viper.GetInt("transcoder.interval") + time.Sleep(time.Duration(interval) * time.Minute) } } diff --git a/transcoder/repository.go b/transcoder/repository.go index aefe0f4..aca6fb8 100644 --- a/transcoder/repository.go +++ b/transcoder/repository.go @@ -30,6 +30,8 @@ func NewRepository(path string) *Repository { func (r *Repository) SearchIngest() []os.FileInfo { ingestPath := filepath.Join(r.basePath, "ingest") + log.Printf("Searching ingest directory for files to transcode...") + ingestDir, err := os.Open(ingestPath) if err != nil { log.Fatalf("Error opening ingest directory: %s", err)