summaryrefslogtreecommitdiff
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/video.go30
1 files changed, 29 insertions, 1 deletions
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 {