package indexer import ( "encoding/xml" pb "homelab.lan/music-agregator/gen/music_agregator/indexer/v1" "homelab.lan/music-agregator/internal/tracker/rutracker" ) type SearchResult struct { XMLName xml.Name `xml:"rss"` Items []Item `xml:"channel>item"` } type JackettIndexer struct { ID string `xml:"id,attr"` } 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"` JackettIndexer JackettIndexer `xml:"jackettindexer"` } 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"` } var ( rutrackerParserFactory = rutracker.NewRuTrackerParserFactory() ) func (sr *SearchResult) ToProto() *pb.SearchResponse { var pbItems []*pb.SearchItem for _, item := range sr.Items { pbAttrs := make([]*pb.TorznabAttr, len(item.TorznabAttrs)) for j, attr := range item.TorznabAttrs { pbAttrs[j] = &pb.TorznabAttr{ Name: attr.Name, Value: attr.Value, } } // TODO add the check from what tracker the result is to properly get the parser and thus parse it release := rutrackerParserFactory.GetParser(item.Categories).Parse(item.Title) pbItems = append(pbItems, &pb.SearchItem{ Title: item.Title, DownloadLink: item.Link, TorrentPageUrl: 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, Release: release.ToProto(), }) } return &pb.SearchResponse{ Result: pbItems, } }