mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(feeds): RSS improve torrent size parsing (#667)
* Fixes issue 636 - fail to parse torrent size on some RSS feeds when enclosure is a fixed value * Pick the biggest size * minor comment * Updates release size when new parsed string size is bigger - Sets default size of `Release` to zero (unparsed) - When there are parsing errors, then it doesn't RESET the size to 0 (assuming a tracker providing some size that can't be parsed) - Updates the size to the new size only if the parsed size is bigger than the previous. * fix(feeds): ignore default 39399 enclosure size --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
c17034dcff
commit
9a47dbc588
2 changed files with 9 additions and 10 deletions
|
@ -185,6 +185,7 @@ func NewRelease(indexer string) *Release {
|
|||
Implementation: ReleaseImplementationIRC,
|
||||
Timestamp: time.Now(),
|
||||
Tags: []string{},
|
||||
Size: 0,
|
||||
}
|
||||
|
||||
return r
|
||||
|
@ -272,13 +273,13 @@ func (r *Release) ParseReleaseTagsString(tags string) {
|
|||
}
|
||||
}
|
||||
|
||||
// ParseSizeBytesString If there are parsing errors, then it keeps the original (or default size 0)
|
||||
// Otherwise, it will update the size only if the new size is bigger than the previous one.
|
||||
func (r *Release) ParseSizeBytesString(size string) {
|
||||
s, err := humanize.ParseBytes(size)
|
||||
if err != nil {
|
||||
// log could not parse into bytes
|
||||
r.Size = 0
|
||||
if err == nil && s > r.Size {
|
||||
r.Size = s
|
||||
}
|
||||
r.Size = s
|
||||
}
|
||||
|
||||
func (r *Release) DownloadTorrentFileCtx(ctx context.Context) error {
|
||||
|
|
|
@ -113,7 +113,7 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release {
|
|||
if e.Type == "application/x-bittorrent" && e.URL != "" {
|
||||
rls.TorrentURL = e.URL
|
||||
}
|
||||
if e.Length != "" {
|
||||
if e.Length != "" && e.Length != "39399" {
|
||||
rls.ParseSizeBytesString(e.Length)
|
||||
}
|
||||
}
|
||||
|
@ -154,11 +154,9 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release {
|
|||
rls.Uploader += v.Name
|
||||
}
|
||||
|
||||
if rls.Size == 0 {
|
||||
// parse size bytes string
|
||||
if sz, ok := item.Custom["size"]; ok {
|
||||
rls.ParseSizeBytesString(sz)
|
||||
}
|
||||
// When custom->size and enclosures->size differ, `ParseSizeBytesString` will pick the largest one.
|
||||
if size, ok := item.Custom["size"]; ok {
|
||||
rls.ParseSizeBytesString(size)
|
||||
}
|
||||
|
||||
// additional size parsing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue