diff --git a/internal/data/source.go b/internal/data/source.go index f548340..14edf66 100644 --- a/internal/data/source.go +++ b/internal/data/source.go @@ -12,6 +12,7 @@ type SourceType struct { var SourceTypes = []SourceType{ {Name: "Youtube", Regex: *regexp.MustCompile(`(?i)\b(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})\b`)}, + {Name: "Musify", Regex: *regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)}, } func GetSourceType(name string) *SourceType { diff --git a/internal/data/source_test.go b/internal/data/source_test.go index 1d3f7b4..e363d28 100644 --- a/internal/data/source_test.go +++ b/internal/data/source_test.go @@ -38,3 +38,33 @@ func TestYouTube(t *testing.T) { } } } + +func TestMusify(t *testing.T) { + validUrls := []string{ + "https://musify.club/artist/plohoyparen-645023", + "https://musify.club/track/plohoyparen-obgon-dve-sploshnie-poh-voobshe-9769231", + "https://musify.club/release/plohoyparen-hello-my-name-2018-1029885", + "https://musify.clUb/Release/plohoyParen-hello-my-name-2018-1029885", + } + invalidUrls := []string{ + "https://musify.club/", + "https://musify.club/not-data-type", + "https://m.youtube.com/watch?v=dQw4w9WgXcQ", + } + + st := GetSourceType("Musify") + + for _, u := range validUrls { + _, err := st.NewSource(u) + if err != nil { + t.Errorf(`%q is a valid musify url`, u) + } + } + + for _, u := range invalidUrls { + _, err := st.NewSource(u) + if err == nil { + t.Errorf(`%q is an invalid musify url`, u) + } + } +}