Documentation ¶
Overview ¶
Package data provides the models and database backends of the wavepipe media server.
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type Album
- type Art
- type Artist
- type Folder
- type Session
- type Song
- type SongSlice
- type SqliteBackend
- func (s *SqliteBackend) AlbumsForArtist(ID int) ([]Album, error)
- func (s *SqliteBackend) AllAlbums() ([]Album, error)
- func (s *SqliteBackend) AllArtists() ([]Artist, error)
- func (s *SqliteBackend) AllArtistsByTitle() ([]Artist, error)
- func (s *SqliteBackend) AllFolders() ([]Folder, error)
- func (s *SqliteBackend) AllSongs() ([]Song, error)
- func (s *SqliteBackend) AllUsers() ([]User, error)
- func (s *SqliteBackend) ArtInPath(path string) ([]Art, error)
- func (s *SqliteBackend) ArtNotInPath(path string) ([]Art, error)
- func (s *SqliteBackend) Close() error
- func (s *SqliteBackend) CountAlbums() (int64, error)
- func (s *SqliteBackend) CountArt() (int64, error)
- func (s *SqliteBackend) CountArtists() (int64, error)
- func (s *SqliteBackend) CountFolders() (int64, error)
- func (s *SqliteBackend) CountSongs() (int64, error)
- func (s *SqliteBackend) DSN(path string)
- func (s *SqliteBackend) DeleteAlbum(a *Album) error
- func (s *SqliteBackend) DeleteArt(a *Art) error
- func (s *SqliteBackend) DeleteArtist(a *Artist) error
- func (s *SqliteBackend) DeleteFolder(f *Folder) error
- func (s *SqliteBackend) DeleteSession(u *Session) error
- func (s *SqliteBackend) DeleteSong(a *Song) error
- func (s *SqliteBackend) DeleteUser(u *User) error
- func (s *SqliteBackend) FoldersInPath(path string) ([]Folder, error)
- func (s *SqliteBackend) FoldersNotInPath(path string) ([]Folder, error)
- func (s *SqliteBackend) LimitAlbums(offset int, count int) ([]Album, error)
- func (s *SqliteBackend) LimitArtists(offset int, count int) ([]Artist, error)
- func (s *SqliteBackend) LimitFolders(offset int, count int) ([]Folder, error)
- func (s *SqliteBackend) LimitSongs(offset int, count int) ([]Song, error)
- func (s *SqliteBackend) LoadAlbum(a *Album) error
- func (s *SqliteBackend) LoadArt(a *Art) error
- func (s *SqliteBackend) LoadArtist(a *Artist) error
- func (s *SqliteBackend) LoadFolder(f *Folder) error
- func (s *SqliteBackend) LoadSession(u *Session) error
- func (s *SqliteBackend) LoadSong(a *Song) error
- func (s *SqliteBackend) LoadUser(u *User) error
- func (s *SqliteBackend) Open() error
- func (s *SqliteBackend) PurgeOrphanAlbums() (int, error)
- func (s *SqliteBackend) PurgeOrphanArtists() (int, error)
- func (s *SqliteBackend) RandomSongs(n int) ([]Song, error)
- func (s *SqliteBackend) SaveAlbum(a *Album) error
- func (s *SqliteBackend) SaveArt(a *Art) error
- func (s *SqliteBackend) SaveArtist(a *Artist) error
- func (s *SqliteBackend) SaveFolder(f *Folder) error
- func (s *SqliteBackend) SaveSession(u *Session) error
- func (s *SqliteBackend) SaveSong(a *Song) error
- func (s *SqliteBackend) SaveUser(u *User) error
- func (s *SqliteBackend) SearchAlbums(query string) ([]Album, error)
- func (s *SqliteBackend) SearchArtists(query string) ([]Artist, error)
- func (s *SqliteBackend) SearchFolders(query string) ([]Folder, error)
- func (s *SqliteBackend) SearchSongs(query string) ([]Song, error)
- func (s *SqliteBackend) SessionsForUser(userID int) ([]Session, error)
- func (s *SqliteBackend) Setup() error
- func (s *SqliteBackend) SongsForAlbum(ID int) ([]Song, error)
- func (s *SqliteBackend) SongsForArtist(ID int) ([]Song, error)
- func (s *SqliteBackend) SongsForFolder(ID int) ([]Song, error)
- func (s *SqliteBackend) SongsInPath(path string) ([]Song, error)
- func (s *SqliteBackend) SongsNotInPath(path string) ([]Song, error)
- func (s *SqliteBackend) Subfolders(parentID int) ([]Folder, error)
- func (s *SqliteBackend) UpdateSession(u *Session) error
- func (s *SqliteBackend) UpdateSong(a *Song) error
- func (s *SqliteBackend) UpdateUser(u *User) error
- type User
- Bugs
Constants ¶
const ( APE = iota FLAC M4A MP3 MPC OGG WMA WV )
Constants representing the various song file types which wavepipe can index
const ( RoleGuest = iota RoleUser RoleAdmin )
Constants representing the various roles a user may possess
Variables ¶
var ( // ErrSongTags is returned when required tags could not be extracted from a TagLib file ErrSongTags = errors.New("song: required tags could not be extracted from TagLib file") // ErrSongProperties is returned when required properties could not be extracted from a TagLib file ErrSongProperties = errors.New("song: required properties could not be extracted from TagLib file") )
var CodecMap = map[int]string{ APE: "APE", FLAC: "FLAC", M4A: "M4A", MP3: "MP3", MPC: "MPC", OGG: "OGG", WMA: "WMA", WV: "WV", }
CodecMap maps wavepipe file type IDs to file types
var DB dbBackend
DB is the current database backend
var FileTypeMap = map[string]int{ ".ape": APE, ".flac": FLAC, ".m4a": M4A, ".mp3": MP3, ".mpc": MPC, ".ogg": OGG, ".wma": WMA, ".wv": WV, }
FileTypeMap maps song extension to wavepipe file type IDs
var MIMEMap = map[int]string{ APE: "audio/ape", FLAC: "audio/flac", M4A: "audio/aac", MP3: "audio/mpeg", MPC: "audio/mpc", OGG: "audio/ogg", WMA: "audio/wma", WV: "audio/wv", }
MIMEMap maps a wavepipe file type ID its MIME type BUG(mdlayher): MIMEMap: verify correctness of MIME types
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Album ¶
type Album struct { ID int `json:"id"` Artist string `json:"artist"` ArtistID int `db:"artist_id" json:"artistId"` Title string `json:"title"` Year int `json:"year"` }
Album represents an album known to wavepipe, and contains information extracted from song tags
func AlbumFromSong ¶
AlbumFromSong creates a new Album from a Song model, extracting its fields as needed to build the struct
type Art ¶
type Art struct { ID int FileSize int64 `db:"file_size"` FileName string `db:"file_name"` LastModified int64 `db:"last_modified"` }
Art represents folder or album art known to wavepipe, and contains filesystem metadata
type Artist ¶
Artist represents an artist known to wavepipe, and contains a unique ID and name for this artist
func ArtistFromSong ¶
ArtistFromSong creates a new Artist from a Song model, extracting its fields as needed to build the struct
type Folder ¶
type Folder struct { ID int `json:"id"` ParentID int `db:"parent_id" json:"parentId"` Title string `json:"title"` Path string `json:"path"` }
Folder represents a filesystem folder known to wavepipe
func (*Folder) Subfolders ¶
Subfolders retrieves all folders with this folder as their parent ID
type Session ¶
type Session struct { ID int `json:"id"` UserID int `db:"user_id" json:"userId"` Client string `json:"client"` Expire int64 `json:"expire"` Key string `db:"key" json:"key"` }
Session represents an API session for a specific user on wavepipe
func NewSession ¶
NewSession generates and saves a new session for the specified user, with the specified client name. This function also randomly generates public and private keys.
type Song ¶
type Song struct { ID int `json:"id"` Album string `json:"album"` AlbumID int `db:"album_id" json:"albumId"` ArtID int `db:"art_id" json:"artId"` Artist string `json:"artist"` ArtistID int `db:"artist_id" json:"artistId"` Bitrate int `json:"bitrate"` Channels int `json:"channels"` Comment string `json:"comment"` FileName string `db:"file_name" json:"fileName"` FileSize int64 `db:"file_size" json:"fileSize"` FileTypeID int `db:"file_type_id" json:"fileTypeId"` FolderID int `db:"folder_id" json:"folderId"` Genre string `json:"genre"` LastModified int64 `db:"last_modified" json:"lastModified"` Length int `json:"length"` SampleRate int `db:"sample_rate" json:"sampleRate"` Title string `json:"title"` Track int `json:"track"` Year int `json:"year"` }
Song represents a song known to wavepipe, and contains metadata regarding the song, and where it resides in the filsystem
func SongFromFile ¶
SongFromFile creates a new Song from a TagLib file, extracting its tags and properties into the fields of the struct.
type SongSlice ¶
type SongSlice []Song
SongSlice represents a slice of songs, and provides convenience methods to access their aggregate properties
type SqliteBackend ¶
type SqliteBackend struct { Path string // contains filtered or unexported fields }
SqliteBackend represents a sqlite3-based database backend
func (*SqliteBackend) AlbumsForArtist ¶
func (s *SqliteBackend) AlbumsForArtist(ID int) ([]Album, error)
AlbumsForArtist loads a slice of all Album structs with matching artist ID
func (*SqliteBackend) AllAlbums ¶
func (s *SqliteBackend) AllAlbums() ([]Album, error)
AllAlbums loads a slice of all Album structs from the database
func (*SqliteBackend) AllArtists ¶
func (s *SqliteBackend) AllArtists() ([]Artist, error)
AllArtists loads a slice of all Artist structs from the database
func (*SqliteBackend) AllArtistsByTitle ¶
func (s *SqliteBackend) AllArtistsByTitle() ([]Artist, error)
AllArtistsByTitle loads a slice of all Artist structs from the database, sorted alphabetically by title
func (*SqliteBackend) AllFolders ¶
func (s *SqliteBackend) AllFolders() ([]Folder, error)
AllFolders loads a slice of all Folder structs from the database
func (*SqliteBackend) AllSongs ¶
func (s *SqliteBackend) AllSongs() ([]Song, error)
AllSongs loads a slice of all Song structs from the database
func (*SqliteBackend) AllUsers ¶
func (s *SqliteBackend) AllUsers() ([]User, error)
AllUsers loads a slice of all User structs from the database
func (*SqliteBackend) ArtInPath ¶
func (s *SqliteBackend) ArtInPath(path string) ([]Art, error)
ArtInPath loads a slice of all Art structs contained within the specified file path
func (*SqliteBackend) ArtNotInPath ¶
func (s *SqliteBackend) ArtNotInPath(path string) ([]Art, error)
ArtNotInPath loads a slice of all Art structs NOT contained within the specified file path
func (*SqliteBackend) Close ¶
func (s *SqliteBackend) Close() error
Close closes the current sqlite sqlx database connection
func (*SqliteBackend) CountAlbums ¶
func (s *SqliteBackend) CountAlbums() (int64, error)
CountAlbums fetches the total number of Album structs from the database
func (*SqliteBackend) CountArt ¶
func (s *SqliteBackend) CountArt() (int64, error)
CountArt fetches the total number of Art structs from the database
func (*SqliteBackend) CountArtists ¶
func (s *SqliteBackend) CountArtists() (int64, error)
CountArtists fetches the total number of Artist structs from the database
func (*SqliteBackend) CountFolders ¶
func (s *SqliteBackend) CountFolders() (int64, error)
CountFolders fetches the total number of Folder structs from the database
func (*SqliteBackend) CountSongs ¶
func (s *SqliteBackend) CountSongs() (int64, error)
CountSongs fetches the total number of Artist structs from the database
func (*SqliteBackend) DSN ¶
func (s *SqliteBackend) DSN(path string)
DSN sets the Path for use with sqlite3
func (*SqliteBackend) DeleteAlbum ¶
func (s *SqliteBackend) DeleteAlbum(a *Album) error
DeleteAlbum removes a Album from the database
func (*SqliteBackend) DeleteArt ¶
func (s *SqliteBackend) DeleteArt(a *Art) error
DeleteArt removes Art from the database
func (*SqliteBackend) DeleteArtist ¶
func (s *SqliteBackend) DeleteArtist(a *Artist) error
DeleteArtist removes an Artist from the database
func (*SqliteBackend) DeleteFolder ¶
func (s *SqliteBackend) DeleteFolder(f *Folder) error
DeleteFolder removes a Folder from the database
func (*SqliteBackend) DeleteSession ¶
func (s *SqliteBackend) DeleteSession(u *Session) error
DeleteSession removes a Session from the database
func (*SqliteBackend) DeleteSong ¶
func (s *SqliteBackend) DeleteSong(a *Song) error
DeleteSong removes a Song from the database
func (*SqliteBackend) DeleteUser ¶
func (s *SqliteBackend) DeleteUser(u *User) error
DeleteUser removes a User from the database
func (*SqliteBackend) FoldersInPath ¶
func (s *SqliteBackend) FoldersInPath(path string) ([]Folder, error)
FoldersInPath loads a slice of all Folder structs contained within the specified file path
func (*SqliteBackend) FoldersNotInPath ¶
func (s *SqliteBackend) FoldersNotInPath(path string) ([]Folder, error)
FoldersNotInPath loads a slice of all Folder structs NOT contained within the specified file path
func (*SqliteBackend) LimitAlbums ¶
func (s *SqliteBackend) LimitAlbums(offset int, count int) ([]Album, error)
LimitAlbums loads a slice of Album structs from the database using SQL limit, where the first parameter specifies an offset and the second specifies an item count
func (*SqliteBackend) LimitArtists ¶
func (s *SqliteBackend) LimitArtists(offset int, count int) ([]Artist, error)
LimitArtists loads a slice of Artist structs from the database using SQL limit, where the first parameter specifies an offset and the second specifies an item count
func (*SqliteBackend) LimitFolders ¶
func (s *SqliteBackend) LimitFolders(offset int, count int) ([]Folder, error)
LimitFolders loads a slice of Folder structs from the database using SQL limit, where the first parameter specifies an offset and the second specifies an item count
func (*SqliteBackend) LimitSongs ¶
func (s *SqliteBackend) LimitSongs(offset int, count int) ([]Song, error)
LimitSongs loads a slice of Song structs from the database using SQL limit, where the first parameter specifies an offset and the second specifies an item count
func (*SqliteBackend) LoadAlbum ¶
func (s *SqliteBackend) LoadAlbum(a *Album) error
LoadAlbum loads an Album from the database, populating the parameter struct
func (*SqliteBackend) LoadArt ¶
func (s *SqliteBackend) LoadArt(a *Art) error
LoadArt loads Art from the database, populating the parameter struct
func (*SqliteBackend) LoadArtist ¶
func (s *SqliteBackend) LoadArtist(a *Artist) error
LoadArtist loads an Artist from the database, populating the parameter struct
func (*SqliteBackend) LoadFolder ¶
func (s *SqliteBackend) LoadFolder(f *Folder) error
LoadFolder loads a Folder from the database, populating the parameter struct
func (*SqliteBackend) LoadSession ¶
func (s *SqliteBackend) LoadSession(u *Session) error
LoadSession loads a Session from the database, populating the parameter struct
func (*SqliteBackend) LoadSong ¶
func (s *SqliteBackend) LoadSong(a *Song) error
LoadSong loads a Song from the database, populating the parameter struct
func (*SqliteBackend) LoadUser ¶
func (s *SqliteBackend) LoadUser(u *User) error
LoadUser loads a User from the database, populating the parameter struct
func (*SqliteBackend) Open ¶
func (s *SqliteBackend) Open() error
Open initializes a new sqlite sqlx database connection
func (*SqliteBackend) PurgeOrphanAlbums ¶
func (s *SqliteBackend) PurgeOrphanAlbums() (int, error)
PurgeOrphanAlbums deletes all albums who are "orphaned", meaning that they no longer have any songs which reference their ID
func (*SqliteBackend) PurgeOrphanArtists ¶
func (s *SqliteBackend) PurgeOrphanArtists() (int, error)
PurgeOrphanArtists deletes all artists who are "orphaned", meaning that they no longer have any songs which reference their ID
func (*SqliteBackend) RandomSongs ¶
func (s *SqliteBackend) RandomSongs(n int) ([]Song, error)
RandomSongs loads a slice of 'n' random song structs from the database
func (*SqliteBackend) SaveAlbum ¶
func (s *SqliteBackend) SaveAlbum(a *Album) error
SaveAlbum attempts to save an Album to the database
func (*SqliteBackend) SaveArt ¶
func (s *SqliteBackend) SaveArt(a *Art) error
SaveArt attempts to save Art to the database
func (*SqliteBackend) SaveArtist ¶
func (s *SqliteBackend) SaveArtist(a *Artist) error
SaveArtist attempts to save an Artist to the database
func (*SqliteBackend) SaveFolder ¶
func (s *SqliteBackend) SaveFolder(f *Folder) error
SaveFolder attempts to save an Folder to the database
func (*SqliteBackend) SaveSession ¶
func (s *SqliteBackend) SaveSession(u *Session) error
SaveSession attempts to save a Session to the database
func (*SqliteBackend) SaveSong ¶
func (s *SqliteBackend) SaveSong(a *Song) error
SaveSong attempts to save a Song to the database
func (*SqliteBackend) SaveUser ¶
func (s *SqliteBackend) SaveUser(u *User) error
SaveUser attempts to save a User to the database
func (*SqliteBackend) SearchAlbums ¶
func (s *SqliteBackend) SearchAlbums(query string) ([]Album, error)
SearchAlbums loads a slice of all Album structs from the database which contain titles that match the specified search query
func (*SqliteBackend) SearchArtists ¶
func (s *SqliteBackend) SearchArtists(query string) ([]Artist, error)
SearchArtists loads a slice of all Artist structs from the database which contain titles that match the specified search query
func (*SqliteBackend) SearchFolders ¶
func (s *SqliteBackend) SearchFolders(query string) ([]Folder, error)
SearchFolders loads a slice of all Folder structs from the database which contain titles that match the specified search query
func (*SqliteBackend) SearchSongs ¶
func (s *SqliteBackend) SearchSongs(query string) ([]Song, error)
SearchSongs loads a slice of all Song structs from the database which contain titles that match the specified search query
func (*SqliteBackend) SessionsForUser ¶
func (s *SqliteBackend) SessionsForUser(userID int) ([]Session, error)
SessionsForUser loads a slice of all Sessions for a given User from the database
func (*SqliteBackend) Setup ¶
func (s *SqliteBackend) Setup() error
Setup copies the empty sqlite database into the wavepipe configuration directory
func (*SqliteBackend) SongsForAlbum ¶
func (s *SqliteBackend) SongsForAlbum(ID int) ([]Song, error)
SongsForAlbum loads a slice of all Song structs which have the matching album ID
func (*SqliteBackend) SongsForArtist ¶
func (s *SqliteBackend) SongsForArtist(ID int) ([]Song, error)
SongsForArtist loads a slice of all Song structs which have the matching artist ID
func (*SqliteBackend) SongsForFolder ¶
func (s *SqliteBackend) SongsForFolder(ID int) ([]Song, error)
SongsForFolder loads a slice of all Song structs which have the matching folder ID
func (*SqliteBackend) SongsInPath ¶
func (s *SqliteBackend) SongsInPath(path string) ([]Song, error)
SongsInPath loads a slice of all Song structs residing under the specified filesystem path from the database
func (*SqliteBackend) SongsNotInPath ¶
func (s *SqliteBackend) SongsNotInPath(path string) ([]Song, error)
SongsNotInPath loads a slice of all Song structs that do not reside under the specified filesystem path from the database
func (*SqliteBackend) Subfolders ¶
func (s *SqliteBackend) Subfolders(parentID int) ([]Folder, error)
Subfolders loads a slice of all Folder structs residing directly beneath this one from the database
func (*SqliteBackend) UpdateSession ¶
func (s *SqliteBackend) UpdateSession(u *Session) error
UpdateSession updates a Session in the database
func (*SqliteBackend) UpdateSong ¶
func (s *SqliteBackend) UpdateSong(a *Song) error
UpdateSong attempts to update a Song in the database
func (*SqliteBackend) UpdateUser ¶
func (s *SqliteBackend) UpdateUser(u *User) error
UpdateUser updates a User in the database
type User ¶
type User struct { ID int `json:"id"` Username string `json:"username"` Password string `json:"-"` RoleID int `db:"role_id" json:"roleId"` LastFMToken string `db:"lastfm_token" json:"-"` }
User represents an user registered to wavepipe
func (User) CreateSession ¶
CreateSession generates a new API session for this user
func (*User) SetPassword ¶
SetPassword hashes a password using bcrypt, and stores it in the User struct
Notes ¶
Bugs ¶
MIMEMap: verify correctness of MIME types