Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 024e066

Browse files
committed
rss parse size from length
1 parent 702bfe8 commit 024e066

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
1212
github.com/boypt/scraper v1.0.3
1313
github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2
14+
github.com/dustin/go-humanize v1.0.0 // indirect
1415
github.com/elithrar/simple-scrypt v1.3.0 // indirect
1516
github.com/fatih/structs v1.1.0 // indirect
1617
github.com/fsnotify/fsnotify v1.4.9

server/server_rss.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"net/http"
66
"regexp"
77
"sort"
8+
"strconv"
89
"strings"
910
"time"
1011

12+
"github.com/dustin/go-humanize"
1113
"github.com/mmcdole/gofeed"
1214
)
1315

@@ -40,7 +42,7 @@ func (ritem *rssJSONItem) findFromFeedItem(i *gofeed.Item) (found bool) {
4042
for _, e := range i.Enclosures {
4143
if strings.HasPrefix(e.URL, "magnet:") {
4244
ritem.Magnet = e.URL
43-
} else if e.Type == "application/x-bittorrent" {
45+
} else if torrentExp.Match([]byte(e.URL)) {
4446
ritem.Torrent = e.URL
4547
}
4648
}
@@ -79,6 +81,12 @@ func (r *rssJSONItem) readExtention(i *gofeed.Item, ext string) (found bool) {
7981
r.Size = e[0].Value
8082
}
8183

84+
if e, ok := etor["contentLength"]; ok && len(e) > 0 {
85+
if size, err := strconv.ParseUint(e[0].Value, 10, 64); err == nil {
86+
r.Size = humanize.Bytes(size)
87+
}
88+
}
89+
8290
if e, ok := etor["magnetURI"]; ok && len(e) > 0 {
8391
r.Magnet = e[0].Value
8492
found = true

0 commit comments

Comments
 (0)