Documentation ¶
Overview ¶
Package index defines functionality for creating and manipulating a Tchaik music index.
Index ¶
- Constants
- Variables
- func Convert(l Library, id string) *library
- func DefaultGetStrings(t Track, f string) []string
- func IndexOfPath(paths []Path, p Path) int
- func ParallelSort(s sort.Interface, w Swaper) sort.Interface
- func Sort(tracks []Track, f LessFn)
- func SortKeysByGroupName(c Collection)
- func Walk(g Group, p Path, f WalkFn) error
- func WriteTo(l Library, w io.Writer) error
- type ByPrefix
- type Collection
- type Collector
- type Expander
- type Filter
- type FilterItem
- type FilterItemSlice
- type FlatSearcher
- type Group
- func CommonGroupAttr(a []attr.Interface, g Group) Group
- func FirstTrackAttr(a attr.Interface, g Group) Group
- func GroupFromPath(g Group, p Path) (Group, error)
- func RemoveEmptyCollections(g Group) Group
- func SumGroupIntAttr(field string, g Group) Group
- func Transform(g Group, fn TransformFn) Group
- func TrimEnumPrefix(g Group) Group
- func TrimTrackNumPrefix(g Group) Group
- type Key
- type LessFn
- type Library
- type Path
- func CollectionPaths(c Collection, root Path) []Path
- func NewPath(x string) Path
- func OrderedIntersection(paths ...[]Path) []Path
- func PathFromJSONInterface(raw interface{}) (Path, error)
- func PathFromStringSlice(s []string) Path
- func Recent(c Collection, n int) []Path
- func Union(l ...[]Path) []Path
- type PathSlice
- type PersistStore
- type PrefixMultiExpand
- type Searcher
- type Swaper
- type Track
- type Tracker
- type TransformFn
- type WalkFn
- type WordIndex
Constants ¶
const MinPrefix = 3
MinPrefix is the minimum number of characters that can be used in a prefix.
const PathSeparator string = ":"
PathSeparator is a string used to separate path components.
Variables ¶
var ListSeparators = []string{"/", ",", ";", ":", "&", " and ", " - ", " And "}
ListSepeartors is the list of strings used to separate String fields into 'Strings' fields.
Functions ¶
func Convert ¶
Convert reads all the data exported by the Library and writes into the standard tchaik Library implementation. NB: The identifier field is set to be the value of ID on every track, regardless of whether this value has already been set in the input Library.
func DefaultGetStrings ¶
DefaultGetStrings is a function which returns the default value for a GetStrings attribute which is based on an existing GetString attribute. In particular, we handle the case where an empty 'GetString' attribute would be "", whereas the corresponding 'GetStrings' method should return 'nil' and not '[]string{""}'.
func IndexOfPath ¶
IndexOfPath returns the index of the path within the slice of paths, or -1 if the path isn't present.
func ParallelSort ¶
ParallelSort combines a sort.Interface implementation with a Swaper, and performs the same swap operations to w as they are applied to s.
func SortKeysByGroupName ¶
func SortKeysByGroupName(c Collection)
SorkKeysByGroupName sorts the names of the given collection (in place). In particular, this assumes that g.Names() returns the actual internal representation of the listing.
Types ¶
type ByPrefix ¶
type ByPrefix string
ByPrefix is a type which creates a collection of tracks using a common prefix.
func (ByPrefix) Collect ¶
func (p ByPrefix) Collect(t Tracker) Collection
type Collection ¶
type Collection interface { Group // Keys returns a slice of Keys which give an ordering for Groups in the Collection. Keys() []Key // Get returns the Group corresponding to the given Key. Get(Key) Group }
Collection is an interface which represents an ordered series of Groups.
func Collect ¶
func Collect(t Tracker, c Collector) Collection
Collect applies the Collector to the Tracker and returns the resulting Collection.
func NewPathsCollection ¶
func NewPathsCollection(src Collection, paths []Path) Collection
NewPathsCollection creates a new collection from a source collection `c` which will contain the groups represented by the given list of paths.
func SubCollect ¶
func SubCollect(c Collection, r Collector) Collection
SubCollect applies the given Collector to each of the "leaf" Groups in the Collection.
func SubTransform ¶
func SubTransform(c Collection, fn TransformFn) Collection
SubTransform recursively applies the TransformFn to each Group in the Collection.
type Collector ¶
type Collector interface {
Collect(Tracker) Collection
}
Collector is an interface which defines the Collect method.
type Expander ¶
type Expander interface { // Expand the given string into a list of alternatives. Expand(string) []string }
Expander is an interface which implements the Expand method.
type Filter ¶
type Filter interface { // Items returns a list of FilterItems. Items() []FilterItem }
Filter is an iterface which defines the Items method.
func FilterCollection ¶
func FilterCollection(c Collection, field attr.Interface) Filter
FilterCollection creates Filter of the Collection using fields to partition Tracks in a collection.
type FilterItem ¶
FilterItem is an interface which defines behaviour for creating arbitrary filters where each filtered item is a list of Paths.
type FilterItemSlice ¶
type FilterItemSlice []FilterItem
FilterItemSlice is a convenience type which implements sort.Interface and is used to sort slices of FilterItem.
func (FilterItemSlice) Len ¶
func (f FilterItemSlice) Len() int
func (FilterItemSlice) Less ¶
func (f FilterItemSlice) Less(i, j int) bool
func (FilterItemSlice) Swap ¶
func (f FilterItemSlice) Swap(i, j int)
type FlatSearcher ¶
type FlatSearcher struct {
Searcher
}
FlatSearcher is a Searcher wrapper which flattens input strings (replaces any accented characters with their un-accented equivalents).
func (FlatSearcher) Search ¶
func (f FlatSearcher) Search(s string) []Path
Search implements Searcher.
type Group ¶
type Group interface { Tracker // Name returns the name of the group. Name() string // Field returns the value of a field. Field(string) interface{} }
Group is an interface which represents a named group of Tracks.
func CommonGroupAttr ¶
CommonGroupAttr recurses through the Group and assigns fields on all sub groups which are common amoungst their children (Groups or Tracks). If there is no common field, then the associated Field value is not set.
func FirstTrackAttr ¶
FirstTrackAttr wraps the given Group adding a string field `field` with the value taken from the first track.
func GroupFromPath ¶
GroupFromPath returns the Group which represents the given Path.
func RemoveEmptyCollections ¶
RemoveEmptyCollections recursively goes through each sub Collection contained in the Group and removes any which don't have any tracks/groups in them.
func SumGroupIntAttr ¶
SumGroupIntAttr recurses through the Group and assigns the field with the sum of fields from children (Groups or Tracks).
func Transform ¶
func Transform(g Group, fn TransformFn) Group
Transform applies the TransformFn to the Group and returns the result.
func TrimEnumPrefix ¶
TrimEnumPrefix removes enumeratative prefixes from the Tracks in the Group. The resulting group will have a ListStyle field which will indicate the style of enumeration (if any).
func TrimTrackNumPrefix ¶
TrimTrackNumPrefix trims track number prefixes on tracks. Is only applied when all the tracks names on a disc have the track number prefix.
type Key ¶
type Key string
Key represents a unique value used to represent a group within a collection.
type LessFn ¶
LessFn is a function type used for evaluating
func SortByInt ¶
SortByInt returns a LessFn which orders Tracks using the GetInt Attr on the given field.
func SortByString ¶
SortByString returns a LessFn which orders Tracks using the GetString Attr on the given field.
func SortByTime ¶
SortByTime returns a LessFn which orders Tracks using the GetTime Attr on the given field.
type Library ¶
type Library interface { // Tracks returns a slice of all the tracks in the library. Tracks() []Track // Track returns the track from the given identifier and true if successful, // false otherwise. Track(identifier string) (Track, bool) }
Library is an interface which defines methods for listing tracks.
type Path ¶
type Path []Key
Path is type which represents a position in the index heirarchy. Each level has a key, and so the path is a slice of strings where each element is the key of some index element (group or track).
func CollectionPaths ¶
func CollectionPaths(c Collection, root Path) []Path
CollectionPaths creates a slice of Paths which contains the path for each immediate Group in the Collection.
func OrderedIntersection ¶
OrderedIntersection computes the intersection of the given lists of paths.
func PathFromJSONInterface ¶
PathFromJSONInterface reconstructs a Path from the given JSON-parsed interface{}
func PathFromStringSlice ¶
PathFromStringSlice creates a path from the given []string.
func Recent ¶
func Recent(c Collection, n int) []Path
Recent returns a list of paths which are the n most recently added paths.
type PathSlice ¶
type PathSlice []Path
PathSlice is a wrapper type implementing sort.Interface (and index.Swapper).
type PersistStore ¶
type PersistStore string
PersistStore is a type which defines a simple persistence store.
func NewPersistStore ¶
func NewPersistStore(path string, data interface{}) (PersistStore, error)
NewPersistStore creates a new PersistStore. By default PersistStore uses JSON to persist data.
func (PersistStore) Persist ¶
func (p PersistStore) Persist(data interface{}) error
Persist writes the data to the underlying data store, overwriting any previous data.
type PrefixMultiExpand ¶
type PrefixMultiExpand struct {
// contains filtered or unexported fields
}
PrefixMultiExpand is a type which implements Expander
func BuildPrefixMultiExpander ¶
func BuildPrefixMultiExpander(words []string, n int) PrefixMultiExpand
BuildPrefixMultiExpander builds an Expander with given length n. All words mapped to by prefixes will have length greater than or equal to MinPrefix.
func (PrefixMultiExpand) Expand ¶
func (p PrefixMultiExpand) Expand(s string) []string
Expand uses the prefix mapping to return a list of words which can be expanded from s.
type Searcher ¶
type Searcher interface { // Search uses the given string to filter a list of paths. Search(string) []Path }
Searcher is an interface which defines the Search method.
func BuildPrefixExpandSearcher ¶
BuildPrefixExpandSearcher constructs a prefix expander which wraps the given Searcher by expanding each word in the search input using the WordIndex.
func WordsIntersectSearcher ¶
WordsSearchIntersect calls Search on the Searcher for each word in the input string and then returns the ordered intersection (Paths are ordered by the number of times they appear).
type Swaper ¶
type Swaper interface { // Swap the items at indices i and j. Swap(i, j int) }
Swapper is an interface which defines the Swap method.
type Track ¶
type Track interface { // GetString returns a string value for the given attribute name. Panics // if no such string attribute exists. GetString(string) string // GetStrings returns a list of strings for the given attribute name. // Panics if no such attribute exists. GetStrings(string) []string // GetInt returns an int value for the given attribute name. Panics if no such // attribute exists. GetInt(string) int // GetTime returns a time.Time value for the given attribute name. Panics if no // such attribute exists. GetTime(string) time.Time }
Track is an interface which defines methods for retrieving track metadata. Methods return zero values if attributes are unset and panic on undefined attributes and type mismatches.
type Tracker ¶
type Tracker interface {
Tracks() []Track
}
Tracker is an interface which defines the Tracks method which returns a list of Tracks.
type TransformFn ¶
TransformFn is a type which represents a function which Transforms a Group into another.
func SplitList ¶
func SplitList(fields ...string) TransformFn
SplitList returns a transform which splits lists of names in 'String' fields of Tracks into 'Strings' fields. The String values are split by ListSeparators.
type WalkFn ¶
WalkFn is the type of the function called for each Track visited by Walk. Return non-nil error from Walk to stop the trasversal, and return the error from Walk.
type WordIndex ¶
WordIndex is an interface which defines the Words method.
func BuildCollectionWordIndex ¶
func BuildCollectionWordIndex(c Collection, fields []string) WordIndex
BuildCollectionWordIndex creates a WordIndex using the given Collection, taking data from the given fields.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package attr defines types and helpers for accessing typed attributes.
|
Package attr defines types and helpers for accessing typed attributes. |
Package checklist defines a collection of types for managing index checklists.
|
Package checklist defines a collection of types for managing index checklists. |
Package cursor defines types for constructing play cursors.
|
Package cursor defines types for constructing play cursors. |
Package favourite defines methods for setting/getting favourites for paths and persisting this data.
|
Package favourite defines methods for setting/getting favourites for paths and persisting this data. |
Package history implements functionality for fetching/adding to play history.
|
Package history implements functionality for fetching/adding to play history. |
Package itl defines types and methods for creating a Tchaik library representation of an iTunes Library.
|
Package itl defines types and methods for creating a Tchaik library representation of an iTunes Library. |
Package playlist defines functionality for creating, manipulating and persisting playlists.
|
Package playlist defines functionality for creating, manipulating and persisting playlists. |
Package rating defines types and methods for setting/getting ratings for paths and persisting this data.
|
Package rating defines types and methods for setting/getting ratings for paths and persisting this data. |
Package walk implements a path walker which reads audio files under a path and constructs an index.Library from supported metadata tags (see github.com/dhowden/tag).
|
Package walk implements a path walker which reads audio files under a path and constructs an index.Library from supported metadata tags (see github.com/dhowden/tag). |