Documentation ¶
Overview ¶
Package data provides the models and database backends of the wavepipe media server.
Index ¶
- Constants
- Variables
- type Album
- type Artist
- type Folder
- type Session
- type Song
- 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) AllFolders() ([]Folder, error)
- func (s *SqliteBackend) AllSongs() ([]Song, error)
- func (s *SqliteBackend) DSN(path string)
- func (s *SqliteBackend) DeleteAlbum(a *Album) 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) LoadAlbum(a *Album) 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() (*sqlx.DB, error)
- func (s *SqliteBackend) PurgeOrphanAlbums() (int, error)
- func (s *SqliteBackend) PurgeOrphanArtists() (int, error)
- func (s *SqliteBackend) SaveAlbum(a *Album) 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) 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
- type User
Constants ¶
const ( APE = iota FLAC M4A MP3 MPC OGG WMA WV )
Constants representing the various song file types which wavepipe can index
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
Functions ¶
This section is empty.
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 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"` PublicKey string `db:"public_key" json:"publicKey"` SecretKey string `db:"secret_key" json:"secretKey"` }
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"` 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.
func (Song) Stream ¶
func (s Song) Stream() (io.ReadCloser, error)
Stream generates a binary file stream from this Song's file location
type SqliteBackend ¶
type SqliteBackend struct {
Path string
}
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) 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) 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) 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) LoadAlbum ¶
func (s *SqliteBackend) LoadAlbum(a *Album) error
LoadAlbum loads an Album 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() (*sqlx.DB, error)
Open opens a new 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) SaveAlbum ¶
func (s *SqliteBackend) SaveAlbum(a *Album) error
SaveAlbum attempts to save an Album 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) 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
type User ¶
type User struct { ID int `json:"id"` Username string `json:"username"` Password string `json:"password"` }
User represents an user registered to wavepipe
func (User) CreateSession ¶
CreateSession generates a new API session for this user