From e42b2d746cf8d606d6d8ec5720dc2b03d82ba004 Mon Sep 17 00:00:00 2001 From: itouakirai <85016486+itouakirai@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:21:03 +0800 Subject: [PATCH] Update main.go --- main.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 590cbe7..1309c80 100644 --- a/main.go +++ b/main.go @@ -97,6 +97,7 @@ type SongInfo struct { r io.ReadSeeker alacParam *Alac samples []SampleInfo + totalDataSize int64 } func loadConfig() error { @@ -978,7 +979,22 @@ func decryptSong(info *SongInfo, keys []string, manifest *AutoGenerated, filenam var decrypted []byte var lastIndex uint32 = math.MaxUint8 - fmt.Println("Decrypt start.") + bar := progressbar.NewOptions64(info.totalDataSize, + progressbar.OptionClearOnFinish(), + progressbar.OptionSetElapsedTime(true), + progressbar.OptionShowElapsedTimeOnFinish(), + progressbar.OptionShowCount(), + progressbar.OptionEnableColorCodes(true), + progressbar.OptionShowBytes(true), + progressbar.OptionSetDescription("Decrypting..."), + progressbar.OptionSetTheme(progressbar.Theme{ + Saucer: "", + SaucerHead: "", + SaucerPadding: "", + BarStart: "", + BarEnd: "", + }), + ) for _, sp := range info.samples { if lastIndex != sp.descIndex { if len(decrypted) != 0 { @@ -1030,10 +1046,11 @@ func decryptSong(info *SongInfo, keys []string, manifest *AutoGenerated, filenam } decrypted = append(decrypted, de...) + bar.Add(len(sp.data)) } _, _ = conn.Write([]byte{0, 0, 0, 0, 0}) - fmt.Println("Decrypt finished.") + fmt.Println("Decrypted.") create, err := os.Create(filename) if err != nil { @@ -1704,12 +1721,15 @@ func rip(albumId string, token string, storefront string, userToken string) erro } samplesOk := true for samplesOk { + var totalSize int64 = 0 for _, i := range info.samples { + totalSize += int64(len(i.data)) if int(i.descIndex) >= len(keys) { fmt.Println("Decryption size mismatch.") samplesOk = false } } + info.totalDataSize = totalSize break } if !samplesOk { @@ -2321,12 +2341,20 @@ func extractSong(url string) (*SongInfo, error) { } contentLength := track.ContentLength bar := progressbar.NewOptions64(contentLength, + progressbar.OptionClearOnFinish(), progressbar.OptionSetElapsedTime(true), progressbar.OptionShowElapsedTimeOnFinish(), progressbar.OptionShowCount(), progressbar.OptionEnableColorCodes(true), progressbar.OptionShowBytes(true), progressbar.OptionSetDescription("Downloading..."), + progressbar.OptionSetTheme(progressbar.Theme{ + Saucer: "", + SaucerHead: "", + SaucerPadding: "", + BarStart: "", + BarEnd: "", + }), ) rawSong, err := ioutil.ReadAll(io.TeeReader(track.Body, bar)) if err != nil {