model

package
v0.0.0-...-f064738 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package model of the application, mainly the database, miner and parser.

Index

Constants

This section is empty.

Variables

This section is empty.

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 AssetDir

func AssetDir(name string) ([]string, error)

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

func AssetInfo(name string) (os.FileInfo, error)

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 AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Database

type Database struct {
	Database *sql.DB
	// contains filtered or unexported fields
}

A Database is the intermediary between the sql database and the rest of the model and the view.

func NewDatabase

func NewDatabase() (*Database, bool)

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

func (database *Database) AddAlbum(rola *Rola) int64

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

func (database *Database) AddGroup(groupName, start, end string) int64

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

func (database *Database) AddPerformer(rola *Rola) int64

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

func (database *Database) AddPerson(stageName, realName, birth, death string)

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

func (database *Database) AddPersonToGroup(personID, groupID int64)

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

func (database *Database) AddRola(rola *Rola, idperformer, idalbum int64) int64

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

func (database *Database) AllGroups() map[string]int64

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

func (database *Database) AllPersons() map[string]int64

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

func (database *Database) ExistsAlbum(albumPath, name string) int64

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

func (database *Database) ExistsGroup(groupName string) int64

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

func (database *Database) ExistsPerformer(performerName string) int64

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

func (database *Database) ExistsPerson(stageName string) int64

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

func (database *Database) PrepareStatement(statement string) (*sql.Tx, *sql.Stmt)

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

func (database *Database) QueryCustom(stmtStr string, terms ...interface{}) []int64

QueryCustom receives a parsed string in disjunctive normal form and executes the corresponding query.

func (*Database) QueryGroup

func (database *Database) QueryGroup(groupID int64) (string, string, string)

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

func (database *Database) QueryGroupMembers(groupID int64) map[string]bool

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

func (database *Database) QueryPerformerType(id int64) (int, string)

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

func (database *Database) QueryPerson(personID int64) (string, string, string, string)

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

func (database *Database) QueryPersonGroups(personID int64) map[string]bool

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

func (database *Database) QueryRola(rolaID int64) *Rola

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

func (database *Database) QueryRolaForeign(rolaID int64) (int64, int64)

QueryRolaForeign takes a Rola's ID as an argument and returns the IDs associated to its performer and album.

func (*Database) QuerySimple

func (database *Database) QuerySimple(wildcard string) []int64

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

func (database *Database) UpdateGroup(name, start, end string, groupID int64)

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

func (database *Database) UpdatePerformerType(performerID int64, performerType int)

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

func (database *Database) UpdatePerson(stageName, realName, birth, death string, personID int64)

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

func (database *Database) UpdateRola(rola *Rola)

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.

func GetGenre

func GetGenre() *Genre

GetGenre returns the singleton instance of Genre. The implementation of the singleton is not thread-safe due to conflicts with gtk.

func (*Genre) Get

func (genre *Genre) Get(code string) string

Get receives a string corresponding to an ID3v1 genre code and returns the corresponding genre.

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 NewMiner

func NewMiner() *Miner

NewMiner returns a new Miner with an empty paths slice.

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.

func (*Miner) Populate

func (miner *Miner) Populate(database *Database)

Populate takes the Rolas in the ore channel of the miner, adds them to the database, and if it was a new Rola, it is put in the TrackList channel. TODO: Maybe this method should be in the controller package.

func (*Miner) Traverse

func (miner *Miner) Traverse()

Traverse walks the file tree looking for mp3 files and saving their paths into the paths slice.

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.

func GetParser

func GetParser() *Parser

GetParser returns the singleton instance of Parser. The singleton implementation is not thread safe due to conflicts with gtk.

func (*Parser) Parse

func (parser *Parser) Parse(entry string) (string, []interface{}, bool)

Parse parses a search string into a sqlite query.

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

func (rola *Rola) Album() string

Album returns the album where the Rola is included.

func (*Rola) Artist

func (rola *Rola) Artist() string

Artist returns the performer of the Rola.

func (*Rola) Genre

func (rola *Rola) Genre() string

Genre returns the genre of the Rola as a string.

func (*Rola) ID

func (rola *Rola) ID() int64

ID returns the ID assigned to the Rola by the database at insertion.

func (*Rola) Path

func (rola *Rola) Path() string

Path returns the path of the song file where the Rola was mined.

func (*Rola) SetAlbum

func (rola *Rola) SetAlbum(album string)

SetAlbum sets the album title of the Rola.

func (*Rola) SetArtist

func (rola *Rola) SetArtist(artist string)

SetArtist sets the Rola performer.

func (*Rola) SetGenre

func (rola *Rola) SetGenre(genre string)

SetGenre sets the genre of the Rola.

func (*Rola) SetID

func (rola *Rola) SetID(id int64)

SetID sets the ID of the Rola. This value should not be changed unless the corresponding value changes in the Database.

func (*Rola) SetPath

func (rola *Rola) SetPath(path string)

SetPath sets the path of the file where the song represented by the Rola is.

func (*Rola) SetTitle

func (rola *Rola) SetTitle(title string)

SetTitle sets the Rola title.

func (*Rola) SetTrack

func (rola *Rola) SetTrack(track int)

SetTrack sets the track number of the Rola. Should be an int.

func (*Rola) SetYear

func (rola *Rola) SetYear(year int)

SetYear sets the year of the Rola. Should be an int.

func (*Rola) Title

func (rola *Rola) Title() string

Title returns the title of the Rola.

func (*Rola) Track

func (rola *Rola) Track() int

Track returns the track number of the Rola as an int.

func (*Rola) Year

func (rola *Rola) Year() int

Year returns the year of the Rola as an int.

Jump to

Keyboard shortcuts

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