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

Commit

Permalink
rss parse size from length
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Jul 27, 2021
1 parent 702bfe8 commit 024e066
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/boypt/scraper v1.0.3
github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/elithrar/simple-scrypt v1.3.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.9
Expand Down
10 changes: 9 additions & 1 deletion server/server_rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"net/http"
"regexp"
"sort"
"strconv"
"strings"
"time"

"github.com/dustin/go-humanize"
"github.com/mmcdole/gofeed"
)

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

if e, ok := etor["contentLength"]; ok && len(e) > 0 {
if size, err := strconv.ParseUint(e[0].Value, 10, 64); err == nil {
r.Size = humanize.Bytes(size)
}
}

if e, ok := etor["magnetURI"]; ok && len(e) > 0 {
r.Magnet = e[0].Value
found = true
Expand Down

0 comments on commit 024e066

Please sign in to comment.