parent
9c4d189000
commit
8904ddbfd7
|
|
@ -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)
|
||||
|
|
|
|||
11
download.go
11
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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ struct RunDownload_Req{
|
|||
std::map<std::string, std::vector<std::string>> 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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>762</width>
|
||||
<height>253</height>
|
||||
<height>271</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -17,17 +17,10 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>代理设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>保存的文件名</string>
|
||||
<string>m3u8的url</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -38,6 +31,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pushButton_curlMode">
|
||||
<property name="text">
|
||||
<string>curl模式</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
|
|
@ -73,6 +73,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>保存的文件名</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_FileName">
|
||||
<property name="placeholderText">
|
||||
|
|
@ -80,13 +87,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pushButton_curlMode">
|
||||
<property name="text">
|
||||
<string>curl模式</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
|
|
@ -97,10 +97,10 @@
|
|||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_SkipTsCountFromHead"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>m3u8的url</string>
|
||||
<string>代理设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -114,6 +114,23 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>下载线程数</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_ThreadCount">
|
||||
<property name="text">
|
||||
<string>8</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>[1,1000]</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
@ -130,13 +147,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_SingleThread">
|
||||
<property name="text">
|
||||
<string>单线程下载</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
|
|||
Loading…
Reference in New Issue