From a99dee51045c8b56f9aa856ae8fd6c5ac9c62329 Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Wed, 8 Oct 2025 10:32:43 +0200 Subject: [PATCH] allowing pointer --- internal/cli/shell.go | 2 +- internal/plugin/interface.go | 2 ++ internal/plugin/musify.go | 14 ++++++++++---- internal/plugin/plugin_test.go | 18 +++++++++++------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/internal/cli/shell.go b/internal/cli/shell.go index f3e1fe9..16eb941 100644 --- a/internal/cli/shell.go +++ b/internal/cli/shell.go @@ -23,7 +23,7 @@ func printResults(musicObjects []data.MusicObject) { } func Shell() { - plugin.RegisterPlugin(plugin.Musify{}) + plugin.RegisterPlugin(&plugin.Musify{}) for { fmt.Print("> ") diff --git a/internal/plugin/interface.go b/internal/plugin/interface.go index 95c91c8..8e936f9 100644 --- a/internal/plugin/interface.go +++ b/internal/plugin/interface.go @@ -15,6 +15,8 @@ type Plugin interface { RegexAlbum() *regexp.Regexp RegexSong() *regexp.Regexp + Init() + Search(query common.Query) ([]data.MusicObject, error) FetchArtist(source data.Source) (data.Artist, error) diff --git a/internal/plugin/musify.go b/internal/plugin/musify.go index e9e072c..9276a7b 100644 --- a/internal/plugin/musify.go +++ b/internal/plugin/musify.go @@ -35,10 +35,20 @@ func (m Musify) RegexAlbum() *regexp.Regexp { return regexp.MustCompile(`(?i)https?://musify\.club/release/[a-z\-0-9]+`) } +func (m *Musify) Init() { + +} + func (m Musify) RegexSong() *regexp.Regexp { 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) { return data.Song{ Name: extractName(source.Url), @@ -56,7 +66,3 @@ func (m Musify) FetchArtist(source data.Source) (data.Artist, error) { Name: extractName(source.Url), }, nil } - -func (m Musify) Search(query common.Query) ([]data.MusicObject, error) { - return []data.MusicObject{}, nil -} diff --git a/internal/plugin/plugin_test.go b/internal/plugin/plugin_test.go index f41ad98..f466d35 100644 --- a/internal/plugin/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -40,6 +40,10 @@ func (m MusifyTest) RegexSong() *regexp.Regexp { 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) { return data.Song{ Name: extractNameTest(source.Url), @@ -63,11 +67,11 @@ func (m MusifyTest) Search(query common.Query) ([]data.MusicObject, error) { } func TestRegister(t *testing.T) { - if RegisterPlugin(MusifyTest{}) != nil { + if RegisterPlugin(&MusifyTest{}) != nil { 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`) } @@ -81,7 +85,7 @@ func TestRegister(t *testing.T) { } func TestFetchSong(t *testing.T) { - RegisterPlugin(MusifyTest{}) + RegisterPlugin(&MusifyTest{}) s, err := Fetch(data.Source{ 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) { - RegisterPlugin(MusifyTest{}) + RegisterPlugin(&MusifyTest{}) a, err := Fetch(data.Source{ 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) { - RegisterPlugin(MusifyTest{}) + RegisterPlugin(&MusifyTest{}) a, err := Fetch(data.Source{ Url: "https://musify.club/artist/linkin-park-5", @@ -144,7 +148,7 @@ func TestFetchArtist(t *testing.T) { } func TestFetchWrongUrl(t *testing.T) { - RegisterPlugin(MusifyTest{}) + RegisterPlugin(&MusifyTest{}) _, err := Fetch(data.Source{ Url: "https://musify.club/", @@ -156,7 +160,7 @@ func TestFetchWrongUrl(t *testing.T) { } func TestNonExistentSourceType(t *testing.T) { - RegisterPlugin(MusifyTest{}) + RegisterPlugin(&MusifyTest{}) _, err := Fetch(data.Source{ Url: "https://musify.club/",