From b7f5ed4e5fcb3b51636a9dad79e7e80f7ebbb102 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 23 Dec 2022 08:51:37 +0100 Subject: implement local storage backend The 'local' backend is able to serve the music from a path specified by '-server-music-dir'. Add command line options to select the server port as well as a list of backends. --- backend.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 backend.go (limited to 'backend.go') diff --git a/backend.go b/backend.go new file mode 100644 index 0000000..9cb42f8 --- /dev/null +++ b/backend.go @@ -0,0 +1,29 @@ +package main + +import ( + "crypto/sha1" + "encoding/base64" +) + +type Backend interface { + Play(song *Song, player *Player) + Search(keyword string) []Song +} + +type DummyBackend struct{} + +func (dummy *DummyBackend) Play(song *Song, player *Player) { +} + +func (dummy *DummyBackend) Search(keyword string) []Song { + + s := NewDummySong("Dummy Mc Crashtest", "exactly "+keyword) + return []Song{s} +} + +func NewDummySong(title, artist string) Song { + h := sha1.New() + h.Write([]byte(title)) + h.Write([]byte(artist)) + return NewSong(title, artist, "dummy", base64.URLEncoding.EncodeToString(h.Sum(nil))) +} -- cgit v1.2.3