draft
This commit is contained in:
		
							
								
								
									
										37
									
								
								internal/plugin/interface.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								internal/plugin/interface.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package plugin | ||||
|  | ||||
| import ( | ||||
| 	"reflect" | ||||
| 	"regexp" | ||||
|  | ||||
| 	"gitea.elara.ws/Hazel/music-kraken/internal/data" | ||||
| ) | ||||
|  | ||||
| type Plugin interface { | ||||
| 	GetRegex() regexp.Regexp | ||||
|  | ||||
| 	Search(query string) []data.MusicObject | ||||
|  | ||||
| 	Fetch(source data.Source) data.MusicObject | ||||
| 	FetchSong(source data.Source) data.Song | ||||
| 	FetchAlbum(source data.Source) data.Album | ||||
| 	FetchArtist(source data.Source) data.Artist | ||||
| } | ||||
|  | ||||
| var plugins map[string]Plugin = make(map[string]Plugin) | ||||
|  | ||||
| func AddPlugin(plugin Plugin) { | ||||
| 	name := reflect.TypeOf(plugin).Name() | ||||
|  | ||||
| 	sourceType := data.SourceType{ | ||||
| 		Name:  reflect.TypeOf(plugin).Name(), | ||||
| 		Regex: plugin.GetRegex(), | ||||
| 	} | ||||
|  | ||||
| 	plugins[name] = pluginStorage{ | ||||
| 		plugin:     plugin, | ||||
| 		sourceType: sourceType, | ||||
| 	} | ||||
|  | ||||
| 	data.SourceTypes = append(data.SourceTypes, &sourceType) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user