library

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2014 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

This module 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 UNKNOWN_LABEL = "Unknown"

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

This section is empty.

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 whcih 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()
}

This type 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 {
	// contains filtered or unexported fields
}

Implements the Library interface. Will represent files found on the local storage

func NewLocalLibrary

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

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)

func (*LocalLibrary) AddMedia

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

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

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

Satisfies the Library interface

func (*LocalLibrary) GetAlbumID

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

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)

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

func (*LocalLibrary) GetFilePath

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

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)

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

func (*LocalLibrary) Initialize

func (lib *LocalLibrary) Initialize() error

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

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

func (*LocalLibrary) Scan

func (lib *LocalLibrary) Scan()

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

func (*LocalLibrary) Search

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

Does a search in the library. Will match against the track's name, artist and album.

func (*LocalLibrary) Truncate

func (lib *LocalLibrary) Truncate() error

func (*LocalLibrary) WaitScan

func (lib *LocalLibrary) WaitScan()

Blocks the current goroutine until the scan has been finished

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"`
}

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