-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
library.go
91 lines (69 loc) 路 2.77 KB
/
library.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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.
package library
// SearchResult contains a result for a search term. Contains all the neccessery
// information to uniquely identify a media in the library.
type SearchResult struct {
// ID in the library for a media file
ID int64 `json:"id"`
// Meta info: Artist ID
ArtistID int64 `json:"artist_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"`
// File format of the underlying data file. Examples: "mp3", "flac", "ogg" etc.
Format string `json:"format"`
// Duration is the track length in milliseconds.
Duration int64 `json:"duration"`
}
// Artist represents an artist from the database
type Artist struct {
ID int64 `json:"artist_id"`
Name string `json:"artist"`
}
// Album represents an album from the database
type Album struct {
ID int64 `json:"album_id"`
Name string `json:"album"`
Artist string `json:"artist"`
}
// 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 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 matches 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 full library scan. Will scan all paths if
// they are not scanned already.
Scan()
// 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()
}