draft
This commit is contained in:
parent
fefa69e92a
commit
62cb5259ac
@ -7,12 +7,12 @@ import (
|
|||||||
|
|
||||||
type SourceType struct {
|
type SourceType struct {
|
||||||
Name string
|
Name string
|
||||||
Regex regexp.Regexp
|
Regex *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
var SourceTypes = []SourceType{
|
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: "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]+`)},
|
{Name: "Musify", Regex: regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)},
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSourceType(name string) *SourceType {
|
func GetSourceType(name string) *SourceType {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
GetRegex() regexp.Regexp
|
Name() string
|
||||||
|
GetRegex() *regexp.Regexp
|
||||||
|
|
||||||
Search(query string) []data.MusicObject
|
Search(query string) []data.MusicObject
|
||||||
|
|
||||||
@ -18,20 +18,41 @@ type Plugin interface {
|
|||||||
FetchArtist(source data.Source) data.Artist
|
FetchArtist(source data.Source) data.Artist
|
||||||
}
|
}
|
||||||
|
|
||||||
var plugins map[string]Plugin = make(map[string]Plugin)
|
var namePlugins = map[string]Plugin{}
|
||||||
|
var nameSourceType = map[string]data.SourceType{}
|
||||||
|
|
||||||
func AddPlugin(plugin Plugin) {
|
func RegisterPlugin(plugin Plugin) {
|
||||||
name := reflect.TypeOf(plugin).Name()
|
name := plugin.Name()
|
||||||
|
|
||||||
sourceType := data.SourceType{
|
nameSourceType[name] = data.SourceType{
|
||||||
Name: reflect.TypeOf(plugin).Name(),
|
Name: name,
|
||||||
Regex: plugin.GetRegex(),
|
Regex: plugin.GetRegex(),
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins[name] = pluginStorage{
|
namePlugins[name] = plugin
|
||||||
plugin: plugin,
|
}
|
||||||
sourceType: sourceType,
|
|
||||||
|
func compileSource(source data.Source) data.Source {
|
||||||
|
if source.Type != nil {
|
||||||
|
return source
|
||||||
}
|
}
|
||||||
|
|
||||||
data.SourceTypes = append(data.SourceTypes, &sourceType)
|
for _, st := range nameSourceType {
|
||||||
|
if m := st.Regex.FindString(source.Url); m != "" {
|
||||||
|
source.Url = m
|
||||||
|
return source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("couldn't find source type for " + source.Url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FetchUrl(url string) data.MusicObject {
|
||||||
|
return FetchSource(data.Source{
|
||||||
|
Url: string,
|
||||||
|
Type: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func FetchSource(source data.Source) data.MusicObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,12 @@ import (
|
|||||||
type Musify struct {
|
type Musify struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Musify) GetRegex() regexp.Regexp {
|
func (m Musify) Name() string {
|
||||||
return *regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)
|
return "Musify"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Musify) Regex() *regexp.Regexp {
|
||||||
|
return regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Musify) Fetch(source data.Source) data.MusicObject {
|
func (m *Musify) Fetch(source data.Source) data.MusicObject {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user