From 8904ddbfd735b8629276e71fa784fe5ce355e8cc Mon Sep 17 00:00:00 2001 From: orestonce Date: Tue, 6 Dec 2022 20:20:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=BA=BF=E7=A8=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 +- download.go | 11 +++--- m3u8d-qt/m3u8d.cpp | 76 ++++++++++++++++++++++++++--------------- m3u8d-qt/m3u8d.h | 4 +-- m3u8d-qt/mainwindow.cpp | 6 ++-- m3u8d-qt/mainwindow.ui | 66 ++++++++++++++++++++--------------- 6 files changed, 97 insertions(+), 68 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 3da37b9..c67d3b2 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -113,7 +113,7 @@ func init() { downloadCmd.Flags().IntVarP(&gRunReq.SkipTsCountFromHead, "SkipTsCountFromHead", "", 0, "跳过前面几个ts") downloadCmd.Flags().StringVarP(&gRunReq.SetProxy, "SetProxy", "", "", "代理设置, http://127.0.0.1:8080 socks5://127.0.0.1:1089") downloadCmd.Flags().BoolVarP(&gRunReq.SkipRemoveTs, "SkipRemoveTs", "", false, "不删除下载的ts文件") - downloadCmd.Flags().BoolVarP(&gRunReq.SingleThread, "SingleThread", "", false, "单线程下载") + downloadCmd.Flags().IntVarP(&gRunReq.ThreadCount, "ThreadCount", "", 8, "下载线程数") rootCmd.AddCommand(downloadCmd) curlCmd.DisableFlagParsing = true rootCmd.AddCommand(curlCmd) diff --git a/download.go b/download.go index 32ef519..00438e3 100644 --- a/download.go +++ b/download.go @@ -91,7 +91,7 @@ type RunDownload_Req struct { HeaderMap map[string][]string SkipRemoveTs bool ProgressBarShow bool - SingleThread bool + ThreadCount int } type downloadEnv struct { @@ -201,7 +201,7 @@ func (this *downloadEnv) RunDownload(req RunDownload_Req) (resp RunDownload_Resp // 下载ts this.SetProgressBarTitle("[4/6]下载ts") this.speedSetBegin() - err = this.downloader(tsList, downloadDir, tsKey, req.SingleThread) + err = this.downloader(tsList, downloadDir, tsKey, req.ThreadCount) this.speedClearBytes() if err != nil { resp.ErrMsg = "下载ts文件错误: " + err.Error() @@ -459,10 +459,9 @@ func (this *downloadEnv) SleepDur(d time.Duration) { } } -func (this *downloadEnv) downloader(tsList []TsInfo, downloadDir string, key string, singleThread bool) (err error) { - var threadCount = 8 - if singleThread { - threadCount = 1 +func (this *downloadEnv) downloader(tsList []TsInfo, downloadDir string, key string, threadCount int) (err error) { + if threadCount <= 0 || threadCount > 1000 { + return errors.New("downloadEnv.threadCount invalid: " + strconv.Itoa(threadCount)) } task := gopool.NewThreadPool(threadCount) tsLen := len(tsList) diff --git a/m3u8d-qt/m3u8d.cpp b/m3u8d-qt/m3u8d.cpp index 73df015..b49e4e5 100644 --- a/m3u8d-qt/m3u8d.cpp +++ b/m3u8d-qt/m3u8d.cpp @@ -184,7 +184,14 @@ RunDownload_Resp RunDownload(RunDownload_Req in0){ } in.append((char*)(&in0.SkipRemoveTs), 1); in.append((char*)(&in0.ProgressBarShow), 1); - in.append((char*)(&in0.SingleThread), 1); + { + char tmp55[4]; + tmp55[0] = (uint32_t(in0.ThreadCount) >> 24) & 0xFF; + tmp55[1] = (uint32_t(in0.ThreadCount) >> 16) & 0xFF; + tmp55[2] = (uint32_t(in0.ThreadCount) >> 8) & 0xFF; + tmp55[3] = (uint32_t(in0.ThreadCount) >> 0) & 0xFF; + in.append(tmp55, 4); + } } char *out = NULL; int outLen = 0; @@ -193,30 +200,30 @@ RunDownload_Resp RunDownload(RunDownload_Req in0){ int outIdx = 0; { { - uint32_t tmp55 = 0; - uint32_t tmp56 = uint32_t(uint8_t(out[outIdx+0]) << 24); - uint32_t tmp57 = uint32_t(uint8_t(out[outIdx+1]) << 16); - uint32_t tmp58 = uint32_t(uint8_t(out[outIdx+2]) << 8); - uint32_t tmp59 = uint32_t(uint8_t(out[outIdx+3]) << 0); - tmp55 = tmp56 | tmp57 | tmp58 | tmp59; + uint32_t tmp56 = 0; + uint32_t tmp57 = uint32_t(uint8_t(out[outIdx+0]) << 24); + uint32_t tmp58 = uint32_t(uint8_t(out[outIdx+1]) << 16); + uint32_t tmp59 = uint32_t(uint8_t(out[outIdx+2]) << 8); + uint32_t tmp60 = uint32_t(uint8_t(out[outIdx+3]) << 0); + tmp56 = tmp57 | tmp58 | tmp59 | tmp60; outIdx+=4; - retValue.ErrMsg = std::string(out+outIdx, out+outIdx+tmp55); - outIdx+=tmp55; + retValue.ErrMsg = std::string(out+outIdx, out+outIdx+tmp56); + outIdx+=tmp56; } retValue.IsSkipped = (bool) out[outIdx]; outIdx++; retValue.IsCancel = (bool) out[outIdx]; outIdx++; { - uint32_t tmp60 = 0; - uint32_t tmp61 = uint32_t(uint8_t(out[outIdx+0]) << 24); - uint32_t tmp62 = uint32_t(uint8_t(out[outIdx+1]) << 16); - uint32_t tmp63 = uint32_t(uint8_t(out[outIdx+2]) << 8); - uint32_t tmp64 = uint32_t(uint8_t(out[outIdx+3]) << 0); - tmp60 = tmp61 | tmp62 | tmp63 | tmp64; + uint32_t tmp61 = 0; + uint32_t tmp62 = uint32_t(uint8_t(out[outIdx+0]) << 24); + uint32_t tmp63 = uint32_t(uint8_t(out[outIdx+1]) << 16); + uint32_t tmp64 = uint32_t(uint8_t(out[outIdx+2]) << 8); + uint32_t tmp65 = uint32_t(uint8_t(out[outIdx+3]) << 0); + tmp61 = tmp62 | tmp63 | tmp64 | tmp65; outIdx+=4; - retValue.SaveFileTo = std::string(out+outIdx, out+outIdx+tmp60); - outIdx+=tmp60; + retValue.SaveFileTo = std::string(out+outIdx, out+outIdx+tmp61); + outIdx+=tmp61; } } if (out != NULL) { @@ -441,8 +448,14 @@ ParseCurl_Resp ParseCurlStr(std::string in0){ outIdx++; retValue.DownloadReq.ProgressBarShow = (bool) out[outIdx]; outIdx++; - retValue.DownloadReq.SingleThread = (bool) out[outIdx]; - outIdx++; + { + uint32_t tmp77 = uint32_t(uint8_t(out[outIdx+0]) << 24); + uint32_t tmp78 = uint32_t(uint8_t(out[outIdx+1]) << 16); + uint32_t tmp79 = uint32_t(uint8_t(out[outIdx+2]) << 8); + uint32_t tmp80 = uint32_t(uint8_t(out[outIdx+3]) << 0); + retValue.DownloadReq.ThreadCount = tmp77 | tmp78 | tmp79 | tmp80; + outIdx+=4; + } } } if (out != NULL) { @@ -547,7 +560,14 @@ std::string RunDownload_Req_ToCurlStr(RunDownload_Req in0){ } in.append((char*)(&in0.SkipRemoveTs), 1); in.append((char*)(&in0.ProgressBarShow), 1); - in.append((char*)(&in0.SingleThread), 1); + { + char tmp52[4]; + tmp52[0] = (uint32_t(in0.ThreadCount) >> 24) & 0xFF; + tmp52[1] = (uint32_t(in0.ThreadCount) >> 16) & 0xFF; + tmp52[2] = (uint32_t(in0.ThreadCount) >> 8) & 0xFF; + tmp52[3] = (uint32_t(in0.ThreadCount) >> 0) & 0xFF; + in.append(tmp52, 4); + } } char *out = NULL; int outLen = 0; @@ -555,15 +575,15 @@ std::string RunDownload_Req_ToCurlStr(RunDownload_Req in0){ std::string retValue; int outIdx = 0; { - uint32_t tmp52 = 0; - uint32_t tmp53 = uint32_t(uint8_t(out[outIdx+0]) << 24); - uint32_t tmp54 = uint32_t(uint8_t(out[outIdx+1]) << 16); - uint32_t tmp55 = uint32_t(uint8_t(out[outIdx+2]) << 8); - uint32_t tmp56 = uint32_t(uint8_t(out[outIdx+3]) << 0); - tmp52 = tmp53 | tmp54 | tmp55 | tmp56; + uint32_t tmp53 = 0; + uint32_t tmp54 = uint32_t(uint8_t(out[outIdx+0]) << 24); + uint32_t tmp55 = uint32_t(uint8_t(out[outIdx+1]) << 16); + uint32_t tmp56 = uint32_t(uint8_t(out[outIdx+2]) << 8); + uint32_t tmp57 = uint32_t(uint8_t(out[outIdx+3]) << 0); + tmp53 = tmp54 | tmp55 | tmp56 | tmp57; outIdx+=4; - retValue = std::string(out+outIdx, out+outIdx+tmp52); - outIdx+=tmp52; + retValue = std::string(out+outIdx, out+outIdx+tmp53); + outIdx+=tmp53; } if (out != NULL) { free(out); diff --git a/m3u8d-qt/m3u8d.h b/m3u8d-qt/m3u8d.h index a6351ce..c1f79d8 100644 --- a/m3u8d-qt/m3u8d.h +++ b/m3u8d-qt/m3u8d.h @@ -18,8 +18,8 @@ struct RunDownload_Req{ std::map> HeaderMap; bool SkipRemoveTs; bool ProgressBarShow; - bool SingleThread; - RunDownload_Req(): Insecure(false),SkipTsCountFromHead(0),SkipRemoveTs(false),ProgressBarShow(false),SingleThread(false){} + int32_t ThreadCount; + RunDownload_Req(): Insecure(false),SkipTsCountFromHead(0),SkipRemoveTs(false),ProgressBarShow(false),ThreadCount(0){} }; struct RunDownload_Resp{ std::string ErrMsg; diff --git a/m3u8d-qt/mainwindow.cpp b/m3u8d-qt/mainwindow.cpp index b2b1494..3b32737 100644 --- a/m3u8d-qt/mainwindow.cpp +++ b/m3u8d-qt/mainwindow.cpp @@ -58,7 +58,7 @@ void MainWindow::on_pushButton_RunDownload_clicked() ui->lineEdit_SetProxy->setEnabled(false); ui->pushButton_curlMode->setEnabled(false); ui->checkBox_SkipRemoveTs->setEnabled(false); - ui->checkBox_SingleThread->setEnabled(false); + ui->lineEdit_ThreadCount->setEnabled(false); ui->pushButton_StopDownload->setEnabled(true); RunDownload_Req req; @@ -70,7 +70,7 @@ void MainWindow::on_pushButton_RunDownload_clicked() req.SetProxy = ui->lineEdit_SetProxy->text().toStdString(); req.HeaderMap = m_HeaderMap; req.SkipRemoveTs = ui->checkBox_SkipRemoveTs->isChecked(); - req.SingleThread = ui->checkBox_SingleThread->isChecked(); + req.ThreadCount = ui->lineEdit_ThreadCount->text().toInt(); m_syncUi.AddRunFnOn_OtherThread([req, this](){ RunDownload_Resp resp = RunDownload(req); @@ -87,7 +87,7 @@ void MainWindow::on_pushButton_RunDownload_clicked() ui->pushButton_StopDownload->setEnabled(false); ui->pushButton_curlMode->setEnabled(true); ui->checkBox_SkipRemoveTs->setEnabled(true); - ui->checkBox_SingleThread->setEnabled(true); + ui->lineEdit_ThreadCount->setEnabled(true); if (resp.IsCancel) { return; } diff --git a/m3u8d-qt/mainwindow.ui b/m3u8d-qt/mainwindow.ui index 1e6bf7e..b9ceca3 100644 --- a/m3u8d-qt/mainwindow.ui +++ b/m3u8d-qt/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 762 - 253 + 271 @@ -17,17 +17,10 @@ - - + + - 代理设置 - - - - - - - 保存的文件名 + m3u8的url @@ -38,6 +31,13 @@ + + + + curl模式 + + + @@ -73,6 +73,13 @@ + + + + 保存的文件名 + + + @@ -80,13 +87,6 @@ - - - - curl模式 - - - @@ -97,10 +97,10 @@ - - + + - m3u8的url + 代理设置 @@ -114,6 +114,23 @@ + + + + 下载线程数 + + + + + + + 8 + + + [1,1000] + + + @@ -130,13 +147,6 @@ - - - - 单线程下载 - - -