Skip to content

Commit 2db3a17

Browse files
authored
torznab - fix incorrect leechers in arrs (bitmagnet-io#372)
* fix incorrect leechers in arrs * use peers defined as seeders + leechers * peers as well
1 parent 0b51d37 commit 2db3a17

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

internal/torznab/adapter/search.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package adapter
33
import (
44
"context"
55
"fmt"
6+
"strconv"
7+
"strings"
8+
69
"github.com/bitmagnet-io/bitmagnet/internal/database/query"
710
"github.com/bitmagnet-io/bitmagnet/internal/database/search"
811
"github.com/bitmagnet-io/bitmagnet/internal/model"
912
"github.com/bitmagnet-io/bitmagnet/internal/torznab"
10-
"strconv"
11-
"strings"
1213
)
1314

1415
func (a adapter) Search(ctx context.Context, req torznab.SearchRequest) (torznab.SearchResult, error) {
@@ -220,18 +221,26 @@ func (a adapter) transformSearchResult(req torznab.SearchRequest, res search.Tor
220221
AttrValue: item.PublishedAt.Format(torznab.RssDateDefaultFormat),
221222
},
222223
}
223-
if seeders := item.Torrent.Seeders(); seeders.Valid {
224+
seeders := item.Torrent.Seeders()
225+
leechers := item.Torrent.Leechers()
226+
if seeders.Valid {
224227
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
225228
AttrName: torznab.AttrSeeders,
226229
AttrValue: strconv.Itoa(int(seeders.Uint)),
227230
})
228231
}
229-
if leechers := item.Torrent.Leechers(); leechers.Valid {
232+
if leechers.Valid {
230233
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
231-
AttrName: torznab.AttrPeers,
234+
AttrName: torznab.AttrLeechers,
232235
AttrValue: strconv.Itoa(int(leechers.Uint)),
233236
})
234237
}
238+
if leechers.Valid && seeders.Valid {
239+
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
240+
AttrName: torznab.AttrPeers,
241+
AttrValue: strconv.Itoa(int(leechers.Uint) + int(seeders.Uint)),
242+
})
243+
}
235244
if len(item.Torrent.Files) > 0 {
236245
attrs = append(attrs, torznab.SearchResultItemTorznabAttr{
237246
AttrName: torznab.AttrFiles,

internal/torznab/attributes.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88
AttrSize = "size"
99
AttrPublishDate = "publishdate"
1010
AttrSeeders = "seeders"
11+
AttrLeechers = "leechers"
1112
AttrPeers = "peers"
1213
// AttrFiles is the number of files in the torrent
1314
AttrFiles = "files"

0 commit comments

Comments
 (0)