From 0fa829828f987ce9b825f04f300c73b142438373 Mon Sep 17 00:00:00 2001 From: bytedream Date: Mon, 16 May 2022 22:42:31 +0200 Subject: [PATCH] Fix 1080p, 720p, ... not working --- cmd/crunchyroll-go/cmd/archive.go | 10 +++++++--- cmd/crunchyroll-go/cmd/download.go | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/crunchyroll-go/cmd/archive.go b/cmd/crunchyroll-go/cmd/archive.go index 6f3f6a0..6dcf61b 100644 --- a/cmd/crunchyroll-go/cmd/archive.go +++ b/cmd/crunchyroll-go/cmd/archive.go @@ -13,6 +13,7 @@ import ( "github.com/grafov/m3u8" "github.com/spf13/cobra" "io" + "math" "os" "os/exec" "os/signal" @@ -98,9 +99,12 @@ var archiveCmd = &cobra.Command{ } switch archiveResolutionFlag { - case "1080p", "720p", "480p", "360p", "240p": - intRes, _ := strconv.ParseFloat(strings.TrimSuffix(archiveResolutionFlag, "p"), 84) - archiveResolutionFlag = fmt.Sprintf("%dx%s", int(intRes*(16/9)), strings.TrimSuffix(archiveResolutionFlag, "p")) + case "1080p", "720p", "480p", "360p": + intRes, _ := strconv.ParseFloat(strings.TrimSuffix(downloadResolutionFlag, "p"), 84) + archiveResolutionFlag = fmt.Sprintf("%.0fx%s", math.Ceil(intRes*(float64(16)/float64(9))), strings.TrimSuffix(downloadResolutionFlag, "p")) + case "240p": + // 240p would round up to 427x240 if used in the case statement above, so it has to be handled separately + archiveResolutionFlag = "428x240" case "1920x1080", "1280x720", "640x480", "480x360", "428x240", "best", "worst": default: return fmt.Errorf("'%s' is not a valid resolution", archiveResolutionFlag) diff --git a/cmd/crunchyroll-go/cmd/download.go b/cmd/crunchyroll-go/cmd/download.go index 1ce202c..92b6027 100644 --- a/cmd/crunchyroll-go/cmd/download.go +++ b/cmd/crunchyroll-go/cmd/download.go @@ -7,6 +7,7 @@ import ( "github.com/ByteDream/crunchyroll-go/v2/utils" "github.com/grafov/m3u8" "github.com/spf13/cobra" + "math" "os" "os/signal" "path/filepath" @@ -53,9 +54,12 @@ var downloadCmd = &cobra.Command{ out.Debug("Locales: audio: %s / subtitle: %s", downloadAudioFlag, downloadSubtitleFlag) switch downloadResolutionFlag { - case "1080p", "720p", "480p", "360p", "240p": + case "1080p", "720p", "480p", "360p": intRes, _ := strconv.ParseFloat(strings.TrimSuffix(downloadResolutionFlag, "p"), 84) - downloadResolutionFlag = fmt.Sprintf("%dx%s", int(intRes*(16/9)), strings.TrimSuffix(downloadResolutionFlag, "p")) + downloadResolutionFlag = fmt.Sprintf("%.0fx%s", math.Ceil(intRes*(float64(16)/float64(9))), strings.TrimSuffix(downloadResolutionFlag, "p")) + case "240p": + // 240p would round up to 427x240 if used in the case statement above, so it has to be handled separately + downloadResolutionFlag = "428x240" case "1920x1080", "1280x720", "640x480", "480x360", "428x240", "best", "worst": default: return fmt.Errorf("'%s' is not a valid resolution", downloadResolutionFlag)