Compare commits

...

8 commits
v1.0.0 ... main

Author SHA1 Message Date
dd54e8cc49
add warnings for exceeding metadata character length
All checks were successful
/ build-linux-amd64 (push) Successful in 2m47s
2026-02-01 17:08:16 +00:00
9f32aedc3b
exclude dot-prefixed files from footage scan
All checks were successful
/ build-linux-amd64 (push) Successful in 3m18s
2026-01-31 18:10:39 +00:00
c52290392d
update README 2026-01-31 04:19:20 +00:00
51a1de845f
fix crummy ffprobe json output handling
All checks were successful
/ build-linux-amd64 (push) Successful in 1m35s
2026-01-31 04:04:32 +00:00
f4381f7cdc
real girls forget to pass pointers at 3am
All checks were successful
/ build-linux-amd64 (push) Successful in 1m10s
2026-01-31 03:22:17 +00:00
1d03bdebd0
move templates to user config dir
All checks were successful
/ build-linux-amd64 (push) Successful in 1m6s
2026-01-31 03:14:33 +00:00
34065bd06f
fix forgejo actions
All checks were successful
/ build-linux-amd64 (push) Successful in 1m3s
2026-01-31 03:05:45 +00:00
aa28ffedc8
check if fullvod exists; store config in UserConfigDir
All checks were successful
/ build-linux-amd64 (push) Successful in 1m8s
2026-01-31 02:54:09 +00:00
6 changed files with 136 additions and 40 deletions

View file

@ -1,7 +1,7 @@
on: on:
push: push:
branches: tags:
- main - 'v*'
jobs: jobs:
build-linux-amd64: build-linux-amd64:
@ -24,3 +24,5 @@ jobs:
with: with:
direction: upload direction: upload
token: ${{ secrets.RELEASE_TOKEN }} token: ${{ secrets.RELEASE_TOKEN }}
tag: ${{ env.GITHUB_REF_NAME }}

View file

@ -14,8 +14,13 @@ I built this to greatly simplify the process of getting my full-quality livestre
$ vodular $ vodular
New config file created (config.toml). Please edit this file before running again! New config file created (config.toml). Please edit this file before running again!
``` ```
The directory which holds your configuration file and templates varies,
depending on platform:
- **Linux:** `~/.config/vodular/templates`
- **macOS:** `~/Library/Application Support/vodular/templates`
- **Windows:** `%AppData%/vodular/templates`
2. Edit configuration file as necessary (You will need to create a [YouTube Data API v3](https://developers.google.com/youtube/v3) service and provide its credentials here). 2. Edit your configuration file as necessary (You will need to create a [YouTube Data API v3](https://developers.google.com/youtube/v3) service and provide its credentials here).
**IMPORTANT:** `config.toml` contains very sensitive credentials. Do not share this file with anyone. **IMPORTANT:** `config.toml` contains very sensitive credentials. Do not share this file with anyone.
3. Initialise a VOD directory: 3. Initialise a VOD directory:
@ -63,10 +68,11 @@ url = 'https://example.org'
``` ```
## Templates ## Templates
Template files can be created at `templates/title.txt`, There are three template files, `title.txt`, `description.txt`, and `tags.txt`,
`template/description.txt`, and `templates/tags.txt` respectively. These which can be created in `/path/to/vodular/templates`. These templates can be
files can use Go's [text template format](https://pkg.go.dev/text/template) to created and tweaked to customise your VOD metadata on upload. They are enhanced
customise VOD metadata on upload. with Go's [template format](https://pkg.go.dev/text/template) to inject
information provided in `metadata.toml`, and other neat functionality!
You can use the following data in templates: You can use the following data in templates:
- **`.Title`:** The title of the stream. - **`.Title`:** The title of the stream.

View file

@ -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)

78
main.go
View file

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"math"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -25,22 +26,34 @@ import (
//go:embed res/help.txt //go:embed res/help.txt
var helpText string var helpText string
const segmentExtension = "mkv" const SEGMENT_EXTENSION = "mkv"
const MAX_TITLE_LEN = 100
const MAX_DESCRIPTION_LEN = 5000
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 +70,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 +88,6 @@ func main() {
fallthrough fallthrough
case "--help": case "--help":
showHelp() showHelp()
os.Exit(0)
case "-v": case "-v":
fallthrough fallthrough
@ -143,7 +154,7 @@ func main() {
} }
// good to have early on // good to have early on
templates, err := yt.FetchTemplates() templates, err := yt.FetchTemplates(path.Join(userConfigDir, "vodular", "templates"))
if err != nil { if err != nil {
log.Fatalf("Failed to fetch templates: %v", err) log.Fatalf("Failed to fetch templates: %v", err)
os.Exit(1) os.Exit(1)
@ -185,7 +196,7 @@ func main() {
} }
// scan for VOD segments // scan for VOD segments
vodFiles, err := scanner.ScanSegments(metadata.FootageDir, segmentExtension) vodFiles, err := scanner.ScanSegments(metadata.FootageDir, SEGMENT_EXTENSION)
if err != nil { if err != nil {
log.Fatalf("Failed to fetch VOD filenames: %v", err) log.Fatalf("Failed to fetch VOD filenames: %v", err)
os.Exit(1) os.Exit(1)
@ -193,7 +204,7 @@ func main() {
if len(vodFiles) == 0 { if len(vodFiles) == 0 {
log.Fatalf( log.Fatalf(
"Directory contained no VOD files (expecting .%s)", "Directory contained no VOD files (expecting .%s)",
segmentExtension, SEGMENT_EXTENSION,
) )
os.Exit(1) os.Exit(1)
} }
@ -212,11 +223,6 @@ func main() {
log.Fatalf("Failed to build video template: %v", err) log.Fatalf("Failed to build video template: %v", err)
os.Exit(1) os.Exit(1)
} }
if verbose {
enc := json.NewEncoder(os.Stdout)
fmt.Printf("\nVideo template: ")
enc.Encode(video)
title, err := yt.BuildTemplate(video, templates.Title) title, err := yt.BuildTemplate(video, templates.Title)
if err != nil { if err != nil {
log.Fatalf("Failed to build video title: %v", err) log.Fatalf("Failed to build video title: %v", err)
@ -227,21 +233,58 @@ func main() {
log.Fatalf("Failed to build video description: %v", err) log.Fatalf("Failed to build video description: %v", err)
os.Exit(1) os.Exit(1)
} }
if len(title) > 100 {
log.Fatalf(
"Video title length exceeds %d characters (%d). YouTube may reject this!",
MAX_TITLE_LEN,
len(video.Title),
)
}
if len(description) > 5000 {
log.Fatalf(
"Video description length exceeds %d characters (%d). YouTube may reject this!",
MAX_DESCRIPTION_LEN,
len(description),
)
}
if verbose {
enc := json.NewEncoder(os.Stdout)
fmt.Printf("\nVideo template: ")
enc.Encode(video)
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
fullVodProbe, err := scanner.ProbeSegment(video.Filename)
if err != nil { return false }
video.SizeBytes = fullVodProbe.Format.Size
var totalLength float64 = 0
for _, filename := range vodFiles {
probe, err := scanner.ProbeSegment(path.Join(metadata.FootageDir, filename))
if err != nil { continue }
totalLength += probe.Format.Duration
}
return math.Abs(fullVodProbe.Format.Duration - totalLength) < float64(0.1)
}()
if fullVodExists {
log.Print("Full VOD appears to already exist- uploading this file...")
} else {
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()
@ -290,6 +333,7 @@ func main() {
log.Print("Video uploaded successfully!") log.Print("Video uploaded successfully!")
// update metadata to reflect VOD is uploaded // update metadata to reflect VOD is uploaded
// TODO: rather than a boolean flag, link to actual video
metadata.Uploaded = true metadata.Uploaded = true
err = scanner.WriteMetadata(directory, metadata) err = scanner.WriteMetadata(directory, metadata)
if err != nil { if err != nil {

View file

@ -1,12 +1,15 @@
package scanner package scanner
import ( import (
"encoding/json"
"os" "os"
"path" "path"
"strconv"
"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 +28,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"
@ -39,6 +51,7 @@ func ScanSegments(directory string, extension string) ([]string, error) {
for _, item := range entries { for _, item := range entries {
if item.IsDir() { continue } if item.IsDir() { continue }
if strings.HasPrefix(item.Name(), ".") { continue }
if !strings.HasSuffix(item.Name(), "." + extension) { continue } if !strings.HasSuffix(item.Name(), "." + extension) { continue }
if strings.HasSuffix(item.Name(), "-fullvod." + extension) { continue } if strings.HasSuffix(item.Name(), "-fullvod." + extension) { continue }
files = append(files, item.Name()) files = append(files, item.Name())
@ -47,6 +60,38 @@ 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 }
type (
RawFFprobeFormat struct {
// these being strings upsets me immensely
Duration string `json:"duration"`
Size string `json:"size"`
}
RawFFprobeOutput struct {
Format RawFFprobeFormat `json:"format"`
}
)
probe := RawFFprobeOutput{}
err = json.Unmarshal([]byte(out), &probe)
if err != nil { return nil, err }
duration, err := strconv.ParseFloat(probe.Format.Duration, 64)
if err != nil { return nil, err }
size, err := strconv.ParseInt(probe.Format.Size, 10, 0)
if err != nil { return nil, err }
return &FFprobeOutput{
Format: FFprobeFormat{
Duration: duration,
Size: size,
},
}, 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(

View file

@ -113,11 +113,6 @@ var videoYtCategory = map[CategoryType]string {
CATEGORY_ENTERTAINMENT: YT_CATEGORY_ENTERTAINMENT, CATEGORY_ENTERTAINMENT: YT_CATEGORY_ENTERTAINMENT,
} }
var templateDir = "templates"
var tagsPath = path.Join(templateDir, "tags.txt")
var titlePath = path.Join(templateDir, "title.txt")
var descriptionPath = path.Join(templateDir, "description.txt")
const defaultTitleTemplate = const defaultTitleTemplate =
"{{.Title}} - {{FormatTime .Date \"02 Jan 2006\"}}" "{{.Title}} - {{FormatTime .Date \"02 Jan 2006\"}}"
const defaultDescriptionTemplate = const defaultDescriptionTemplate =
@ -135,9 +130,13 @@ var templateFuncs = template.FuncMap{
}, },
} }
func FetchTemplates() (*Template, error) { func FetchTemplates(templateDir string) (*Template, error) {
tmpl := Template{} tmpl := Template{}
var tagsPath = path.Join(templateDir, "tags.txt")
var titlePath = path.Join(templateDir, "title.txt")
var descriptionPath = path.Join(templateDir, "description.txt")
// tags // tags
if tagsFile, err := os.ReadFile(tagsPath); err == nil { if tagsFile, err := os.ReadFile(tagsPath); err == nil {
tmpl.Tags = strings.Split(string(tagsFile), "\n") tmpl.Tags = strings.Split(string(tagsFile), "\n")