aboutsummaryrefslogtreecommitdiff
path: root/backend.go
blob: 0d82e7fae335674a421ca2b62013f66294a4b319 (plain)
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
package main

import (
	"crypto/sha1"
	"encoding/base64"
)

type Backend interface {
	Play(song *Song, player *Player)
	Search(keyword string) []Song
	OnSongFinished(song *Song)
}

type DummyBackend struct{}

func (dummy *DummyBackend) Play(song *Song, player *Player) {}
func (dummy *DummyBackend) OnSongFinished(song *Song)       {}
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)))
}