allowing pointer
This commit is contained in:
parent
8587bdf360
commit
a99dee5104
@ -23,7 +23,7 @@ func printResults(musicObjects []data.MusicObject) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Shell() {
|
func Shell() {
|
||||||
plugin.RegisterPlugin(plugin.Musify{})
|
plugin.RegisterPlugin(&plugin.Musify{})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Print("> ")
|
fmt.Print("> ")
|
||||||
|
@ -15,6 +15,8 @@ type Plugin interface {
|
|||||||
RegexAlbum() *regexp.Regexp
|
RegexAlbum() *regexp.Regexp
|
||||||
RegexSong() *regexp.Regexp
|
RegexSong() *regexp.Regexp
|
||||||
|
|
||||||
|
Init()
|
||||||
|
|
||||||
Search(query common.Query) ([]data.MusicObject, error)
|
Search(query common.Query) ([]data.MusicObject, error)
|
||||||
|
|
||||||
FetchArtist(source data.Source) (data.Artist, error)
|
FetchArtist(source data.Source) (data.Artist, error)
|
||||||
|
@ -35,10 +35,20 @@ func (m Musify) RegexAlbum() *regexp.Regexp {
|
|||||||
return regexp.MustCompile(`(?i)https?://musify\.club/release/[a-z\-0-9]+`)
|
return regexp.MustCompile(`(?i)https?://musify\.club/release/[a-z\-0-9]+`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Musify) Init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (m Musify) RegexSong() *regexp.Regexp {
|
func (m Musify) RegexSong() *regexp.Regexp {
|
||||||
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
|
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Musify) Search(query common.Query) ([]data.MusicObject, error) {
|
||||||
|
res := []data.MusicObject{}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m Musify) FetchSong(source data.Source) (data.Song, error) {
|
func (m Musify) FetchSong(source data.Source) (data.Song, error) {
|
||||||
return data.Song{
|
return data.Song{
|
||||||
Name: extractName(source.Url),
|
Name: extractName(source.Url),
|
||||||
@ -56,7 +66,3 @@ func (m Musify) FetchArtist(source data.Source) (data.Artist, error) {
|
|||||||
Name: extractName(source.Url),
|
Name: extractName(source.Url),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Musify) Search(query common.Query) ([]data.MusicObject, error) {
|
|
||||||
return []data.MusicObject{}, nil
|
|
||||||
}
|
|
||||||
|
@ -40,6 +40,10 @@ func (m MusifyTest) RegexSong() *regexp.Regexp {
|
|||||||
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
|
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MusifyTest) Init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (m MusifyTest) FetchSong(source data.Source) (data.Song, error) {
|
func (m MusifyTest) FetchSong(source data.Source) (data.Song, error) {
|
||||||
return data.Song{
|
return data.Song{
|
||||||
Name: extractNameTest(source.Url),
|
Name: extractNameTest(source.Url),
|
||||||
@ -63,11 +67,11 @@ func (m MusifyTest) Search(query common.Query) ([]data.MusicObject, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRegister(t *testing.T) {
|
func TestRegister(t *testing.T) {
|
||||||
if RegisterPlugin(MusifyTest{}) != nil {
|
if RegisterPlugin(&MusifyTest{}) != nil {
|
||||||
t.Errorf(`registering first plugin shouldn't return an error`)
|
t.Errorf(`registering first plugin shouldn't return an error`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if RegisterPlugin(MusifyTest{}) == nil {
|
if RegisterPlugin(&MusifyTest{}) == nil {
|
||||||
t.Errorf(`registering same plugin twice should return an error`)
|
t.Errorf(`registering same plugin twice should return an error`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +85,7 @@ func TestRegister(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchSong(t *testing.T) {
|
func TestFetchSong(t *testing.T) {
|
||||||
RegisterPlugin(MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
s, err := Fetch(data.Source{
|
s, err := Fetch(data.Source{
|
||||||
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
|
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
|
||||||
@ -102,7 +106,7 @@ func TestFetchSong(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchAlbum(t *testing.T) {
|
func TestFetchAlbum(t *testing.T) {
|
||||||
RegisterPlugin(MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
a, err := Fetch(data.Source{
|
a, err := Fetch(data.Source{
|
||||||
Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188",
|
Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188",
|
||||||
@ -123,7 +127,7 @@ func TestFetchAlbum(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchArtist(t *testing.T) {
|
func TestFetchArtist(t *testing.T) {
|
||||||
RegisterPlugin(MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
a, err := Fetch(data.Source{
|
a, err := Fetch(data.Source{
|
||||||
Url: "https://musify.club/artist/linkin-park-5",
|
Url: "https://musify.club/artist/linkin-park-5",
|
||||||
@ -144,7 +148,7 @@ func TestFetchArtist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchWrongUrl(t *testing.T) {
|
func TestFetchWrongUrl(t *testing.T) {
|
||||||
RegisterPlugin(MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
_, err := Fetch(data.Source{
|
_, err := Fetch(data.Source{
|
||||||
Url: "https://musify.club/",
|
Url: "https://musify.club/",
|
||||||
@ -156,7 +160,7 @@ func TestFetchWrongUrl(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNonExistentSourceType(t *testing.T) {
|
func TestNonExistentSourceType(t *testing.T) {
|
||||||
RegisterPlugin(MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
_, err := Fetch(data.Source{
|
_, err := Fetch(data.Source{
|
||||||
Url: "https://musify.club/",
|
Url: "https://musify.club/",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user