Compare commits
No commits in common. "main" and "v1.2.0" have entirely different histories.
3 changed files with 35 additions and 85 deletions
16
README.md
16
README.md
|
|
@ -14,13 +14,8 @@ 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 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).
|
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).
|
||||||
**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:
|
||||||
|
|
@ -68,11 +63,10 @@ url = 'https://example.org'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Templates
|
## Templates
|
||||||
There are three template files, `title.txt`, `description.txt`, and `tags.txt`,
|
Template files can be created at `templates/title.txt`,
|
||||||
which can be created in `/path/to/vodular/templates`. These templates can be
|
`template/description.txt`, and `templates/tags.txt` respectively. These
|
||||||
created and tweaked to customise your VOD metadata on upload. They are enhanced
|
files can use Go's [text template format](https://pkg.go.dev/text/template) to
|
||||||
with Go's [template format](https://pkg.go.dev/text/template) to inject
|
customise VOD metadata on upload.
|
||||||
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.
|
||||||
|
|
|
||||||
67
main.go
67
main.go
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -26,9 +25,7 @@ import (
|
||||||
//go:embed res/help.txt
|
//go:embed res/help.txt
|
||||||
var helpText string
|
var helpText string
|
||||||
|
|
||||||
const SEGMENT_EXTENSION = "mkv"
|
const segmentExtension = "mkv"
|
||||||
const MAX_TITLE_LEN = 100
|
|
||||||
const MAX_DESCRIPTION_LEN = 5000
|
|
||||||
|
|
||||||
func showHelp() {
|
func showHelp() {
|
||||||
fmt.Println(helpText)
|
fmt.Println(helpText)
|
||||||
|
|
@ -196,7 +193,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// scan for VOD segments
|
// scan for VOD segments
|
||||||
vodFiles, err := scanner.ScanSegments(metadata.FootageDir, SEGMENT_EXTENSION)
|
vodFiles, err := scanner.ScanSegments(metadata.FootageDir, segmentExtension)
|
||||||
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)
|
||||||
|
|
@ -204,7 +201,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)",
|
||||||
SEGMENT_EXTENSION,
|
segmentExtension,
|
||||||
)
|
)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
@ -223,35 +220,21 @@ 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)
|
||||||
}
|
}
|
||||||
title, err := yt.BuildTemplate(video, templates.Title)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to build video title: %v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
description, err := yt.BuildTemplate(video, templates.Description)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to build video description: %v", err)
|
|
||||||
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 {
|
if verbose {
|
||||||
enc := json.NewEncoder(os.Stdout)
|
enc := json.NewEncoder(os.Stdout)
|
||||||
fmt.Printf("\nVideo template: ")
|
fmt.Printf("\nVideo template: ")
|
||||||
enc.Encode(video)
|
enc.Encode(video)
|
||||||
|
|
||||||
|
title, err := yt.BuildTemplate(video, templates.Title)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to build video title: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
description, err := yt.BuildTemplate(video, templates.Description)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to build video description: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"\n================================\n\n" +
|
"\n================================\n\n" +
|
||||||
"< TITLE >\n%s\n\n" +
|
"< TITLE >\n%s\n\n" +
|
||||||
|
|
@ -264,21 +247,18 @@ func main() {
|
||||||
// concatenate VOD segments into full VOD
|
// concatenate VOD segments into full VOD
|
||||||
fullVodExists := func () bool {
|
fullVodExists := func () bool {
|
||||||
// check if full VOD already exists with expected duration
|
// check if full VOD already exists with expected duration
|
||||||
fullVodProbe, err := scanner.ProbeSegment(video.Filename)
|
if fullVodProbe, err := scanner.ProbeSegment(video.Filename); err != nil {
|
||||||
if err != nil { return false }
|
var totalLength float64 = 0
|
||||||
video.SizeBytes = fullVodProbe.Format.Size
|
for _, filename := range vodFiles {
|
||||||
var totalLength float64 = 0
|
probe, err := scanner.ProbeSegment(filename)
|
||||||
|
if err != nil { continue }
|
||||||
for _, filename := range vodFiles {
|
totalLength += probe.Format.Duration
|
||||||
probe, err := scanner.ProbeSegment(path.Join(metadata.FootageDir, filename))
|
}
|
||||||
if err != nil { continue }
|
return fullVodProbe.Format.Duration == totalLength
|
||||||
totalLength += probe.Format.Duration
|
|
||||||
}
|
}
|
||||||
return math.Abs(fullVodProbe.Format.Duration - totalLength) < float64(0.1)
|
return false
|
||||||
}()
|
}()
|
||||||
if fullVodExists {
|
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)
|
||||||
|
|
@ -333,7 +313,6 @@ 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 {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -29,13 +28,13 @@ type (
|
||||||
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
||||||
}
|
}
|
||||||
|
|
||||||
FFprobeFormat struct {
|
ffprobeFormat struct {
|
||||||
Duration float64 `json:"duration"`
|
Duration float64 `json:"duration"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
FFprobeOutput struct {
|
ffprobeOutput struct {
|
||||||
Format FFprobeFormat `json:"format"`
|
Format ffprobeFormat `json:"format"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -51,7 +50,6 @@ 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())
|
||||||
|
|
@ -60,36 +58,15 @@ func ScanSegments(directory string, extension string) ([]string, error) {
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProbeSegment(filename string) (*FFprobeOutput, error) {
|
func ProbeSegment(filename string) (*ffprobeOutput, error) {
|
||||||
out, err := ffmpeg_go.Probe(filename)
|
out, err := ffmpeg_go.Probe(filename)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
type (
|
probe := ffprobeOutput{}
|
||||||
RawFFprobeFormat struct {
|
err = json.Unmarshal([]byte(out), probe)
|
||||||
// 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 }
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
duration, err := strconv.ParseFloat(probe.Format.Duration, 64)
|
return &probe, nil
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue