added compile to fetch
This commit is contained in:
parent
f1b075f47b
commit
b65d68ed86
@ -46,6 +46,7 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,22 +85,6 @@ 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)
|
||||||
@ -118,7 +103,8 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return song, err
|
return song, err
|
||||||
}
|
}
|
||||||
song.Sources = dedupeSources(append(song.Sources, source))
|
song.Sources = append(song.Sources, source)
|
||||||
|
song = song.Compile().(data.Song)
|
||||||
return song, nil
|
return song, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +114,8 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return album, err
|
return album, err
|
||||||
}
|
}
|
||||||
album.Sources = dedupeSources(append(album.Sources, source))
|
album.Sources = append(album.Sources, source)
|
||||||
|
album = album.Compile().(data.Album)
|
||||||
return album, nil
|
return album, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +125,8 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return artist, err
|
return artist, err
|
||||||
}
|
}
|
||||||
artist.Sources = dedupeSources(append(artist.Sources, source))
|
artist.Sources = append(artist.Sources, source)
|
||||||
|
artist = artist.Compile().(data.Artist)
|
||||||
return artist, nil
|
return artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,19 @@ 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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,18 +38,24 @@ 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) FetchArtist(source data.Source) (data.Artist, error) {
|
func (m Musify) FetchSong(source data.Source) (data.Song, error) {
|
||||||
panic("unimplemented")
|
return data.Song{
|
||||||
|
Name: extractName(source.Url),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Musify) FetchAlbum(source data.Source) (data.Album, error) {
|
func (m Musify) FetchAlbum(source data.Source) (data.Album, error) {
|
||||||
panic("unimplemented")
|
return data.Album{
|
||||||
|
Name: extractName(source.Url),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
func (m Musify) FetchArtist(source data.Source) (data.Artist, error) {
|
||||||
panic("unimplemented")
|
return data.Artist{
|
||||||
|
Name: extractName(source.Url),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Musify) Search(query string) ([]data.MusicObject, error) {
|
func (m Musify) Search(query string) ([]data.MusicObject, error) {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
7
main.go
7
main.go
@ -4,9 +4,14 @@ 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