Refactor return type of the search
This commit is contained in:
+14
-10
@@ -4,11 +4,14 @@ import (
|
||||
"encoding/xml"
|
||||
|
||||
pb "homelab.lan/music-agregator/gen/music_agregator/indexer/v1"
|
||||
"homelab.lan/music-agregator/internal/tracker/rutracker"
|
||||
)
|
||||
|
||||
var parserFactory = rutracker.NewParserFactory()
|
||||
|
||||
type SearchResult struct {
|
||||
XMLName xml.Name `xml:"rss"`
|
||||
Items []Item `xml:"channel>item"` // Directly targets items inside channel
|
||||
Items []Item `xml:"channel>item"`
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
@@ -38,7 +41,6 @@ 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{
|
||||
@@ -47,21 +49,23 @@ func (sr *SearchResult) ToProto() *pb.SearchResponse {
|
||||
}
|
||||
}
|
||||
|
||||
// Map the Item
|
||||
release := parserFactory.GetParser(item.Categories).Parse(item.Title)
|
||||
|
||||
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,
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user