From 8d071f74617e9581686b3aa8e19c173681c81041 Mon Sep 17 00:00:00 2001 From: itouakirai Date: Wed, 15 Jan 2025 21:25:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=86=85=E5=AD=98=E4=B8=8A=E9=99=90=E8=B0=83=E6=95=B4=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/runv2/runv2.go | 48 ++++++++++++++++++++++++++------------------ utils/runv3/runv3.go | 7 ++----- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/utils/runv2/runv2.go b/utils/runv2/runv2.go index 3d7b8a0..29f7dff 100644 --- a/utils/runv2/runv2.go +++ b/utils/runv2/runv2.go @@ -118,14 +118,36 @@ func Run(adamId string, playlistUrl string, outfile string, Config structs.Confi return err } defer do.Body.Close() - body = do.Body + if do.ContentLength < int64(Config.MaxMemoryLimit * 1024 * 1024) { + var buffer bytes.Buffer + bar := progressbar.NewOptions64( + do.ContentLength, + progressbar.OptionClearOnFinish(), + progressbar.OptionSetElapsedTime(false), + progressbar.OptionSetPredictTime(false), + progressbar.OptionShowElapsedTimeOnFinish(), + progressbar.OptionShowCount(), + progressbar.OptionEnableColorCodes(true), + progressbar.OptionShowBytes(true), + progressbar.OptionSetDescription("Downloading..."), + progressbar.OptionSetTheme(progressbar.Theme{ + Saucer: "", + SaucerHead: "", + SaucerPadding: "", + BarStart: "", + BarEnd: "", + }), + ) + io.Copy(io.MultiWriter(&buffer, bar), do.Body) + body = &buffer + fmt.Print("Downloaded\n") + } else { + body = do.Body + } } var totalLen int64 totalLen = do.ContentLength - - - // connect to decryptor //addr := fmt.Sprintf("127.0.0.1:10020") addr := Config.DecryptM3u8Port @@ -133,26 +155,14 @@ func Run(adamId string, playlistUrl string, outfile string, Config structs.Confi if err != nil { return err } - fmt.Print("Downloading...\n") + //fmt.Print("Decrypting...\n") defer Close(conn) err = downloadAndDecryptFile(conn, body, outfile, adamId, segments, totalLen, Config) if err != nil { return err } - fmt.Print("Decryption finished\n") - // create output file - // ofh, err := os.Create(outfile) - // if err != nil { - // return err - // } - // defer ofh.Close() - // - // _, err = ofh.Write(buffer.Bytes()) - // if err != nil { - // return err - // } - + fmt.Print("Decrypted\n") return nil } @@ -204,7 +214,7 @@ func downloadAndDecryptFile(conn io.ReadWriter, in io.Reader, outfile string, progressbar.OptionShowCount(), progressbar.OptionEnableColorCodes(true), progressbar.OptionShowBytes(true), - //progressbar.OptionSetDescription("Decrypting..."), + progressbar.OptionSetDescription("Decrypting..."), progressbar.OptionSetTheme(progressbar.Theme{ Saucer: "", SaucerHead: "", diff --git a/utils/runv3/runv3.go b/utils/runv3/runv3.go index 2fa1e82..9b8d147 100644 --- a/utils/runv3/runv3.go +++ b/utils/runv3/runv3.go @@ -223,7 +223,7 @@ func extsong(b string)(bytes.Buffer){ progressbar.OptionShowCount(), progressbar.OptionEnableColorCodes(true), progressbar.OptionShowBytes(true), - //progressbar.OptionSetDescription("Downloading..."), + progressbar.OptionSetDescription("Downloading..."), progressbar.OptionSetTheme(progressbar.Theme{ Saucer: "", SaucerHead: "", @@ -233,9 +233,6 @@ func extsong(b string)(bytes.Buffer){ }), ) io.Copy(io.MultiWriter(&buffer, bar), resp.Body) - if err != nil { - fmt.Printf("读取文件失败: %v\n", err) - } return buffer } func Run(adamId string, trackpath string, authtoken string, mutoken string)(error) { @@ -271,8 +268,8 @@ func Run(adamId string, trackpath string, authtoken string, mutoken string)(erro fmt.Println(err) return err } - fmt.Print("Downloading...\n") body := extsong(fileurl) + fmt.Print("Downloaded\n") //bodyReader := bytes.NewReader(body) var buffer bytes.Buffer