Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
076947ebf9 | |||
611d0dba9a | |||
674327e0cf | |||
602ddb1a00 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -16,7 +16,7 @@
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
35
adept.go
35
adept.go
@ -1,15 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"git.metaunix.net/BitGoblin/adept/config"
|
||||
"git.metaunix.net/BitGoblin/adept/transcoder"
|
||||
"git.metaunix.net/BitGoblin/adept/util"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -25,31 +20,7 @@ func main() {
|
||||
// initialize the video repository
|
||||
r := transcoder.NewRepository(viper.GetString("transcoder.repository"))
|
||||
|
||||
// main program loop - runs infinitely until externally terminated
|
||||
for {
|
||||
ingestFiles := r.SearchIngest()
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
// sleep for X minutes - specified in the adept.toml config file
|
||||
interval := viper.GetInt("transcoder.interval")
|
||||
time.Sleep(time.Duration(interval) * time.Minute)
|
||||
}
|
||||
// create transcoder object and start the main loop
|
||||
t := transcoder.NewTranscoder(*r)
|
||||
t.Start()
|
||||
}
|
||||
|
15
build/etc/adept/adept.toml
Normal file
15
build/etc/adept/adept.toml
Normal file
@ -0,0 +1,15 @@
|
||||
log_to_file = true
|
||||
log_file = '~/adept/adept.log'
|
||||
log_level = 'info'
|
||||
|
||||
[transcoder]
|
||||
repository = '~/adept'
|
||||
interval = 15
|
||||
video_format = 'mov'
|
||||
video_codec = 'dnxhd'
|
||||
video_profile = 'dnxhr_hq'
|
||||
video_resolution = '1920x1080'
|
||||
video_framerate = 60
|
||||
video_color = 'yuv422p'
|
||||
audio_codec = 'pcm_s16le'
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@ -20,10 +21,12 @@ func InitLogging() *os.File {
|
||||
log.Fatalf("Error opening log file: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// set logging to file handle
|
||||
log.SetOutput(fileHandle)
|
||||
}
|
||||
|
||||
// create a MultiWriter instance so we can write to both console AND file
|
||||
mw := io.MultiWriter(os.Stdout, fileHandle)
|
||||
// set our multiwriter object as the output for logging
|
||||
log.SetOutput(mw)
|
||||
|
||||
return fileHandle
|
||||
}
|
||||
|
@ -9,30 +9,40 @@ import (
|
||||
|
||||
type Repository struct {
|
||||
basePath string
|
||||
ingestPath string
|
||||
archivePath string
|
||||
outputPath string
|
||||
}
|
||||
|
||||
func NewRepository(path string) *Repository {
|
||||
// make sure repository base directory exists
|
||||
create_repo_dir(path)
|
||||
|
||||
// make sure the ingest, archive, and output directories exist
|
||||
subDirs := []string{"ingest", "archive", "output"}
|
||||
for _, d := range subDirs {
|
||||
subPath := filepath.Join(path, d)
|
||||
create_repo_dir(subPath)
|
||||
}
|
||||
|
||||
r := new(Repository)
|
||||
r.basePath = path
|
||||
r.ingestPath = filepath.Join(path, "ingest")
|
||||
r.archivePath = filepath.Join(path, "archive")
|
||||
r.outputPath = filepath.Join(path, "output")
|
||||
|
||||
// make sure repository base directory exists
|
||||
create_repo_dir(r.basePath)
|
||||
// make sure the folder structure is setup
|
||||
create_repo_dir(r.ingestPath)
|
||||
create_repo_dir(r.archivePath)
|
||||
create_repo_dir(r.archivePath)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Repository) SearchIngest() []os.FileInfo {
|
||||
ingestPath := filepath.Join(r.basePath, "ingest")
|
||||
// Repository getters
|
||||
func (r *Repository) GetIngestPath() string {
|
||||
return r.ingestPath
|
||||
}
|
||||
func (r *Repository) GetOutputPath() string {
|
||||
return r.outputPath
|
||||
}
|
||||
|
||||
func (r *Repository) SearchIngest() []os.FileInfo {
|
||||
log.Printf("Searching ingest directory for files to transcode...")
|
||||
|
||||
ingestDir, err := os.Open(ingestPath)
|
||||
ingestDir, err := os.Open(r.ingestPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening ingest directory: %s", err)
|
||||
os.Exit(1)
|
||||
@ -48,13 +58,13 @@ func (r *Repository) SearchIngest() []os.FileInfo {
|
||||
|
||||
func (r *Repository) ArchiveFile(inFile string) {
|
||||
// create ingest and archive paths
|
||||
ingestPath := filepath.Join(r.basePath, "ingest", inFile)
|
||||
archivePath := filepath.Join(r.basePath, "archive", inFile)
|
||||
ingestFilePath := filepath.Join(r.ingestPath, inFile)
|
||||
archiveFilePath := filepath.Join(r.archivePath, inFile)
|
||||
|
||||
log.Printf("Copying %s to the archive.", ingestPath)
|
||||
log.Printf("Copying %s to the archive.", ingestFilePath)
|
||||
|
||||
// open ingest file
|
||||
source, err := os.Open(ingestPath)
|
||||
source, err := os.Open(ingestFilePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening file in ingest: %s.", err)
|
||||
os.Exit(1)
|
||||
@ -62,7 +72,7 @@ func (r *Repository) ArchiveFile(inFile string) {
|
||||
defer source.Close()
|
||||
|
||||
// attempt to create destination file
|
||||
destination, err := os.Create(archivePath)
|
||||
destination, err := os.Create(archiveFilePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening archive file: %s.", err)
|
||||
os.Exit(1)
|
||||
@ -80,10 +90,10 @@ func (r *Repository) ArchiveFile(inFile string) {
|
||||
|
||||
func (r *Repository) CleanupFile(inFile string) {
|
||||
// create ingest path
|
||||
ingestPath := filepath.Join(r.basePath, "ingest", inFile)
|
||||
ingestFilePath := filepath.Join(r.ingestPath, inFile)
|
||||
|
||||
// remove the file
|
||||
os.Remove(ingestPath)
|
||||
os.Remove(ingestFilePath)
|
||||
}
|
||||
|
||||
func create_repo_dir(path string) {
|
||||
|
@ -6,14 +6,61 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"git.metaunix.net/BitGoblin/adept/util"
|
||||
)
|
||||
|
||||
func Transcode(inFile string) {
|
||||
type Transcoder struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
// Transcoder object constructor
|
||||
func NewTranscoder(r Repository) *Transcoder {
|
||||
t := new(Transcoder)
|
||||
t.repo = r
|
||||
return t
|
||||
}
|
||||
|
||||
// Start the main transcoder loop
|
||||
func (t *Transcoder) Start() {
|
||||
// main program loop - runs infinitely until externally terminated
|
||||
for {
|
||||
ingestFiles := t.repo.SearchIngest()
|
||||
|
||||
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(t.repo.GetIngestPath(), i.Name())) {
|
||||
log.Printf("%s appears to be open in another program; skipping it for this run.", i.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
// archive file
|
||||
t.repo.ArchiveFile(i.Name())
|
||||
// transcode file
|
||||
t.Transcode(i.Name())
|
||||
// clean up source file
|
||||
t.repo.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)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transcoder) Transcode(inFile string) {
|
||||
// create ingest and archive paths
|
||||
ingestPath := filepath.Join(viper.GetString("transcoder.repository"), "ingest", inFile)
|
||||
outputPath := filepath.Join(viper.GetString("transcoder.repository"), "output", inFile)
|
||||
ingestPath := filepath.Join(t.repo.GetIngestPath(), inFile)
|
||||
outputName := strings.Join([]string{util.FilenameWithoutExtension(inFile), viper.GetString("transcoder.video_format")}, ".")
|
||||
outputPath := filepath.Join(t.repo.GetOutputPath(), outputName)
|
||||
|
||||
log.Printf("Transcoding video file %s.", ingestPath)
|
||||
|
||||
|
Reference in New Issue
Block a user