Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feeds): improve RSS size parsing #1367

Merged
merged 9 commits into from
Jan 27, 2024

Conversation

KyleSanderson
Copy link
Collaborator

No description provided.

@zze0s zze0s changed the title fix(feeds): Parse multiple sizes. feat(feeds): improve size parsing Jan 22, 2024
@zze0s zze0s added backend Backend releases feeds Feeds: RSS, Torznab and Newznab labels Jan 22, 2024
@zze0s zze0s changed the title feat(feeds): improve size parsing feat(feeds): improve RSS size parsing Jan 24, 2024
Copy link
Collaborator

@zze0s zze0s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvements! 👍 Left some comments.

Comment on lines 296 to 333
func parseSize(sizeStr string) (uint64, error) {
var multiplier uint64 = 1
sizeStr = strings.TrimSpace(sizeStr)

switch {
case strings.HasSuffix(sizeStr, "PiB"):
multiplier = 1024 * 1024 * 1024 * 1024 * 1024
sizeStr = strings.TrimSuffix(sizeStr, "PiB")
case strings.HasSuffix(sizeStr, "TiB"):
multiplier = 1024 * 1024 * 1024 * 1024
sizeStr = strings.TrimSuffix(sizeStr, "TiB")
case strings.HasSuffix(sizeStr, "GiB"):
multiplier = 1024 * 1024 * 1024
sizeStr = strings.TrimSuffix(sizeStr, "GiB")
case strings.HasSuffix(sizeStr, "MiB"):
multiplier = 1024 * 1024
sizeStr = strings.TrimSuffix(sizeStr, "MiB")
case strings.HasSuffix(sizeStr, "PB"):
multiplier = 1000 * 1000 * 1000 * 1000 * 1000
sizeStr = strings.TrimSuffix(sizeStr, "PB")
case strings.HasSuffix(sizeStr, "TB"):
multiplier = 1000 * 1000 * 1000 * 1000
sizeStr = strings.TrimSuffix(sizeStr, "TB")
case strings.HasSuffix(sizeStr, "GB"):
multiplier = 1000 * 1000 * 1000
sizeStr = strings.TrimSuffix(sizeStr, "GB")
case strings.HasSuffix(sizeStr, "B"):
sizeStr = strings.TrimSuffix(sizeStr, "B")
}

sizeStr = strings.Replace(sizeStr, " ", "", -1) // Remove any spaces
size, err := strconv.ParseFloat(sizeStr, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse size: %v", err)
}

return uint64(size * float64(multiplier)), nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort, but humanize.ParseBytes(str) does this already.

if matches == nil {
return ""
// pullSizeFromDescription get size from description
func pullSizeFromDescription(str string, r *domain.Release) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick but I think the old name readSizeFromDescription is better, or parse instead of read. we don't use the pull terminology anywhere else.

@zze0s zze0s added this to the v1.36.0 milestone Jan 27, 2024
@KyleSanderson KyleSanderson merged commit cdd91d2 into develop Jan 27, 2024
19 checks passed
@KyleSanderson KyleSanderson deleted the fix/feed-size/cats-in-the-cradle branch January 27, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend feeds Feeds: RSS, Torznab and Newznab releases
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants