library

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package library provides the core implementation of `fakelib`. It implements the "library" abstraction, and a song reader that proxies to a golden MP3.

Typical Usage:

import (
    "os"
    "log"

    "github.com/joshkunz/fakelib"
)

f, err := os.Open("gold.mp3")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

lib, err := library.New(f)
if err != nil {
    log.Fatal(err)
}

// Access any songs/paths you want...

s := lib.SongAt(0)
s.Read(...)
s.Size()

A mountable file-system can be found in github.com/joshkunz/fakelib/filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArtistAlbumTitle added in v0.0.3

func ArtistAlbumTitle(index int, tag *id3v2.Tag) string

ArtistAlbumTitle implements PathFunc. The generated path follows a typical <artist>/<album>/<title>.mp3 pattern for the song's title.

func EmbeddedGoldMP3 added in v0.0.8

func EmbeddedGoldMP3() io.ReadSeeker

EmbeddedGoldMP3 returns a ReadSeeker for a golden MP3 file suitable for passing to library.New(). The returned golden MP3 should consist of 5s of silence.

Types

type Library

type Library struct {
	// Total number of tracks in the fake library.
	Tracks int

	// Tagger is invoked to retrieve the tags for the song at each index
	// position (0-based).
	Tagger TagFunc
	// Pather is invoked to generate the path for the song at each index. It
	// is also passed the tag generated by the Tagger.
	Pather PathFunc
	// contains filtered or unexported fields
}

Library represents a fake library of songs. A single "golden" MP3 is used as the basis for every track in the library, and song metadata is generated on a per-track basis. A new library can be created with `New`. The number of tracks, and the structure of the library can be controlled via member variables.

func New

func New(golden io.ReadSeeker) (*Library, error)

New returns a new Library that uses Golden data read from the given golden reader.

func (*Library) PathAt

func (l *Library) PathAt(idx int) (string, error)

PathAt returns the path to the idx-th song in the library.

func (*Library) SongAt

func (l *Library) SongAt(idx int) (Song, error)

SongAt returns the song at the idx-th spot in the library.

type PathFunc added in v0.0.3

type PathFunc func(index int, tag *id3v2.Tag) string

PathFunc is a function that generates the path for a particular song with the given index and tag.

type RepeatedLetters added in v0.0.3

type RepeatedLetters struct {
	TracksPerAlbum  int
	AlbumsPerArtist int

	// The minimum length of a component. Components are repeated to extend
	// this value. Defaults to 1 if unset.
	MinComponentLength int
}

RepeatedLetters implements a tagger to generate track metadata using repeated letters. Each component is some number of characters from A-Z. Artists/Albums/Tracks are named in-order, starting at 0. So track 0 is

Artist: A, Album: A, Title: A

Track 1 is:

Artist: A, Album: A, Title: B

etc.

When MinComponentLength is set, track components are duplicated to extend the length of the path, while maintaining uniqueness. E.g., when MinComponentLength = 2, Track 0 is:

Artist: AA, Album: AA, Title: AA

When all letters have been exhausted in a category, the name is extended following a "spreadsheet" schema: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... When MinComponentLength is set, the repeated name is extended. So when MinComponentLength = 2, "AB" becomes "ABAB".

func (RepeatedLetters) Tag added in v0.0.3

func (a RepeatedLetters) Tag(idx int) *id3v2.Tag

Tag implements TagFunc to generate an id3v2 tag for a song at each index.

type Song

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

Song is the type of a song in the library. It can be generated via Library.SongAt().

func (Song) Read

func (s Song) Read(buf []byte, off int64)

Read reads bytes from this song into the buffer `buf` starting at byte `off` in the song. All data is read from memory, so this operation cannot fail.

func (Song) Size

func (s Song) Size() int64

Size is the size in bytes of this song.

type TagFunc added in v0.0.3

type TagFunc func(index int) *id3v2.Tag

TagFunc is a function that generates the tag for the song at the given index in the library.

Jump to

Keyboard shortcuts

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