Add Jacket indexer with capabilities implemented
This commit is contained in:
+103
-1
@@ -1,6 +1,108 @@
|
||||
package indexer
|
||||
|
||||
import ()
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
|
||||
pb "homelab.lan/music-agregator/gen/music_agregator/indexer/v1"
|
||||
)
|
||||
|
||||
type Indexer interface {
|
||||
Search()
|
||||
Capabilities(indexerName string) (IndexerCapabilities, error)
|
||||
}
|
||||
|
||||
type IndexerCapabilities struct {
|
||||
XMLName xml.Name `xml:"caps"`
|
||||
Server Server `xml:"server"`
|
||||
Limits Limits `xml:"limits"`
|
||||
Searching Searching `xml:"searching"`
|
||||
Categories []Category `xml:"categories>category"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Title string `xml:"title,attr"`
|
||||
}
|
||||
|
||||
type Limits struct {
|
||||
Default int `xml:"default,attr"`
|
||||
Max int `xml:"max,attr"`
|
||||
}
|
||||
|
||||
type Searching struct {
|
||||
Search SearchCapability `xml:"search"`
|
||||
TvSearch SearchCapability `xml:"tv-search"`
|
||||
MovieSearch SearchCapability `xml:"movie-search"`
|
||||
MusicSearch SearchCapability `xml:"music-search"`
|
||||
AudioSearch SearchCapability `xml:"audio-search"`
|
||||
BookSearch SearchCapability `xml:"book-search"`
|
||||
}
|
||||
|
||||
type SearchCapability struct {
|
||||
Available string `xml:"available,attr"`
|
||||
SupportedParams string `xml:"supportedParams,attr"`
|
||||
SearchEngine string `xml:"searchEngine,attr"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
ID int `xml:"id,attr"`
|
||||
Name string `xml:"name,attr"`
|
||||
Subcats []Subcat `xml:"subcat"`
|
||||
}
|
||||
|
||||
type Subcat struct {
|
||||
ID int `xml:"id,attr"`
|
||||
Name string `xml:"name,attr"`
|
||||
}
|
||||
|
||||
func (c *IndexerCapabilities) ToProto() *pb.CapabilitiesResponse {
|
||||
return &pb.CapabilitiesResponse{
|
||||
Server: &pb.Server{
|
||||
Title: c.Server.Title,
|
||||
},
|
||||
Limits: &pb.Limits{
|
||||
Default: int32(c.Limits.Default),
|
||||
Max: int32(c.Limits.Max),
|
||||
},
|
||||
Searching: &pb.Searching{
|
||||
Search: c.Searching.Search.toProto(),
|
||||
TvSearch: c.Searching.TvSearch.toProto(),
|
||||
MovieSearch: c.Searching.MovieSearch.toProto(),
|
||||
MusicSearch: c.Searching.MusicSearch.toProto(),
|
||||
AudioSearch: c.Searching.AudioSearch.toProto(),
|
||||
BookSearch: c.Searching.BookSearch.toProto(),
|
||||
},
|
||||
Categories: c.categoriesToProto(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SearchCapability) toProto() *pb.SearchCapability {
|
||||
var params []string
|
||||
if s.SupportedParams != "" {
|
||||
params = strings.Split(s.SupportedParams, ",")
|
||||
}
|
||||
return &pb.SearchCapability{
|
||||
Available: s.Available == "yes",
|
||||
SupportedParams: params,
|
||||
SearchEngine: s.SearchEngine,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *IndexerCapabilities) categoriesToProto() []*pb.Category {
|
||||
categories := make([]*pb.Category, len(c.Categories))
|
||||
for i, cat := range c.Categories {
|
||||
subcats := make([]*pb.Subcat, len(cat.Subcats))
|
||||
for j, sub := range cat.Subcats {
|
||||
subcats[j] = &pb.Subcat{
|
||||
Id: int32(sub.ID),
|
||||
Name: sub.Name,
|
||||
}
|
||||
}
|
||||
categories[i] = &pb.Category{
|
||||
Id: int32(cat.ID),
|
||||
Name: cat.Name,
|
||||
Subcats: subcats,
|
||||
}
|
||||
}
|
||||
return categories
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user