Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
orestonce committed May 29, 2022
1 parent 8809fe2 commit fdfe35d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 158 deletions.
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func init() {
rootCmd.Flags().BoolVarP(&gRunReq.Insecure, "Insecure", "", false, "是否允许不安全的请求")
rootCmd.Flags().StringVarP(&gRunReq.SaveDir, "SaveDir", "d", "", "文件保存路径(默认为当前路径)")
rootCmd.Flags().StringVarP(&gRunReq.FileName, "FileName", "f", "", "文件名")
rootCmd.Flags().BoolVarP(&gRunReq.UserFfmpegMerge, "UserFfmpegMerge", "", true, "使用ffmpeg合并分段视频")
rootCmd.Flags().IntVarP(&gRunReq.SkipTsCountFromHead, "SkipTsCountFromHead", "", 0, "跳过前面几个ts")
}

Expand Down
66 changes: 23 additions & 43 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type RunDownload_Req struct {
Insecure bool `json:"-"` // "是否允许不安全的请求(默认为false)"
SaveDir string `json:"-"` // "文件保存路径(默认为当前路径)"
FileName string `json:"-"` // 文件名
UserFfmpegMerge bool `json:",omitempty"` // 使用ffmpeg合并分段视频
SkipTsCountFromHead int `json:",omitempty"` // 跳过前面几个ts
}

Expand Down Expand Up @@ -99,12 +98,10 @@ func RunDownload(req RunDownload_Req) (resp RunDownload_Resp) {
}
}
var ffmpegExe string
if req.UserFfmpegMerge {
ffmpegExe, err = goffmpeg.SetupFfmpeg()
if err != nil {
resp.ErrMsg = "SetupFfmpeg error: " + err.Error()
return resp
}
ffmpegExe, err = goffmpeg.SetupFfmpeg()
if err != nil {
resp.ErrMsg = "SetupFfmpeg error: " + err.Error()
return resp
}
host, err := getHost(req.M3u8Url, "apiv2")
if err != nil {
Expand Down Expand Up @@ -171,30 +168,21 @@ func RunDownload(req RunDownload_Req) (resp RunDownload_Resp) {
}
var tmpOutputName string
var contentHash string
if req.UserFfmpegMerge {
tmpOutputName = filepath.Join(downloadDir, "all.merge.mp4")
err = goffmpeg.MergeMultiToSingleMp4(goffmpeg.MergeMultiToSingleMp4_Req{
FfmpegExePath: ffmpegExe,
TsFileList: tsFileList,
OutputMp4: tmpOutputName,
ProgressCh: nil,
})
if err != nil {
resp.ErrMsg = "合并错误: " + err.Error()
return resp
}
contentHash = getFileSha256(tmpOutputName)
if contentHash == "" {
resp.ErrMsg = "无法计算摘要信息: " + tmpOutputName
return resp
}
} else {
tmpOutputName = filepath.Join(downloadDir, "all.merge.ts")
contentHash, err = mergeTsFileList_Raw(tsFileList, tmpOutputName)
if err != nil {
resp.ErrMsg = "合并错误: " + err.Error()
return resp
}
tmpOutputName = filepath.Join(downloadDir, "all.merge.mp4")
err = goffmpeg.MergeMultiToSingleMp4(goffmpeg.MergeMultiToSingleMp4_Req{
FfmpegExePath: ffmpegExe,
TsFileList: tsFileList,
OutputMp4: tmpOutputName,
ProgressCh: nil,
})
if err != nil {
resp.ErrMsg = "合并错误: " + err.Error()
return resp
}
contentHash = getFileSha256(tmpOutputName)
if contentHash == "" {
resp.ErrMsg = "无法计算摘要信息: " + tmpOutputName
return resp
}
var name string
for idx := 0; ; idx++ {
Expand All @@ -203,18 +191,10 @@ func RunDownload(req RunDownload_Req) (resp RunDownload_Resp) {
idxS = strings.Repeat("0", 4-len(idxS)) + idxS
}
idxS = "_" + idxS
if req.UserFfmpegMerge {
if idx == 0 {
name = filepath.Join(req.SaveDir, req.FileName+".mp4")
} else {
name = filepath.Join(req.SaveDir, req.FileName+idxS+".mp4")
}
} else { // 直接合并的就是ts,不是mp4
if idx == 0 {
name = filepath.Join(req.SaveDir, req.FileName+".ts")
} else {
name = filepath.Join(req.SaveDir, req.FileName+idxS+".ts")
}
if idx == 0 {
name = filepath.Join(req.SaveDir, req.FileName+".mp4")
} else {
name = filepath.Join(req.SaveDir, req.FileName+idxS+".mp4")
}
if !isFileExists(name) {
resp.SaveFileTo = name
Expand Down
21 changes: 4 additions & 17 deletions export/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

func main() {
//BuildCliBinary() // 编译二进制
CreateLibForQtUi() // 创建Qt需要使用的.a库文件
BuildCliBinary() // 编译二进制
CreateLibForQtUi() // 创建Qt需要使用的.a库文件
}

func BuildCliBinary() {
Expand All @@ -25,23 +25,10 @@ func BuildCliBinary() {
Ext string
}
var list = []buildCfg{
{
GOOS: "windows",
GOARCH: "amd64",
Ext: ".exe",
},
{
GOOS: "linux",
GOARCH: "amd64",
},
{
GOOS: "linux",
GOARCH: "386",
},
{
GOOS: "linux",
GOARCH: "arm64",
},
{
GOOS: "linux",
GOARCH: "arm",
Expand All @@ -52,7 +39,7 @@ func BuildCliBinary() {
},
}
for _, cfg := range list {
name := "m3u8d_cli_v1.0_" + cfg.GOOS + "_" + cfg.GOARCH + cfg.Ext
name := "m3u8d_cli_v1.1_" + cfg.GOOS + "_" + cfg.GOARCH + cfg.Ext
cmd := exec.Command("go", "build", "-o", filepath.Join(wd, "bin", name))
cmd.Dir = filepath.Join(wd, "cmd")
cmd.Env = append(os.Environ(), "GOOS="+cfg.GOOS)
Expand All @@ -78,4 +65,4 @@ func CreateLibForQtUi() {
ctx.Generate1(m3u8d.GetProgress)
ctx.Generate1(m3u8d.GetWd)
ctx.MustCreateAmd64LibraryInDir("m3u8d-qt")
}
}
Binary file modified m3u8d-qt/m3u8d-impl.a
Binary file not shown.
101 changes: 50 additions & 51 deletions m3u8d-qt/m3u8d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,54 +82,53 @@ RunDownload_Resp RunDownload(RunDownload_Req in0){
std::string in;
{
{
uint32_t tmp19 = in0.M3u8Url.length();
char tmp20[4];
tmp20[0] = (uint32_t(tmp19) >> 24) & 0xFF;
tmp20[1] = (uint32_t(tmp19) >> 16) & 0xFF;
tmp20[2] = (uint32_t(tmp19) >> 8) & 0xFF;
tmp20[3] = (uint32_t(tmp19) >> 0) & 0xFF;
in.append(tmp20, 4);
uint32_t tmp18 = in0.M3u8Url.length();
char tmp19[4];
tmp19[0] = (uint32_t(tmp18) >> 24) & 0xFF;
tmp19[1] = (uint32_t(tmp18) >> 16) & 0xFF;
tmp19[2] = (uint32_t(tmp18) >> 8) & 0xFF;
tmp19[3] = (uint32_t(tmp18) >> 0) & 0xFF;
in.append(tmp19, 4);
in.append(in0.M3u8Url);
}
{
uint32_t tmp21 = in0.HostType.length();
char tmp22[4];
tmp22[0] = (uint32_t(tmp21) >> 24) & 0xFF;
tmp22[1] = (uint32_t(tmp21) >> 16) & 0xFF;
tmp22[2] = (uint32_t(tmp21) >> 8) & 0xFF;
tmp22[3] = (uint32_t(tmp21) >> 0) & 0xFF;
in.append(tmp22, 4);
uint32_t tmp20 = in0.HostType.length();
char tmp21[4];
tmp21[0] = (uint32_t(tmp20) >> 24) & 0xFF;
tmp21[1] = (uint32_t(tmp20) >> 16) & 0xFF;
tmp21[2] = (uint32_t(tmp20) >> 8) & 0xFF;
tmp21[3] = (uint32_t(tmp20) >> 0) & 0xFF;
in.append(tmp21, 4);
in.append(in0.HostType);
}
in.append((char*)(&in0.Insecure), 1);
{
uint32_t tmp23 = in0.SaveDir.length();
char tmp24[4];
tmp24[0] = (uint32_t(tmp23) >> 24) & 0xFF;
tmp24[1] = (uint32_t(tmp23) >> 16) & 0xFF;
tmp24[2] = (uint32_t(tmp23) >> 8) & 0xFF;
tmp24[3] = (uint32_t(tmp23) >> 0) & 0xFF;
in.append(tmp24, 4);
uint32_t tmp22 = in0.SaveDir.length();
char tmp23[4];
tmp23[0] = (uint32_t(tmp22) >> 24) & 0xFF;
tmp23[1] = (uint32_t(tmp22) >> 16) & 0xFF;
tmp23[2] = (uint32_t(tmp22) >> 8) & 0xFF;
tmp23[3] = (uint32_t(tmp22) >> 0) & 0xFF;
in.append(tmp23, 4);
in.append(in0.SaveDir);
}
{
uint32_t tmp25 = in0.FileName.length();
char tmp26[4];
tmp26[0] = (uint32_t(tmp25) >> 24) & 0xFF;
tmp26[1] = (uint32_t(tmp25) >> 16) & 0xFF;
tmp26[2] = (uint32_t(tmp25) >> 8) & 0xFF;
tmp26[3] = (uint32_t(tmp25) >> 0) & 0xFF;
in.append(tmp26, 4);
uint32_t tmp24 = in0.FileName.length();
char tmp25[4];
tmp25[0] = (uint32_t(tmp24) >> 24) & 0xFF;
tmp25[1] = (uint32_t(tmp24) >> 16) & 0xFF;
tmp25[2] = (uint32_t(tmp24) >> 8) & 0xFF;
tmp25[3] = (uint32_t(tmp24) >> 0) & 0xFF;
in.append(tmp25, 4);
in.append(in0.FileName);
}
in.append((char*)(&in0.UserFfmpegMerge), 1);
{
char tmp27[4];
tmp27[0] = (uint32_t(in0.SkipTsCountFromHead) >> 24) & 0xFF;
tmp27[1] = (uint32_t(in0.SkipTsCountFromHead) >> 16) & 0xFF;
tmp27[2] = (uint32_t(in0.SkipTsCountFromHead) >> 8) & 0xFF;
tmp27[3] = (uint32_t(in0.SkipTsCountFromHead) >> 0) & 0xFF;
in.append(tmp27, 4);
char tmp26[4];
tmp26[0] = (uint32_t(in0.SkipTsCountFromHead) >> 24) & 0xFF;
tmp26[1] = (uint32_t(in0.SkipTsCountFromHead) >> 16) & 0xFF;
tmp26[2] = (uint32_t(in0.SkipTsCountFromHead) >> 8) & 0xFF;
tmp26[3] = (uint32_t(in0.SkipTsCountFromHead) >> 0) & 0xFF;
in.append(tmp26, 4);
}
}
char *out = NULL;
Expand All @@ -139,28 +138,28 @@ RunDownload_Resp RunDownload(RunDownload_Req in0){
int outIdx = 0;
{
{
uint32_t tmp28 = 0;
uint32_t tmp29 = uint32_t(uint8_t(out[outIdx+0]) << 24);
uint32_t tmp30 = uint32_t(uint8_t(out[outIdx+1]) << 16);
uint32_t tmp31 = uint32_t(uint8_t(out[outIdx+2]) << 8);
uint32_t tmp32 = uint32_t(uint8_t(out[outIdx+3]) << 0);
tmp28 = tmp29 | tmp30 | tmp31 | tmp32;
uint32_t tmp27 = 0;
uint32_t tmp28 = uint32_t(uint8_t(out[outIdx+0]) << 24);
uint32_t tmp29 = uint32_t(uint8_t(out[outIdx+1]) << 16);
uint32_t tmp30 = uint32_t(uint8_t(out[outIdx+2]) << 8);
uint32_t tmp31 = uint32_t(uint8_t(out[outIdx+3]) << 0);
tmp27 = tmp28 | tmp29 | tmp30 | tmp31;
outIdx+=4;
retValue.ErrMsg = std::string(out+outIdx, out+outIdx+tmp28);
outIdx+=tmp28;
retValue.ErrMsg = std::string(out+outIdx, out+outIdx+tmp27);
outIdx+=tmp27;
}
retValue.IsSkipped = (bool) out[outIdx];
outIdx++;
{
uint32_t tmp33 = 0;
uint32_t tmp34 = uint32_t(uint8_t(out[outIdx+0]) << 24);
uint32_t tmp35 = uint32_t(uint8_t(out[outIdx+1]) << 16);
uint32_t tmp36 = uint32_t(uint8_t(out[outIdx+2]) << 8);
uint32_t tmp37 = uint32_t(uint8_t(out[outIdx+3]) << 0);
tmp33 = tmp34 | tmp35 | tmp36 | tmp37;
uint32_t tmp32 = 0;
uint32_t tmp33 = uint32_t(uint8_t(out[outIdx+0]) << 24);
uint32_t tmp34 = uint32_t(uint8_t(out[outIdx+1]) << 16);
uint32_t tmp35 = uint32_t(uint8_t(out[outIdx+2]) << 8);
uint32_t tmp36 = uint32_t(uint8_t(out[outIdx+3]) << 0);
tmp32 = tmp33 | tmp34 | tmp35 | tmp36;
outIdx+=4;
retValue.SaveFileTo = std::string(out+outIdx, out+outIdx+tmp33);
outIdx+=tmp33;
retValue.SaveFileTo = std::string(out+outIdx, out+outIdx+tmp32);
outIdx+=tmp32;
}
}
if (out != NULL) {
Expand Down
1 change: 0 additions & 1 deletion m3u8d-qt/m3u8d.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct RunDownload_Req{
bool Insecure;
std::string SaveDir;
std::string FileName;
bool UserFfmpegMerge;
int32_t SkipTsCountFromHead;
};
struct RunDownload_Resp{
Expand Down
3 changes: 0 additions & 3 deletions m3u8d-qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void MainWindow::on_pushButton_RunDownload_clicked()
ui->lineEdit_FileName->setEnabled(false);
ui->lineEdit_SkipTsCountFromHead->setEnabled(false);
ui->comboBox_HostType->setEnabled(false);
ui->comboBox_OutputFormat->setEnabled(false);
ui->pushButton_RunDownload->setEnabled(false);
ui->checkBox_Insecure->setEnabled(false);
ui->progressBar->setValue(0);
Expand Down Expand Up @@ -59,7 +58,6 @@ void MainWindow::on_pushButton_RunDownload_clicked()
req.Insecure = ui->checkBox_Insecure->isChecked();
req.SaveDir = ui->lineEdit_SaveDir->text().toStdString();
req.FileName = ui->lineEdit_FileName->text().toStdString();
req.UserFfmpegMerge = ui->comboBox_OutputFormat->currentIndex() == 0;
req.SkipTsCountFromHead = ui->lineEdit_SkipTsCountFromHead->text().toInt();

m_syncUi.AddRunFnOn_OtherThread([req, this](){
Expand All @@ -71,7 +69,6 @@ void MainWindow::on_pushButton_RunDownload_clicked()
ui->lineEdit_FileName->setEnabled(true);
ui->lineEdit_SkipTsCountFromHead->setEnabled(true);
ui->comboBox_HostType->setEnabled(true);
ui->comboBox_OutputFormat->setEnabled(true);
ui->pushButton_RunDownload->setEnabled(true);
ui->checkBox_Insecure->setEnabled(false);
ui->pushButton_RunDownload->setText("开始下载");
Expand Down
Loading

0 comments on commit fdfe35d

Please sign in to comment.