Compare commits
No commits in common. "4f527f374737c6f87464e59dc8e7d10d936ff5cd" and "e833af1ecc745abb4ebaf675dffb90de4cea9eec" have entirely different histories.
4f527f3747
...
e833af1ecc
@ -1,37 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestUnify(t *testing.T) {
|
|
||||||
if "foo" != Unify("foo") {
|
|
||||||
t.Errorf(`"foo" has to be untouched by unify`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo" != Unify("Foo") {
|
|
||||||
t.Errorf(`"Foo" needs to be lowercase after test`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo" != Unify(" Foo") {
|
|
||||||
t.Errorf(`The spaces need to be stripped`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo" != Unify(" Foo ") {
|
|
||||||
t.Errorf(`The spaces need to be stripped`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo bar" != Unify("Foo bar") {
|
|
||||||
t.Errorf(`Single whitespaces need to be left alone`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo bar" != Unify("Foo bar") {
|
|
||||||
t.Errorf(`Double whitespaces need to be removed`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo bar" != Unify("Foo bar") {
|
|
||||||
t.Errorf(`Double whitespaces need to be removed`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if "foo bar baz" != Unify("Foo bar baz") {
|
|
||||||
t.Errorf(`Double whitespaces need to be removed`)
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/music-kraken/internal/common"
|
"gitea.elara.ws/Hazel/music-kraken/internal/common"
|
||||||
|
"github.com/gohugoio/hugo/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MusicObject interface {
|
type MusicObject interface {
|
||||||
@ -105,7 +106,6 @@ func (m Song) Merge(other MusicObject) MusicObject {
|
|||||||
func (m Song) Compile() MusicObject {
|
func (m Song) Compile() MusicObject {
|
||||||
m.Sources = dedupeSources(m.Sources)
|
m.Sources = dedupeSources(m.Sources)
|
||||||
m.UnifiedName = common.Unify(m.Name)
|
m.UnifiedName = common.Unify(m.Name)
|
||||||
m.Album = m.Album.Compile().(Album)
|
|
||||||
m.Artists = dedupeMusicObjects(m.Artists)
|
m.Artists = dedupeMusicObjects(m.Artists)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSong(t *testing.T) {
|
|
||||||
song := Song{
|
|
||||||
Name: "song_a",
|
|
||||||
Album: Album{
|
|
||||||
Name: "album_a",
|
|
||||||
Artists: []Artist{
|
|
||||||
{Name: "artist_a"},
|
|
||||||
{Name: "artist_a"},
|
|
||||||
{Name: "artist_b"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Artists: []Artist{
|
|
||||||
{Name: "artist_a"},
|
|
||||||
{Name: "artist_a"},
|
|
||||||
{Name: "artist_b"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
compiled := song.Compile().(Song)
|
|
||||||
|
|
||||||
if len(compiled.Artists) != 2 {
|
|
||||||
t.Errorf(`the two artists with the same name have to be merged, %d`, len(compiled.Artists))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(compiled.Album.Artists) != 2 {
|
|
||||||
t.Errorf(`the two artists with the same names in the album have to be merged, %d`, len(compiled.Album.Artists))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,9 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
/*
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestYouTube(t *testing.T) {
|
func TestYouTube(t *testing.T) {
|
||||||
validUrls := []string{
|
validUrls := []string{
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||||
@ -65,4 +68,3 @@ func TestMusify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
@ -46,7 +46,6 @@ func compileSourceType(source data.Source) (data.Source, error) {
|
|||||||
for _, st := range nameSourceType {
|
for _, st := range nameSourceType {
|
||||||
if m := st.Regex.FindString(source.Url); m != "" {
|
if m := st.Regex.FindString(source.Url); m != "" {
|
||||||
source.Url = m
|
source.Url = m
|
||||||
source.SourceType = &st
|
|
||||||
return source, nil
|
return source, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,6 +84,22 @@ func compileSource(source data.Source) (data.Source, error) {
|
|||||||
return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url)
|
return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dedupeSources(sources []data.Source) []data.Source {
|
||||||
|
urls := map[string]interface{}{}
|
||||||
|
deduped := []data.Source{}
|
||||||
|
|
||||||
|
for _, raw := range sources {
|
||||||
|
parsed, _ := compileSource(raw)
|
||||||
|
|
||||||
|
if _, u := urls[parsed.Url]; !u {
|
||||||
|
urls[parsed.Url] = true
|
||||||
|
deduped = append(deduped, parsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deduped
|
||||||
|
}
|
||||||
|
|
||||||
func Fetch(source data.Source) (data.MusicObject, error) {
|
func Fetch(source data.Source) (data.MusicObject, error) {
|
||||||
// the fetch function without the post processing of the music objects
|
// the fetch function without the post processing of the music objects
|
||||||
source, err := compileSource(source)
|
source, err := compileSource(source)
|
||||||
@ -103,8 +118,7 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return song, err
|
return song, err
|
||||||
}
|
}
|
||||||
song.Sources = append(song.Sources, source)
|
song.Sources = dedupeSources(append(song.Sources, source))
|
||||||
song = song.Compile().(data.Song)
|
|
||||||
return song, nil
|
return song, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +128,7 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return album, err
|
return album, err
|
||||||
}
|
}
|
||||||
album.Sources = append(album.Sources, source)
|
album.Sources = dedupeSources(append(album.Sources, source))
|
||||||
album = album.Compile().(data.Album)
|
|
||||||
return album, nil
|
return album, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +138,7 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return artist, err
|
return artist, err
|
||||||
}
|
}
|
||||||
artist.Sources = append(artist.Sources, source)
|
artist.Sources = dedupeSources(append(artist.Sources, source))
|
||||||
artist = artist.Compile().(data.Artist)
|
|
||||||
return artist, nil
|
return artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,10 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func extractName(s string) string {
|
|
||||||
parts := strings.Split(s, "/")
|
|
||||||
lastPart := parts[len(parts)-1]
|
|
||||||
hyphenParts := strings.Split(lastPart, "-")
|
|
||||||
result := strings.Join(hyphenParts[:len(hyphenParts)-1], " ")
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
type Musify struct {
|
type Musify struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,24 +29,18 @@ 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) FetchSong(source data.Source) (data.Song, error) {
|
func (m *Musify) FetchArtist(source data.Source) (data.Artist, error) {
|
||||||
return data.Song{
|
panic("unimplemented")
|
||||||
Name: extractName(source.Url),
|
}
|
||||||
}, nil
|
|
||||||
}
|
func (m *Musify) FetchAlbum(source data.Source) (data.Album, error) {
|
||||||
|
panic("unimplemented")
|
||||||
func (m Musify) FetchAlbum(source data.Source) (data.Album, error) {
|
}
|
||||||
return data.Album{
|
|
||||||
Name: extractName(source.Url),
|
func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
||||||
}, nil
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Musify) FetchArtist(source data.Source) (data.Artist, error) {
|
func (m *Musify) Search(query string) ([]data.MusicObject, error) {
|
||||||
return data.Artist{
|
|
||||||
Name: extractName(source.Url),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Musify) Search(query string) ([]data.MusicObject, error) {
|
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
7
main.go
7
main.go
@ -4,14 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||||
"gitea.elara.ws/Hazel/music-kraken/internal/plugin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("music kraken")
|
fmt.Println("music kraken")
|
||||||
|
fmt.Println(data.Source{}.SourceType == nil)
|
||||||
plugin.RegisterPlugin(plugin.Musify{})
|
|
||||||
fmt.Println(plugin.Fetch(data.Source{
|
|
||||||
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user