index

package
v0.0.0-...-a380f54 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

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 = ":"

PathSeparator is a string used to separate path components.

Variables

View Source
var ListSeparators = []string{"/", ",", ";", ":", "&", " and ", " - ", " And "}

ListSepeartors is the list of strings used to separate String fields into 'Strings' fields.

Functions

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

func DefaultGetStrings

func DefaultGetStrings(t Track, f string) []string

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

func IndexOfPath(paths []Path, p Path) int

IndexOfPath returns the index of the path within the slice of paths, or -1 if the path isn't present.

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

Walk transverses the Group and calls the WalkFn on each Track. The Path is assumed to be the path of the Group.

func WriteTo

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

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

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.

func By

func By(a attr.Interface) Collector

By is a function which returns a Collector to group a collection using the given attribute.

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

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

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

func CommonGroupAttr(a []attr.Interface, 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(a attr.Interface, g Group) Group

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

func GroupFromPath

func GroupFromPath(g Group, p Path) (Group, error)

GroupFromPath returns the Group which represents the given Path.

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

func TrimTrackNumPrefix

func TrimTrackNumPrefix(g Group) Group

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.

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 and true if successful,
	// false otherwise.
	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 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 NewPath

func NewPath(x string) Path

NewPath creates a Path from the string representation.

func OrderedIntersection

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

OrderedIntersection computes the intersection of the given lists of paths.

func PathFromJSONInterface

func PathFromJSONInterface(raw interface{}) (Path, error)

PathFromJSONInterface reconstructs a Path from the given JSON-parsed interface{}

func PathFromStringSlice

func PathFromStringSlice(s []string) Path

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.

func Union

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

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

func (Path) Contains

func (p Path) Contains(q Path) bool

Contains returns true iff q is contained within p.

func (Path) Encode

func (p Path) Encode() string

Encode returns a string representation of the Path, that is a PathSeparator'ed string where each component is a Key from the Path.

func (Path) Equal

func (p Path) Equal(q Path) bool

Equal returns true iff q is Equal to p.

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

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

type TransformFn func(Group) Group

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

type WalkFn func(Track, Path) error

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

type WordIndex interface {
	Searcher

	// Words returns all the words in the index.
	Words() []string
}

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.

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

Jump to

Keyboard shortcuts

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