package indexer import ( "encoding/xml" pb "homelab.lan/music-agregator/gen/music_agregator/indexer/v1" ) type SearchResult struct { XMLName xml.Name `xml:"rss"` Items []Item `xml:"channel>item"` // Directly targets items inside channel } type Item struct { Title string `xml:"title"` Link string `xml:"link"` Guid string `xml:"guid"` PubDate string `xml:"pubDate"` Size int64 `xml:"size"` Description string `xml:"description"` Categories []string `xml:"category"` Enclosure Enclosure `xml:"enclosure"` TorznabAttrs []TorznabAttr `xml:"attr"` } type Enclosure struct { URL string `xml:"url,attr"` Length int64 `xml:"length,attr"` Type string `xml:"type,attr"` } type TorznabAttr struct { Name string `xml:"name,attr"` Value string `xml:"value,attr"` } func (sr *SearchResult) ToProto() *pb.SearchResponse { pbItems := make([]*pb.SearchItem, len(sr.Items)) for i, item := range sr.Items { // Map Torznab Attributes pbAttrs := make([]*pb.TorznabAttr, len(item.TorznabAttrs)) for j, attr := range item.TorznabAttrs { pbAttrs[j] = &pb.TorznabAttr{ Name: attr.Name, Value: attr.Value, } } // Map the Item pbItems[i] = &pb.SearchItem{ Title: item.Title, Link: item.Link, Guid: item.Guid, PubDate: item.PubDate, Size: item.Size, Description: item.Description, Categories: item.Categories, Enclosure: &pb.Enclosure{ Url: item.Enclosure.URL, Length: item.Enclosure.Length, Type: item.Enclosure.Type, }, TorznabAttrs: pbAttrs, } } return &pb.SearchResponse{ Result: pbItems, } }