data

package
v0.0.0-...-d437fa4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2014 License: MIT Imports: 18 Imported by: 0

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

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

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

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

func (a *Album) FromJSON(in []byte) error

FromJSON generates an Album from its JSON representation

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

func (Album) ToJSON

func (a Album) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of an Album

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

func (a *Artist) FromJSON(in []byte) error

FromJSON generates an Artist from its JSON representation

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

func (Artist) ToJSON

func (a Artist) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of an Artist

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

func (f *Folder) FromJSON(in []byte) error

FromJSON generates a Folder from its JSON representation

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

func (Folder) ToJSON

func (f Folder) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of a Folder

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

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

func (u *Session) FromJSON(in []byte) error

FromJSON generates a Session from its JSON representation

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

func (u Session) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of a Session

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"`
	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) FromJSON

func (s *Song) FromJSON(in []byte) error

FromJSON generates a Song from its JSON representation

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.ReadCloser, error)

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

func (Song) ToJSON

func (s Song) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of a Song

func (*Song) Update

func (s *Song) Update() error

Update updates an existing Song in the database

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 NewUser

func NewUser(username string, password string) (*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) FromJSON

func (u *User) FromJSON(in []byte) error

FromJSON generates a User from its JSON representation

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

func (u User) ToJSON() ([]byte, error)

ToJSON generates a JSON representation of a User

Jump to

Keyboard shortcuts

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