HUGE refactor. working towards web UI
This commit is contained in:
parent
dd54e8cc49
commit
1f94eecca9
29 changed files with 1669 additions and 162 deletions
|
|
@ -1,11 +1,14 @@
|
|||
package scanner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
|
|
@ -14,19 +17,19 @@ import (
|
|||
|
||||
type (
|
||||
Category struct {
|
||||
Name string `toml:"name"`
|
||||
Type string `toml:"type" comment:"Valid types: gaming, other (default: other)"`
|
||||
Url string `toml:"url"`
|
||||
Name string `toml:"name" json:"name"`
|
||||
Type string `toml:"type" json:"type" comment:"Valid types: gaming, other (default: other)"`
|
||||
Url string `toml:"url" json:"url"`
|
||||
}
|
||||
|
||||
Metadata struct {
|
||||
Title string `toml:"title"`
|
||||
Part int `toml:"part"`
|
||||
Date string `toml:"date"`
|
||||
Tags []string `toml:"tags"`
|
||||
FootageDir string `toml:"footage_dir"`
|
||||
Uploaded bool `toml:"uploaded"`
|
||||
Category *Category `toml:"category" comment:"(Optional) Category details, for additional credits."`
|
||||
Title string `toml:"title" json:"title"`
|
||||
Part int `toml:"part" json:"part"`
|
||||
Date toml.LocalDate `toml:"date" json:"date"`
|
||||
Tags []string `toml:"tags" json:"tags"`
|
||||
FootageDir string `toml:"footage_dir" json:"footage_dir"`
|
||||
Uploaded bool `toml:"uploaded" json:"uploaded"`
|
||||
Category *Category `toml:"category" json:"category" comment:"(Optional) Category details, for additional credits."`
|
||||
}
|
||||
|
||||
FFprobeFormat struct {
|
||||
|
|
@ -107,25 +110,36 @@ func ReadMetadata(directory string) (*Metadata, error) {
|
|||
}
|
||||
|
||||
func WriteMetadata(directory string, metadata *Metadata) (error) {
|
||||
file, err := os.OpenFile(
|
||||
path.Join(directory, METADATA_FILENAME),
|
||||
os.O_CREATE | os.O_RDWR, 0644,
|
||||
)
|
||||
data, err := toml.Marshal(metadata)
|
||||
if err != nil { return err }
|
||||
|
||||
err = toml.NewEncoder(file).Encode(metadata)
|
||||
err = os.WriteFile(path.Join(directory, METADATA_FILENAME), data, 0644)
|
||||
return err
|
||||
}
|
||||
|
||||
func DefaultMetadata() *Metadata {
|
||||
return &Metadata{
|
||||
Title: "Untitled Stream",
|
||||
Date: time.Now().Format("2006-01-02"),
|
||||
Part: 0,
|
||||
Category: &Category{
|
||||
Name: "Something",
|
||||
Type: "",
|
||||
Url: "",
|
||||
Date: toml.LocalDate{
|
||||
Year: time.Now().Year(),
|
||||
Month: int(time.Now().Month()),
|
||||
Day: time.Now().Day(),
|
||||
},
|
||||
Part: 0,
|
||||
Category: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func BuildTemplate(metadata *Metadata, tmpl *template.Template) (string, error) {
|
||||
out := &bytes.Buffer{}
|
||||
err := tmpl.Execute(out, metadata)
|
||||
return strings.TrimSpace(out.String()), err
|
||||
}
|
||||
|
||||
func FileSizeString(size int64) string {
|
||||
denomination := "B"
|
||||
if size > 1000 { size /= 1000; denomination = "KB" }
|
||||
if size > 1000 { size /= 1000; denomination = "MB" }
|
||||
if size > 1000 { size /= 1000; denomination = "GB" }
|
||||
if size > 1000 { size /= 1000; denomination = "TB" }
|
||||
return fmt.Sprintf("%d%s", size, denomination)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue