index

package
v0.0.0-...-2070705 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2015 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package group defines the concept of a group which is an ordered list of playable items

Package index defines functionality for creating and manipulating a Tchaik music index.

Index

Constants

View Source
const MinPrefix = 3

MinPrefix is the minimum number of characters that can be used in a prefix.

View Source
const PathSeparator string = ":"

Path separator is a string used to separate path components.

Variables

This section is empty.

Functions

func BuildWordIndex

func BuildWordIndex(c Collection, fields []string) *wordIndex

BuildWordIndex creates a *wordIndex ()

func Convert

func Convert(l Library, id string) *library

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 TrackID on every track, regardless of whether this value has already been set in the input Library.

func ParallelSort

func ParallelSort(s sort.Interface, w Swaper) sort.Interface

ParallelSort combines a sort.Interface implementation with a Swaper, and performs the same swap operations to w as they are applied to s.

func Sort

func Sort(tracks []Track, f LessFn)

Sort sorts the slice of tracks using the given LessFn.

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.

func Walk

func Walk(g Group, p Path, f WalkFn)

Walk transverses the Group g and calls the WalkFn f on each Track.

func WriteTo

func WriteTo(l Library, w io.Writer) error

WriteTo writes the Library data to the writer, currently using gzipped-JSON.

Types

type Attr

type Attr struct {
	// contains filtered or unexported fields
}

Attr is a type which wraps a closure to get an attribute from an implementation of the Attr interface.

func IntAttr

func IntAttr(field string) Attr

IntAttr constructs a Attr which will retrieve the int field from an implementation of Attr.

func StringAttr

func StringAttr(field string) Attr

StringAttr constructs a Attr which will retrieve the string field from an implementation of Attr.

func (Attr) Empty

func (g Attr) Empty() interface{}

Empty returns the empty value of the underlying field (the empty value of the field type).

func (Attr) Field

func (g Attr) Field() string

Field returns the underlying field name.

type ByAttr

type ByAttr Attr

ByAttr is a type which implements Collector, and groups elements by the value of the attribute given by the underlying Attr instance.

func (ByAttr) Collect

func (a ByAttr) Collect(tracker Tracker) Collection

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

NewCollection creates a new collection from a source collection `c` which will have the groups represented by the given list of paths. All the paths are assumed to be unique, an of at least length 2.

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, returning the result and true if succesful, or false
	// otherwise.
	Expand(string) ([]string, bool)
}

Expander is an interface which implements the Expand method.

type FilterItem

type FilterItem interface {
	Name() string
	Fields() map[string]interface{}
	Paths() []Path
}

func Filter

func Filter(c Collection, field string) []FilterItem

type FilterItemSlice

type FilterItemSlice []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

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

func CommonGroupAttr(attrs []Attr, g Group) Group

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

func FirstTrackAttr(attr Attr, g Group) Group

FirstTrackAttr wraps the given Group adding a string field `field` with the value taken from the first track.

func RemoveEmptyCollections

func RemoveEmptyCollections(g Group) Group

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

func SumGroupIntAttr(field string, g Group) Group

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

func TrimEnumPrefix(g Group) Group

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

type Key

type Key string

Key represents a unique value used to represent a group within a collection.

func (Key) String

func (k Key) String() string

String returns the string representation of the key.

type LessFn

type LessFn func(s, t Track) bool

LessFn is a function type used for evaluating

func MultiSort

func MultiSort(fns ...LessFn) LessFn

MultiSort creates a LessFn for tracks using the given LessFns.

func SortByInt

func SortByInt(field string) LessFn

SortByInt returns a LessFn which orders Tracks using the GetInt Attr on the given field.

func SortByString

func SortByString(field string) LessFn

SortByString returns a LessFn which orders Tracks using the GetString Attr on the given field.

func SortByTime

func SortByTime(field string) LessFn

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, second return value true
	// if successful.
	Track(identifier string) (Track, bool)
}

Library is an interface which defines methods for listing tracks.

func ReadFrom

func ReadFrom(r io.Reader) (Library, error)

ReadFrom reads the gzipped-JSON representation of a Library.

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 OrderedIntersection

func OrderedIntersection(paths ...[]Path) []Path

Compute the intersection of the given lists of paths.

func Recent

func Recent(c Collection, n int) []Path

func Union

func Union(l ...[]Path) []Path

Union returns a []Path which is the union (deduped) of the given slices of []Path.

func (Path) Encode

func (p Path) Encode() string

Encode returns a string representation of the Path.

func (Path) String

func (p Path) String() string

String implements Stringer.

type PathSlice

type PathSlice []Path

PathSlice is a wrapper type implementing sort.Interface (and index.Swapper)

func (PathSlice) Len

func (p PathSlice) Len() int

Len implements sort.Interface.

func (PathSlice) Less

func (p PathSlice) Less(i, j int) bool

Less implements sort.Interface.

func (PathSlice) Swap

func (p PathSlice) Swap(i, j int)

Swap implements sort.Interface (and index.Swapper).

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, bool)

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

func BuildPrefixExpandSearcher(s Searcher, w WordIndex, n int) Searcher

BuildPrefixExpandSearcher constructs a prefix expander which wraps the given Searcher by expanding each word in the search input using the WordIndex.

func WordsIntersectSearcher

func WordsIntersectSearcher(s Searcher) Searcher

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 the string attribute with given name.
	GetString(string) string
	// GetInt returns the int attribute with given name.
	GetInt(string) int
	// GetTime returns the time attribute with given name.
	GetTime(string) time.Time
}

Track is an interface which defines a music file.

type Tracker

type Tracker interface {
	Tracks() []Track
}

Tracker is an interface which defines the Tracks method which returns a list of Tracks.

type TransformFn

type TransformFn func(Group) Group

TransformFn is a type which represents a function which Transforms a Group into another.

type WalkFn

type WalkFn func(Track, Path)

WalkFn is the type of the function called for each Track visited by Walk.

type WordIndex

type WordIndex interface {
	// Words returns all the words in the index.
	Words() []string
}

WordIndex is an interface which defines the Words method.

Directories

Path Synopsis
Package history implements functionality for fetching/adding to play history.
Package history implements functionality for fetching/adding to play history.
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).

Jump to

Keyboard shortcuts

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