根据自定义内存上限调整下载方法
This commit is contained in:
parent
eb929e3660
commit
8d071f7461
@ -118,14 +118,36 @@ func Run(adamId string, playlistUrl string, outfile string, Config structs.Confi
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer do.Body.Close()
|
defer do.Body.Close()
|
||||||
|
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
|
body = do.Body
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var totalLen int64
|
var totalLen int64
|
||||||
totalLen = do.ContentLength
|
totalLen = do.ContentLength
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// connect to decryptor
|
// connect to decryptor
|
||||||
//addr := fmt.Sprintf("127.0.0.1:10020")
|
//addr := fmt.Sprintf("127.0.0.1:10020")
|
||||||
addr := Config.DecryptM3u8Port
|
addr := Config.DecryptM3u8Port
|
||||||
@ -133,26 +155,14 @@ func Run(adamId string, playlistUrl string, outfile string, Config structs.Confi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("Downloading...\n")
|
//fmt.Print("Decrypting...\n")
|
||||||
defer Close(conn)
|
defer Close(conn)
|
||||||
|
|
||||||
err = downloadAndDecryptFile(conn, body, outfile, adamId, segments, totalLen, Config)
|
err = downloadAndDecryptFile(conn, body, outfile, adamId, segments, totalLen, Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("Decryption finished\n")
|
fmt.Print("Decrypted\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
|
|
||||||
// }
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +214,7 @@ func downloadAndDecryptFile(conn io.ReadWriter, in io.Reader, outfile string,
|
|||||||
progressbar.OptionShowCount(),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionEnableColorCodes(true),
|
progressbar.OptionEnableColorCodes(true),
|
||||||
progressbar.OptionShowBytes(true),
|
progressbar.OptionShowBytes(true),
|
||||||
//progressbar.OptionSetDescription("Decrypting..."),
|
progressbar.OptionSetDescription("Decrypting..."),
|
||||||
progressbar.OptionSetTheme(progressbar.Theme{
|
progressbar.OptionSetTheme(progressbar.Theme{
|
||||||
Saucer: "",
|
Saucer: "",
|
||||||
SaucerHead: "",
|
SaucerHead: "",
|
||||||
|
@ -223,7 +223,7 @@ func extsong(b string)(bytes.Buffer){
|
|||||||
progressbar.OptionShowCount(),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionEnableColorCodes(true),
|
progressbar.OptionEnableColorCodes(true),
|
||||||
progressbar.OptionShowBytes(true),
|
progressbar.OptionShowBytes(true),
|
||||||
//progressbar.OptionSetDescription("Downloading..."),
|
progressbar.OptionSetDescription("Downloading..."),
|
||||||
progressbar.OptionSetTheme(progressbar.Theme{
|
progressbar.OptionSetTheme(progressbar.Theme{
|
||||||
Saucer: "",
|
Saucer: "",
|
||||||
SaucerHead: "",
|
SaucerHead: "",
|
||||||
@ -233,9 +233,6 @@ func extsong(b string)(bytes.Buffer){
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
io.Copy(io.MultiWriter(&buffer, bar), resp.Body)
|
io.Copy(io.MultiWriter(&buffer, bar), resp.Body)
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("读取文件失败: %v\n", err)
|
|
||||||
}
|
|
||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
func Run(adamId string, trackpath string, authtoken string, mutoken string)(error) {
|
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)
|
fmt.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("Downloading...\n")
|
|
||||||
body := extsong(fileurl)
|
body := extsong(fileurl)
|
||||||
|
fmt.Print("Downloaded\n")
|
||||||
//bodyReader := bytes.NewReader(body)
|
//bodyReader := bytes.NewReader(body)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user