Skip to content

Commit

Permalink
Merge branch 'main' into torznab_profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rraymondgh authored Jan 25, 2025
2 parents 35df2c8 + 2db3a17 commit e3bef16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions internal/torznab/adapter/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package adapter
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/bitmagnet-io/bitmagnet/internal/database/query"
"github.com/bitmagnet-io/bitmagnet/internal/database/search"
"github.com/bitmagnet-io/bitmagnet/internal/model"
"github.com/bitmagnet-io/bitmagnet/internal/torznab"
"strconv"
"strings"
)

func (a adapter) Search(ctx context.Context, req torznab.SearchRequest) (torznab.SearchResult, error) {
Expand Down Expand Up @@ -224,18 +225,26 @@ func (a adapter) transformSearchResult(req torznab.SearchRequest, res search.Tor
AttrValue: item.PublishedAt.Format(torznab.RssDateDefaultFormat),
},
}
if seeders := item.Torrent.Seeders(); seeders.Valid {
seeders := item.Torrent.Seeders()
leechers := item.Torrent.Leechers()
if seeders.Valid {
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
AttrName: torznab.AttrSeeders,
AttrValue: strconv.Itoa(int(seeders.Uint)),
})
}
if leechers := item.Torrent.Leechers(); leechers.Valid {
if leechers.Valid {
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
AttrName: torznab.AttrPeers,
AttrName: torznab.AttrLeechers,
AttrValue: strconv.Itoa(int(leechers.Uint)),
})
}
if leechers.Valid && seeders.Valid {
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
AttrName: torznab.AttrPeers,
AttrValue: strconv.Itoa(int(leechers.Uint) + int(seeders.Uint)),
})
}
if len(item.Torrent.Files) > 0 {
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
AttrName: torznab.AttrFiles,
Expand Down
1 change: 1 addition & 0 deletions internal/torznab/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
AttrSize = "size"
AttrPublishDate = "publishdate"
AttrSeeders = "seeders"
AttrLeechers = "leechers"
AttrPeers = "peers"
// AttrFiles is the number of files in the torrent
AttrFiles = "files"
Expand Down

0 comments on commit e3bef16

Please sign in to comment.