draft
This commit is contained in:
parent
fefa69e92a
commit
62cb5259ac
@ -7,12 +7,12 @@ import (
|
||||
|
||||
type SourceType struct {
|
||||
Name string
|
||||
Regex regexp.Regexp
|
||||
Regex *regexp.Regexp
|
||||
}
|
||||
|
||||
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]+`)},
|
||||
{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 {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||
)
|
||||
|
||||
type Plugin interface {
|
||||
GetRegex() regexp.Regexp
|
||||
Name() string
|
||||
GetRegex() *regexp.Regexp
|
||||
|
||||
Search(query string) []data.MusicObject
|
||||
|
||||
@ -18,20 +18,41 @@ type Plugin interface {
|
||||
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) {
|
||||
name := reflect.TypeOf(plugin).Name()
|
||||
func RegisterPlugin(plugin Plugin) {
|
||||
name := plugin.Name()
|
||||
|
||||
sourceType := data.SourceType{
|
||||
Name: reflect.TypeOf(plugin).Name(),
|
||||
nameSourceType[name] = data.SourceType{
|
||||
Name: name,
|
||||
Regex: plugin.GetRegex(),
|
||||
}
|
||||
|
||||
plugins[name] = pluginStorage{
|
||||
plugin: plugin,
|
||||
sourceType: sourceType,
|
||||
namePlugins[name] = plugin
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
func (m *Musify) GetRegex() regexp.Regexp {
|
||||
return *regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)
|
||||
func (m Musify) Name() string {
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user