1
+ // Package library is responsible for orchestrating actions related to
2
+ // providing a navigable representation of the audio library.
1
3
package library
2
4
3
5
import (
@@ -16,6 +18,8 @@ import (
16
18
"github.com/pkg/errors"
17
19
)
18
20
21
+ const rootAlbumTitle = "Eggplant"
22
+
19
23
type AlbumId string
20
24
21
25
func (id AlbumId ) String () string {
@@ -55,8 +59,6 @@ type Album struct {
55
59
Tracks []Track `json:"tracks,omitempty"`
56
60
}
57
61
58
- const rootAlbumTitle = "Eggplant"
59
-
60
62
type track struct {
61
63
title string
62
64
path string
@@ -66,7 +68,7 @@ type track struct {
66
68
func newTrack (title string , path string ) (track , error ) {
67
69
fileId , err := newFileId (path )
68
70
if err != nil {
69
- return track {}, errors .Wrap (err , "could not create file id" )
71
+ return track {}, errors .Wrap (err , "could not create a file id" )
70
72
}
71
73
t := track {
72
74
title : title ,
@@ -92,6 +94,8 @@ func newAlbum(title string) *album {
92
94
}
93
95
}
94
96
97
+ // Library receives scanner updates, dispatches them to appropriate stores and
98
+ // builds a navigable representation of the music collection.
95
99
type Library struct {
96
100
root * album
97
101
trackStore * store.TrackStore
@@ -100,6 +104,7 @@ type Library struct {
100
104
log logging.Logger
101
105
}
102
106
107
+ // New creates a library which receives updates from the specified channel.
103
108
func New (ch <- chan scanner.Album , thumbnailStore * store.Store , trackStore * store.TrackStore ) (* Library , error ) {
104
109
l := & Library {
105
110
log : logging .New ("library" ),
@@ -112,13 +117,15 @@ func New(ch <-chan scanner.Album, thumbnailStore *store.Store, trackStore *store
112
117
113
118
}
114
119
120
+ // Browse lists the specified album. Provide a zero-length slice to list the
121
+ // root album.
115
122
func (l * Library ) Browse (ids []AlbumId ) (Album , error ) {
116
123
l .mutex .Lock ()
117
124
defer l .mutex .Unlock ()
118
125
119
126
album , err := l .getAlbum (ids )
120
127
if err != nil {
121
- return Album {}, errors .Wrap (err , "failed to get directory " )
128
+ return Album {}, errors .Wrap (err , "failed to get an album " )
122
129
}
123
130
124
131
parents , err := l .getParents (ids )
0 commit comments