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,
|
Implementation: ReleaseImplementationIRC,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Size: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
@ -272,14 +273,14 @@ 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) {
|
func (r *Release) ParseSizeBytesString(size string) {
|
||||||
s, err := humanize.ParseBytes(size)
|
s, err := humanize.ParseBytes(size)
|
||||||
if err != nil {
|
if err == nil && s > r.Size {
|
||||||
// log could not parse into bytes
|
|
||||||
r.Size = 0
|
|
||||||
}
|
|
||||||
r.Size = s
|
r.Size = s
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Release) DownloadTorrentFileCtx(ctx context.Context) error {
|
func (r *Release) DownloadTorrentFileCtx(ctx context.Context) error {
|
||||||
return r.downloadTorrentFile(ctx)
|
return r.downloadTorrentFile(ctx)
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release {
|
||||||
if e.Type == "application/x-bittorrent" && e.URL != "" {
|
if e.Type == "application/x-bittorrent" && e.URL != "" {
|
||||||
rls.TorrentURL = e.URL
|
rls.TorrentURL = e.URL
|
||||||
}
|
}
|
||||||
if e.Length != "" {
|
if e.Length != "" && e.Length != "39399" {
|
||||||
rls.ParseSizeBytesString(e.Length)
|
rls.ParseSizeBytesString(e.Length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,11 +154,9 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release {
|
||||||
rls.Uploader += v.Name
|
rls.Uploader += v.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if rls.Size == 0 {
|
// When custom->size and enclosures->size differ, `ParseSizeBytesString` will pick the largest one.
|
||||||
// parse size bytes string
|
if size, ok := item.Custom["size"]; ok {
|
||||||
if sz, ok := item.Custom["size"]; ok {
|
rls.ParseSizeBytesString(size)
|
||||||
rls.ParseSizeBytesString(sz)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// additional size parsing
|
// additional size parsing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue