data

package
v0.0.0-...-c88dce1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2017 License: MIT Imports: 19 Imported by: 4

Documentation

Overview

Package data provides the models and database backends of the wavepipe media server.

Index

Constants

View Source
const (
	APE = iota
	FLAC
	M4A
	MP3
	MPC
	OGG
	WMA
	WV
)

Constants representing the various song file types which wavepipe can index

View Source
const (
	RoleGuest = iota
	RoleUser
	RoleAdmin
)

Constants representing the various roles a user may possess

Variables

View Source
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")
)
View Source
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

View Source
var DB dbBackend

DB is the current database backend

View Source
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

View Source
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

func Asset(name string) ([]byte, error)

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 AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

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

func AlbumFromSong(song *Song) *Album

AlbumFromSong creates a new Album from a Song model, extracting its fields as needed to build the struct

func (*Album) Delete

func (a *Album) Delete() error

Delete removes an existing Album from the database

func (*Album) Load

func (a *Album) Load() error

Load pulls an existing Album from the database

func (*Album) Save

func (a *Album) Save() error

Save creates a new Album in the database

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

func (*Art) Delete

func (a *Art) Delete() error

Delete removes existing Art from the database

func (*Art) Load

func (a *Art) Load() error

Load pulls existing Art from the database

func (*Art) Save

func (a *Art) Save() error

Save creates new Art in the database

func (Art) Stream

func (a Art) Stream() (io.ReadSeeker, error)

Stream returns an art stream from the art file

type Artist

type Artist struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
}

Artist represents an artist known to wavepipe, and contains a unique ID and name for this artist

func ArtistFromSong

func ArtistFromSong(song *Song) *Artist

ArtistFromSong creates a new Artist from a Song model, extracting its fields as needed to build the struct

func (*Artist) Delete

func (a *Artist) Delete() error

Delete removes an existing Artist from the database

func (*Artist) Load

func (a *Artist) Load() error

Load pulls an existing Artist from the database

func (*Artist) Save

func (a *Artist) Save() error

Save creates a new Artist in the database

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) Delete

func (f *Folder) Delete() error

Delete removes an existing Folder from the database

func (*Folder) Load

func (f *Folder) Load() error

Load pulls an existing Folder from the database

func (*Folder) Save

func (f *Folder) Save() error

Save creates a new Folder in the database

func (*Folder) Subfolders

func (f *Folder) Subfolders() ([]Folder, error)

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

func NewSession(userID int, password string, client string) (*Session, error)

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.

func (*Session) Delete

func (u *Session) Delete() error

Delete removes an existing Session from the database

func (*Session) Load

func (u *Session) Load() error

Load pulls an existing Session from the database

func (*Session) Save

func (u *Session) Save() error

Save creates a new Session in the database

func (*Session) Update

func (u *Session) Update() error

Update updates an existing Session in the database

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

func SongFromFile(file *taglib.File) (*Song, error)

SongFromFile creates a new Song from a TagLib file, extracting its tags and properties into the fields of the struct.

func (*Song) Delete

func (s *Song) Delete() error

Delete removes an existing Song from the database

func (*Song) Load

func (s *Song) Load() error

Load pulls an existing Song from the database

func (*Song) Save

func (s *Song) Save() error

Save creates a new Song in the database

func (Song) Stream

func (s Song) Stream() (io.ReadSeeker, error)

Stream generates a binary file stream from this Song's file location

func (*Song) Update

func (s *Song) Update() error

Update updates an existing Song in the database

type SongSlice

type SongSlice []Song

SongSlice represents a slice of songs, and provides convenience methods to access their aggregate properties

func (SongSlice) Length

func (s SongSlice) Length() int

Length returns the total duration of a slice of songs

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 NewUser

func NewUser(username string, password string, roleID int) (*User, error)

NewUser generates and saves a new user, while also hashing the input password

func (User) CreateSession

func (u User) CreateSession(client string) (*Session, error)

CreateSession generates a new API session for this user

func (*User) Delete

func (u *User) Delete() error

Delete removes an existing User from the database

func (*User) Load

func (u *User) Load() error

Load pulls an existing User from the database

func (*User) Save

func (u *User) Save() error

Save creates a new User in the database

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword hashes a password using bcrypt, and stores it in the User struct

func (*User) Update

func (u *User) Update() error

Update updates an existing User in the database

Notes

Bugs

  • MIMEMap: verify correctness of MIME types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL