check if fullvod exists; store config in UserConfigDir
All checks were successful
/ build-linux-amd64 (push) Successful in 1m12s
All checks were successful
/ build-linux-amd64 (push) Successful in 1m12s
This commit is contained in:
parent
c3dc6f095e
commit
6adbd3e0f1
3 changed files with 58 additions and 13 deletions
|
|
@ -33,7 +33,7 @@ var defaultConfig = Config{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONFIG_FILENAME = "config.toml"
|
var CONFIG_FILENAME string = "config.toml"
|
||||||
|
|
||||||
func ReadConfig(filename string) (*Config, error) {
|
func ReadConfig(filename string) (*Config, error) {
|
||||||
cfgBytes, err := os.ReadFile(filename)
|
cfgBytes, err := os.ReadFile(filename)
|
||||||
|
|
|
||||||
39
main.go
39
main.go
|
|
@ -28,19 +28,29 @@ var helpText string
|
||||||
const segmentExtension = "mkv"
|
const segmentExtension = "mkv"
|
||||||
|
|
||||||
func showHelp() {
|
func showHelp() {
|
||||||
execSplits := strings.Split(os.Args[0], "/")
|
fmt.Println(helpText)
|
||||||
execName := execSplits[len(execSplits) - 1]
|
os.Exit(0)
|
||||||
fmt.Printf(helpText, execName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// config
|
// config
|
||||||
|
userConfigDir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not determine user configuration directory: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
config.CONFIG_FILENAME = path.Join(userConfigDir, "vodular", "config.toml")
|
||||||
cfg, err := config.ReadConfig(config.CONFIG_FILENAME)
|
cfg, err := config.ReadConfig(config.CONFIG_FILENAME)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to read config: %v", err)
|
log.Fatalf("Failed to read config: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
|
err = os.MkdirAll(path.Dir(config.CONFIG_FILENAME), 0750)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create config directory: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
err = config.GenerateConfig(config.CONFIG_FILENAME)
|
err = config.GenerateConfig(config.CONFIG_FILENAME)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate config: %v", err)
|
log.Fatalf("Failed to generate config: %v", err)
|
||||||
|
|
@ -57,7 +67,6 @@ func main() {
|
||||||
// arguments
|
// arguments
|
||||||
if len(os.Args) < 2 || os.Args[1] == "--help" || os.Args[1] == "-h" {
|
if len(os.Args) < 2 || os.Args[1] == "--help" || os.Args[1] == "-h" {
|
||||||
showHelp()
|
showHelp()
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var verbose bool = false
|
var verbose bool = false
|
||||||
|
|
@ -76,7 +85,6 @@ func main() {
|
||||||
fallthrough
|
fallthrough
|
||||||
case "--help":
|
case "--help":
|
||||||
showHelp()
|
showHelp()
|
||||||
os.Exit(0)
|
|
||||||
|
|
||||||
case "-v":
|
case "-v":
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -228,20 +236,35 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"\n================================\n" +
|
"\n================================\n\n" +
|
||||||
"TITLE:\n%s\n\n" +
|
"< TITLE >\n%s\n\n" +
|
||||||
"DESCRIPTION:\n%s\n" +
|
"< DESCRIPTION >\n%s\n" +
|
||||||
"\n================================\n",
|
"\n================================\n",
|
||||||
title, description,
|
title, description,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// concatenate VOD segments into full VOD
|
// concatenate VOD segments into full VOD
|
||||||
|
fullVodExists := func () bool {
|
||||||
|
// check if full VOD already exists with expected duration
|
||||||
|
if fullVodProbe, err := scanner.ProbeSegment(video.Filename); err != nil {
|
||||||
|
var totalLength float64 = 0
|
||||||
|
for _, filename := range vodFiles {
|
||||||
|
probe, err := scanner.ProbeSegment(filename)
|
||||||
|
if err != nil { continue }
|
||||||
|
totalLength += probe.Format.Duration
|
||||||
|
}
|
||||||
|
return fullVodProbe.Format.Duration == totalLength
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}()
|
||||||
|
if !fullVodExists {
|
||||||
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
|
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to concatenate VOD segments: %v", err)
|
log.Fatalf("Failed to concatenate VOD segments: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// youtube oauth flow
|
// youtube oauth flow
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package scanner
|
package scanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pelletier/go-toml/v2"
|
"github.com/pelletier/go-toml/v2"
|
||||||
|
ffmpeg_go "github.com/u2takey/ffmpeg-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
@ -25,6 +27,15 @@ type (
|
||||||
Uploaded bool `toml:"uploaded"`
|
Uploaded bool `toml:"uploaded"`
|
||||||
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ffprobeFormat struct {
|
||||||
|
Duration float64 `json:"duration"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
ffprobeOutput struct {
|
||||||
|
Format ffprobeFormat `json:"format"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const METADATA_FILENAME = "metadata.toml"
|
const METADATA_FILENAME = "metadata.toml"
|
||||||
|
|
@ -47,6 +58,17 @@ func ScanSegments(directory string, extension string) ([]string, error) {
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ProbeSegment(filename string) (*ffprobeOutput, error) {
|
||||||
|
out, err := ffmpeg_go.Probe(filename)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
|
probe := ffprobeOutput{}
|
||||||
|
err = json.Unmarshal([]byte(out), probe)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
|
return &probe, nil
|
||||||
|
}
|
||||||
|
|
||||||
func ReadMetadata(directory string) (*Metadata, error) {
|
func ReadMetadata(directory string) (*Metadata, error) {
|
||||||
metadata := &Metadata{}
|
metadata := &Metadata{}
|
||||||
file, err := os.OpenFile(
|
file, err := os.OpenFile(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue