summaryrefslogtreecommitdiff
path: root/pkg/media
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/media')
-rw-r--r--pkg/media/library.go6
-rw-r--r--pkg/media/playlist.go4
-rw-r--r--pkg/media/video.go2
3 files changed, 12 insertions, 0 deletions
diff --git a/pkg/media/library.go b/pkg/media/library.go
index 337907d..c0d79eb 100644
--- a/pkg/media/library.go
+++ b/pkg/media/library.go
@@ -9,11 +9,13 @@ import (
"sync"
)
+// Library manages importing and retrieving video data.
type Library struct {
mu sync.RWMutex
Videos map[string]*Video
}
+// NewLibrary returns new instance of Library.
func NewLibrary() *Library {
lib := &Library{
Videos: make(map[string]*Video),
@@ -21,6 +23,7 @@ func NewLibrary() *Library {
return lib
}
+// Import adds all valid videos from a given path.
func (lib *Library) Import(path string) error {
files, err := ioutil.ReadDir(path)
if err != nil {
@@ -36,6 +39,7 @@ func (lib *Library) Import(path string) error {
return nil
}
+// Add adds a single video from a given file path.
func (lib *Library) Add(path string) error {
v, err := ParseVideo(path)
if err != nil {
@@ -48,6 +52,7 @@ func (lib *Library) Add(path string) error {
return nil
}
+// Remove removes a single video from a given file path.
func (lib *Library) Remove(path string) {
name := filepath.Base(path)
// ID is name without extension
@@ -65,6 +70,7 @@ func (lib *Library) Remove(path string) {
}
}
+// Playlist returns a sorted Playlist of all videos.
func (lib *Library) Playlist() Playlist {
lib.mu.RLock()
defer lib.mu.RUnlock()
diff --git a/pkg/media/playlist.go b/pkg/media/playlist.go
index 86dcb76..cf8edcf 100644
--- a/pkg/media/playlist.go
+++ b/pkg/media/playlist.go
@@ -1,15 +1,19 @@
package media
+// Playlist holds an array of videos capable of sorting by Timestamp.
type Playlist []*Video
+// Len returns length of array (for sorting).
func (p Playlist) Len() int {
return len(p)
}
+// Swap swaps two values in array by index (for sorting).
func (p Playlist) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
+// Less returns true if p[i] Timestamp is after p[j] (for sorting).
func (p Playlist) Less(i, j int) bool {
return p[i].Timestamp.After(p[j].Timestamp)
}
diff --git a/pkg/media/video.go b/pkg/media/video.go
index 2499433..90ec595 100644
--- a/pkg/media/video.go
+++ b/pkg/media/video.go
@@ -8,6 +8,7 @@ import (
"github.com/dhowden/tag"
)
+// Video represents metadata for a single video.
type Video struct {
ID string
Title string
@@ -20,6 +21,7 @@ type Video struct {
Timestamp time.Time
}
+// ParseVideo parses a video file's metadata and returns a Video.
func ParseVideo(path string) (*Video, error) {
f, err := os.Open(path)
if err != nil {