library

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package library deals with the actual media library. It is creates the Library type.

Every media receives an ID in the library. The main thing a search result returns is the tracks' IDs. They are used to get the media, again using the Library. That way the real location of the file is never revealed to the interface.

Index

Constants

View Source
const UnknownLabel = "Unknown"

UnknownLabel will be used in case some media tag is missing. As a consequence if there are many files with missing title, artist and album only one of them will be saved in the library.

Variables

View Source
var (
	// LibraryFastScan is a flag, populated by the -fast-library-scan argument.
	//
	// When `false` (the default), scanning the local library will honour the
	// configuration for occasional sleeping while scanning the file system.
	//
	// When `true`, scanning will be as fast as possible. This may generate high
	// IO load for the duration of the scan.
	LibraryFastScan bool
)

Functions

This section is empty.

Types

type Library

type Library interface {

	// Adds a new path to the library paths. If it hasn't been scanned yet a new scan
	// will be started.
	AddLibraryPath(string)

	// Search the library using a search string. It will match against Artist, Album
	// and Title. Will OR the results. So it is "return anything which Artist maches or
	// Album matches or Title matches"
	Search(string) []SearchResult

	// Returns the real filesystem path. Requires the media ID.
	GetFilePath(int64) string

	// Returns search result will all the files of this album
	GetAlbumFiles(int64) []SearchResult

	// Starts a background library scan. Will scan all paths if
	// they are not scanned already. Will return immediately.
	Scan()

	// Will sync with the Scan's end
	WaitScan()

	// Adds this media (file) to the library
	AddMedia(string) error

	// Makes sure the library is initialied. This method will be called once on
	// every start of the httpms
	Initialize() error

	// Makes the library forget everything. Also Closes the library.
	Truncate() error

	// Frees all resources this library object is using.
	// Any operations (except Truncate) on closed library will result in panic.
	Close()
}

Library represents the media library which is played using the HTTPMS. It is responsible for scaning the library directories, watching for new files, actually searching for a media by a search term and finding the exact file path in the file system for a media.

type LocalLibrary

type LocalLibrary struct {
	// The configuration for how to scan the libraries.
	ScanConfig config.ScanSection
	// contains filtered or unexported fields
}

LocalLibrary implements the Library interface. Will represent files found on the local storage

func NewLocalLibrary

func NewLocalLibrary(databasePath string) (*LocalLibrary, error)

NewLocalLibrary returns a new LocalLibrary which will use for database the file specified by databasePath. Also creates the database connection so you does not need to worry about that.

func (*LocalLibrary) AddLibraryPath

func (lib *LocalLibrary) AddLibraryPath(path string)

AddLibraryPath adds a library directory to the list of libraries which will be scanned and consequently watched.

func (*LocalLibrary) AddMedia

func (lib *LocalLibrary) AddMedia(filename string) error

AddMedia adds a file specified by its filesystem name to the library. Will create the needed Artist, Album if neccessery.

func (*LocalLibrary) Close

func (lib *LocalLibrary) Close()

Close closes the database connection. It is safe to call it as many times as you want.

func (*LocalLibrary) GetAlbumFiles

func (lib *LocalLibrary) GetAlbumFiles(albumID int64) []SearchResult

GetAlbumFiles satisfies the Library interface

func (*LocalLibrary) GetAlbumID

func (lib *LocalLibrary) GetAlbumID(album string, artistID int64) (int64, error)

GetAlbumID returns the id for this artist's album. When missing or on error returns that error.

func (*LocalLibrary) GetArtistID

func (lib *LocalLibrary) GetArtistID(artist string) (int64, error)

GetArtistID returns the id for this artist. When missing or on error returns that error.

func (*LocalLibrary) GetFilePath

func (lib *LocalLibrary) GetFilePath(ID int64) string

GetFilePath returns the filsystem path for a file specified by its ID.

func (*LocalLibrary) GetTrackID

func (lib *LocalLibrary) GetTrackID(title string,
	artistID, albumID int64) (int64, error)

GetTrackID returns the id for this track. When missing or on error returns that error.

func (*LocalLibrary) Initialize

func (lib *LocalLibrary) Initialize() error

Initialize should be run once every time a library is created. It checks for the sqlite database file and creates one if it is absent. If a file is found it does nothing.

func (*LocalLibrary) MediaExistsInLibrary

func (lib *LocalLibrary) MediaExistsInLibrary(filename string) bool

MediaExistsInLibrary checks if the media file with file system path "filename" has been added to the library already.

func (*LocalLibrary) Scan

func (lib *LocalLibrary) Scan()

Scan scans all of the folders in paths for media files. New files will be added to the database. !TODO: make scan also remove files which have been deleted since the previous scan

func (*LocalLibrary) Search

func (lib *LocalLibrary) Search(searchTerm string) []SearchResult

Search searches in the library. Will match against the track's name, artist and album.

func (*LocalLibrary) Truncate

func (lib *LocalLibrary) Truncate() error

Truncate Closes the library and removes its database file leaving no traces at all.

func (*LocalLibrary) WaitScan

func (lib *LocalLibrary) WaitScan()

WaitScan blocks the current goroutine until the scan has been finished

type MediaFile added in v1.0.2

type MediaFile interface {

	// Artist returns a string which represents the artist resposible for this media file
	Artist() string

	// Album returns a string for the name of the album this media file is part of
	Album() string

	// Title returns the name of this piece of media
	Title() string

	// Track returns the media track number in its album
	Track() int

	// Length returns the duration of this pirce of media
	Length() time.Duration
}

MediaFile is an interface which a media object should satisfy in order to be insertable in the library database.

type SearchResult

type SearchResult struct {

	// ID in the library for a media file
	ID int64 `json:"id"`

	// Meta info: Artist
	Artist string `json:"artist"`

	// Meta info: Album ID
	AlbumID int64 `json:"album_id"`

	// Meta info: Album for music
	Album string `json:"album"`

	// Meta info: the title of this media file
	Title string `json:"title"`

	// Meta info: track number for music
	TrackNumber int64 `json:"track"`
}

SearchResult contains a result for a search term. Contains all the neccessery information to uniquely identify a media in the library.

Jump to

Keyboard shortcuts

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