summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>2022-11-25 01:29:44 +0000
committerJames Mills <james@mills.io>2022-11-25 01:29:44 +0000
commit7a4ef5b6dfe804213d5cc1563f17deeb10e25455 (patch)
tree424ca4318f67d72e09281c9506bb7fe3c90259f4
parenta2cc622bc9028e3fabf6ca8d662c8ab4a327cdf7 (diff)
feat: Add YAML support for added / modified metadata (#37)
This change introduces the ability to read additional or modified metadata like title or description from a YAML file. Just like thumbnails are read from "filename.jpg", we now look for "filename.yml" and override the meta data that is embedded in the video file. This is my very first look at golang, so please tell me if, or rather "where" I went wrong. ;-) Co-authored-by: Heinrich Langos <gumbo2000@noreply@mills.io> Reviewed-on: https://git.mills.io/prologic/tube/pulls/37 Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
-rw-r--r--go.mod1
-rw-r--r--media/video.go30
2 files changed, 30 insertions, 1 deletions
diff --git a/go.mod b/go.mod
index 525713e..1d9352f 100644
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/pflag v1.0.5
github.com/wybiral/feeds v1.1.1
+ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
require (
diff --git a/media/video.go b/media/video.go
index 8bf1a05..cc78973 100644
--- a/media/video.go
+++ b/media/video.go
@@ -3,14 +3,16 @@ package media
import (
"fmt"
"io/ioutil"
+ "log"
"os"
"path"
"path/filepath"
"strings"
"time"
- "github.com/dhowden/tag"
"git.mills.io/prologic/tube/utils"
+ "github.com/dhowden/tag"
+ "gopkg.in/yaml.v3"
)
// Video represents metadata for a single video.
@@ -29,6 +31,26 @@ type Video struct {
Views int64
}
+func getTagsFromYml(v *Video) error {
+ ymlFileName := fmt.Sprintf("%s.yml", strings.TrimSuffix(v.Path, filepath.Ext(v.Path)))
+ if !utils.FileExists(ymlFileName) {
+ return nil
+ }
+
+ ymlFile, err := ioutil.ReadFile(ymlFileName)
+ if err != nil {
+ return err
+ }
+
+ err = yaml.Unmarshal(ymlFile, v)
+ if err != nil {
+ return err
+ }
+
+ log.Println("Got tags from yml for", v.Path)
+ return nil
+}
+
// ParseVideo parses a video file's metadata and returns a Video.
func ParseVideo(p *Path, name string) (*Video, error) {
pth := path.Join(p.Path, name)
@@ -73,6 +95,12 @@ func ParseVideo(p *Path, name string) (*Video, error) {
Path: pth,
Timestamp: timestamp,
}
+ // read yml if exists
+ err = getTagsFromYml(v)
+ if err != nil {
+ log.Println("Failed to read yml for", v.Path)
+ }
+
// Add thumbnail (if exists)
pic := m.Picture()
if pic != nil {