Documentation ¶
Overview ¶
Package model of the application, mainly the database, miner and parser.
Index ¶
- 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 Database
- func (database *Database) AddAlbum(rola *Rola) int64
- func (database *Database) AddGroup(groupName, start, end string) int64
- func (database *Database) AddPerformer(rola *Rola) int64
- func (database *Database) AddPerson(stageName, realName, birth, death string)
- func (database *Database) AddPersonToGroup(personID, groupID int64)
- func (database *Database) AddRola(rola *Rola, idperformer, idalbum int64) int64
- func (database *Database) AllGroups() map[string]int64
- func (database *Database) AllPersons() map[string]int64
- func (database *Database) CreateDB()
- func (database *Database) ExistsAlbum(albumPath, name string) int64
- func (database *Database) ExistsGroup(groupName string) int64
- func (database *Database) ExistsPerformer(performerName string) int64
- func (database *Database) ExistsPerson(stageName string) int64
- func (database *Database) LoadDB()
- func (database *Database) PrepareStatement(statement string) (*sql.Tx, *sql.Stmt)
- func (database *Database) PreparedQuery(statement string, args ...interface{}) (*sql.Tx, *sql.Stmt, *sql.Rows)
- func (database *Database) QueryCustom(stmtStr string, terms ...interface{}) []int64
- func (database *Database) QueryGroup(groupID int64) (string, string, string)
- func (database *Database) QueryGroupMembers(groupID int64) map[string]bool
- func (database *Database) QueryPerformerType(id int64) (int, string)
- func (database *Database) QueryPerson(personID int64) (string, string, string, string)
- func (database *Database) QueryPersonGroups(personID int64) map[string]bool
- func (database *Database) QueryRola(rolaID int64) *Rola
- func (database *Database) QueryRolaForeign(rolaID int64) (int64, int64)
- func (database *Database) QuerySimple(wildcard string) []int64
- func (database *Database) UpdateGroup(name, start, end string, groupID int64)
- func (database *Database) UpdatePerformerType(performerID int64, performerType int)
- func (database *Database) UpdatePerson(stageName, realName, birth, death string, personID int64)
- func (database *Database) UpdateRola(rola *Rola)
- type Genre
- type Miner
- type Parser
- type Rola
- func (rola *Rola) Album() string
- func (rola *Rola) Artist() string
- func (rola *Rola) Genre() string
- func (rola *Rola) ID() int64
- func (rola *Rola) Path() string
- func (rola *Rola) SetAlbum(album string)
- func (rola *Rola) SetArtist(artist string)
- func (rola *Rola) SetGenre(genre string)
- func (rola *Rola) SetID(id int64)
- func (rola *Rola) SetPath(path string)
- func (rola *Rola) SetTitle(title string)
- func (rola *Rola) SetTrack(track int)
- func (rola *Rola) SetYear(year int)
- func (rola *Rola) Title() string
- func (rola *Rola) Track() int
- func (rola *Rola) Year() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 Database ¶
A Database is the intermediary between the sql database and the rest of the model and the view.
func NewDatabase ¶
NewDatabase creates a new Database object, checking whether a .db file already exists and opening a connection to it, or creating a new one. The database is saved in the file "~/.cache/rolas/rolas.db"
func (*Database) AddAlbum ¶
AddAlbum takes a Rola as a parameter, adds its album to the database and returns the ID number of the album in the database. If the album was already in the database, this method does nothing and returns the ID of the album in the database.
func (*Database) AddGroup ¶
AddGroup takes a Rola as a parameter, adds its performer, which has been already verified to be a group, to the database, and returns the ID of the group in the database. If the group is already in the database, this method does nothing and returns the group ID in the database.
func (*Database) AddPerformer ¶
AddPerformer takes a Rola as a parameter, adds its performer to the database, and returns the ID number of the performer in the database. The performer is added with type 2 (not known if it is a person of a group). If the performer is already in the database, this method does nothing and returns the performer ID in the database.
func (*Database) AddPerson ¶
AddPerson takes a Rola as a parameter, adds its performer, which has been already verified to be a person, to the database, and returns the ID of the person in the database. If the person is already in the database, this method does nothing and returns the person ID in the database.
func (*Database) AddPersonToGroup ¶
AddPersonToGroup receives the ID of a person and group in the database, respectively, and adds them to the in_group table, i.e., adds the person to the group.
func (*Database) AddRola ¶
AddRola takes a Rola and the IDs of the performer and album of the Rola as parameters, and attempts to add the Rola to the database. If it was already in the database, it does nothing and returns -1. Otherwise it returns the ID asigned to the Rola by the database.
func (*Database) AllGroups ¶
AllGroups queries the database and returns a map whose keys are the names of all the groups in the database, and the corresponding values are the IDs of the groups.
func (*Database) AllPersons ¶
AllPersons queries the database and returns a map whose keys are the names of all the persons in the database, and the corresponding values are the IDs of the persons.
func (*Database) CreateDB ¶
func (database *Database) CreateDB()
CreateDB creates the tables specified in the rolas.sql file.
func (*Database) ExistsAlbum ¶
ExistsAlbum takes an album's path and name, and returns the album ID in the database, or 0 if the album is not in the database.
func (*Database) ExistsGroup ¶
ExistsGroup takes a group's name as an argument and returns the group ID in the database, or 0 if the group is not in the database.
func (*Database) ExistsPerformer ¶
ExistsPerformer takes a performer's name as an argument and returns the performer ID in the database, or 0 if the performer is not in the database.
func (*Database) ExistsPerson ¶
ExistsPerson takes a person's name and returns the person ID in the database, or 0 if the album is not in the database.
func (*Database) LoadDB ¶
func (database *Database) LoadDB()
LoadDB pings the database to verify if the connection is active.
func (*Database) PrepareStatement ¶
PrepareStatement initializes an sqlite prepared statement from a string and returns the corresponding sql context and prepared statement.
func (*Database) PreparedQuery ¶
func (database *Database) PreparedQuery(statement string, args ...interface{}) (*sql.Tx, *sql.Stmt, *sql.Rows)
PreparedQuery executes a prepared query and returns the resulting rows, it handles the errors and returns the context and prepared statement for the user to close them.
func (*Database) QueryCustom ¶
QueryCustom receives a parsed string in disjunctive normal form and executes the corresponding query.
func (*Database) QueryGroup ¶
QueryGroup receives a group ID and returns its name, start_date and end_date. It is assumed that the group is in the database.
func (*Database) QueryGroupMembers ¶
QueryGroupMembers receives a group ID as a parameter and returns a map having the group members' names as keys and the value is true if the person is a member of the group. It is assumed that the group is in the database.
func (*Database) QueryPerformerType ¶
QueryPerformerType receives a performer's ID as an argument and returns its type and name. It is assumed that the performer is in the database.
func (*Database) QueryPerson ¶
QueryPerson receives a person's ID as an argument and returns its stage_name, real_name, birth_date and death_date, all as strings. It is assumed that the person is in the database.
func (*Database) QueryPersonGroups ¶
QueryPersonGroups takes a person's ID as an argument and returns a map whose keys are the groups where the person is a member, and the values are all true. It is assumed that the person is in the database.
func (*Database) QueryRola ¶
QueryRola receives a Rola's ID as an argument and returns the correspoding rola, but with an empty path. It is assumed that the rola is in the database.
func (*Database) QueryRolaForeign ¶
QueryRolaForeign takes a Rola's ID as an argument and returns the IDs associated to its performer and album.
func (*Database) QuerySimple ¶
QuerySimple receives a string as an argument, and returns a slice with the IDs of all the Rolas containing the string in its performer name, album name, title, or genre.
func (*Database) UpdateGroup ¶
UpdateGroup receives new values for the fields of a group, together with the group's ID, and updates the information. It is assumed that the group is in the database.
func (*Database) UpdatePerformerType ¶
UpdatePerformerType receives a performer's ID and a performer's type (0, 1, 2), to set the new peformer's type. It is assumed that the performer is in the database.
func (*Database) UpdatePerson ¶
UpdatePerson receives new values for the fields of a person, together with the person's ID, and updates the information. It is assumed that the person is in the database.
func (*Database) UpdateRola ¶
UpdateRola takes a Rola as an argument and updates all its fields in the database. It is assumed that the Rola taken as argument has the same ID as the rola we want to update.
type Genre ¶
type Genre struct {
// contains filtered or unexported fields
}
Genre is a simple translator for ID3v1 genre codes, it contains a single dictionary with the codes as keys and the corresponding genres as values (both are strings). It is a singleton.
type Miner ¶
type Miner struct { TrackList chan *Rola // contains filtered or unexported fields }
A Miner searches for mp3 files in the /home/user/Music directory along the file tree, gathers their information, and puts it in a Rola object, which is then loaded into a channel for external use.
func (*Miner) Extract ¶
func (miner *Miner) Extract()
Extract traverses the paths slice, opens each of the files whose paths are in the slice, reads the ID3v2 tag, saves the information into a new Rola, and puts it in the ore channel of the miner.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser for the search bar of the main application window. The parser uses && and || for 'AND' and 'OR', respectively; searches can be performed by any of the id3v2 fields in a Rola. Start a search with '*~*', use the first two letters in the field between asterisks, followed by '=', '~', '<', or '>' for an exact search, a wildcard search, or for certain ranges (for numeric fields), respectively, e.g., '*AR*~punk' searches for all artists containing 'punk' in their name. There are negated versions of the four operators, '!=', etc. The parser joins the atomic formulas to get a formula in disjunctive normal form.
type Rola ¶
type Rola struct {
// contains filtered or unexported fields
}
A Rola represents a song, it contains the information present in various frames from the id3v2 tag, namely, artist, title, album track number, year, genre, and additionally, the path of the song file, and the id assigned by the database to the song.
func NewRola ¶
func NewRola() *Rola
NewRola creates a Rola with default values; text fields are "Unknown" and numeric fields are 0.
func (*Rola) SetID ¶
SetID sets the ID of the Rola. This value should not be changed unless the corresponding value changes in the Database.