From 8095e1a8dc9c8487aea6158554c1d6767e69b987 Mon Sep 17 00:00:00 2001 From: orestonce Date: Tue, 28 Jun 2022 20:46:18 +0800 Subject: [PATCH] =?UTF-8?q?version=E8=87=AA=E5=8A=A8=E7=94=9F=E4=BA=A7=20?= =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E4=B8=8B=E8=BD=BD=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?,=E7=A6=81=E7=94=A8"curl=E6=A8=A1=E5=BC=8F"=E6=8C=89=E9=92=AE?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E8=AF=86=E5=88=ABm3u8/ts=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84url=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- download.go | 17 +++++++-- download_test.go | 26 ++++++++++++++ export/main.go | 76 ++++++++++++++++++++++++++++++++++++++++- go.mod | 1 + go.sum | 1 + m3u8d-qt/mainwindow.cpp | 2 ++ m3u8d-qt/version.rc | 6 ++-- 7 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 download_test.go diff --git a/download.go b/download.go index 3ee39da..f4542b3 100644 --- a/download.go +++ b/download.go @@ -535,18 +535,21 @@ func (this *downloadEnv) sniffM3u8(urlS string) (afterUrl string, content []byte if err != nil { return "", nil, err } - if strings.HasSuffix(strings.ToLower(urlS), ".m3u8") { + if UrlHasSuffix(urlS, ".m3u8") { // 看这个是不是嵌套的m3u8 var m3u8Url string containsTs := false for _, line := range strings.Split(string(content), "\n") { lineOrigin := strings.TrimSpace(line) + if strings.HasPrefix(lineOrigin, "#") { + continue + } line = strings.ToLower(lineOrigin) - if strings.HasSuffix(line, ".m3u8") { + if UrlHasSuffix(line, ".m3u8") { m3u8Url = lineOrigin break } - if strings.HasSuffix(line, ".ts") { + if UrlHasSuffix(line, ".ts") { containsTs = true break } @@ -577,6 +580,14 @@ func (this *downloadEnv) sniffM3u8(urlS string) (afterUrl string, content []byte return "", nil, errors.New("未发现m3u8资源_3") } +func UrlHasSuffix(urlS string, suff string) bool { + urlObj, err := url.Parse(urlS) + if err != nil { + return false + } + return strings.HasSuffix(strings.ToLower(urlObj.Path), suff) +} + func (this *downloadEnv) doGetRequest(urlS string) (data []byte, err error) { req, err := http.NewRequest(http.MethodGet, urlS, nil) if err != nil { diff --git a/download_test.go b/download_test.go new file mode 100644 index 0000000..7a8d721 --- /dev/null +++ b/download_test.go @@ -0,0 +1,26 @@ +package m3u8d + +import "testing" + +func TestUrlHasSuffix(t *testing.T) { + if UrlHasSuffix("/0001.ts", ".ts") == false { + t.Fatal() + return + } + if UrlHasSuffix("/0001.Ts", ".ts") == false { + t.Fatal() + return + } + if UrlHasSuffix("/0001.ts?v=123", ".ts") == false { + t.Fatal() + return + } + if UrlHasSuffix("https://www.example.com/0001.m3u8?hsd=12", "hsd") { + t.Fatal() + return + } + if UrlHasSuffix("https://www.example.com/0001.m3U8?hsd=12", ".m3u8") == false { + t.Fatal() + return + } +} diff --git a/export/main.go b/export/main.go index 1f7cd15..b3a15eb 100644 --- a/export/main.go +++ b/export/main.go @@ -3,15 +3,22 @@ package main import ( "fmt" "github.com/orestonce/go2cpp" + "golang.org/x/text/encoding/simplifiedchinese" + "io/ioutil" "m3u8d" "os" "os/exec" "path/filepath" + "strconv" + "strings" ) +const version = "1.5.1" + func main() { BuildCliBinary() // 编译二进制 CreateLibForQtUi() // 创建Qt需要使用的.a库文件 + WriteVersionDotRc() } func BuildCliBinary() { @@ -42,7 +49,7 @@ func BuildCliBinary() { }, } for _, cfg := range list { - name := "m3u8d_cli_v1.5.0_" + cfg.GOOS + "_" + cfg.GOARCH + name := "m3u8d_cli_v" + version + "_" + cfg.GOOS + "_" + cfg.GOARCH cmd := exec.Command("go", "build", "-trimpath", "-ldflags", "-s -w", "-o", filepath.Join(wd, "bin", name)) cmd.Dir = filepath.Join(wd, "cmd") cmd.Env = append(os.Environ(), "GOOS="+cfg.GOOS) @@ -72,3 +79,70 @@ func CreateLibForQtUi() { ctx.Generate1(m3u8d.RunDownload_Req_ToCurlStr) ctx.MustCreateAmd64LibraryInDir("m3u8d-qt") } + +func WriteVersionDotRc() { + tmp := strings.Split(version, ".") + ok := len(tmp) == 3 + for _, v := range tmp { + vi, err := strconv.Atoi(v) + if err != nil { + ok = false + break + } + if vi < 0 { + ok = false + break + } + } + if ok == false { + panic("version invalid: " + strconv.Quote(version)) + } + tmp = append(tmp, "0") + v1 := strings.Join(tmp, ",") + data := []byte(`IDI_ICON1 ICON "favicon.ico" + +#if defined(UNDER_CE) +#include +#else +#include +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION ` + v1 + ` + PRODUCTVERSION ` + v1 + ` + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080404b0" + BEGIN + VALUE "ProductVersion", "` + version + `.0\0" + VALUE "ProductName", "m3u8视频下载工具\0" + VALUE "LegalCopyright", "https://github.com/orestonce/m3u8d\0" + VALUE "FileDescription", "m3u8视频下载工具\0" + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x804, 1200 + END + END +`) + data, err := simplifiedchinese.GBK.NewEncoder().Bytes(data) + if err != nil { + panic(err) + } + err = ioutil.WriteFile("m3u8d-qt/version.rc", data, 0777) + if err != nil { + panic(err) + } +} diff --git a/go.mod b/go.mod index d4a5166..293e0a6 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/spf13/cobra v1.4.0 github.com/yapingcat/gomedia v0.0.0-20220623101430-02bb90c39484 golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 + golang.org/x/text v0.3.7 ) require ( diff --git a/go.sum b/go.sum index 9ceb0c3..a8d8cf0 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,7 @@ golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/m3u8d-qt/mainwindow.cpp b/m3u8d-qt/mainwindow.cpp index 6f56224..58675c4 100644 --- a/m3u8d-qt/mainwindow.cpp +++ b/m3u8d-qt/mainwindow.cpp @@ -37,6 +37,7 @@ void MainWindow::on_pushButton_RunDownload_clicked() ui->checkBox_Insecure->setEnabled(false); ui->progressBar->setValue(0); ui->lineEdit_SetProxy->setEnabled(false); + ui->pushButton_curlMode->setEnabled(false); ui->pushButton_StopDownload->setEnabled(true); m_syncUi.AddRunFnOn_OtherThread([this](){ @@ -81,6 +82,7 @@ void MainWindow::on_pushButton_RunDownload_clicked() ui->pushButton_RunDownload->setText("开始下载"); ui->lineEdit_SetProxy->setEnabled(true); ui->pushButton_StopDownload->setEnabled(false); + ui->pushButton_curlMode->setEnabled(true); if (resp.IsCancel) { return; } diff --git a/m3u8d-qt/version.rc b/m3u8d-qt/version.rc index 81c1679..92de15a 100644 --- a/m3u8d-qt/version.rc +++ b/m3u8d-qt/version.rc @@ -7,8 +7,8 @@ IDI_ICON1 ICON "favicon.ico" #endif VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,5,0,0 - PRODUCTVERSION 1,5,0,0 + FILEVERSION 1,5,1,0 + PRODUCTVERSION 1,5,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS VS_FF_DEBUG @@ -23,7 +23,7 @@ VS_VERSION_INFO VERSIONINFO BEGIN BLOCK "080404b0" BEGIN - VALUE "ProductVersion", "1.5.0.0\0" + VALUE "ProductVersion", "1.5.1.0\0" VALUE "ProductName", "m3u8Ƶع\0" VALUE "LegalCopyright", "https://github.com/orestonce/m3u8d\0" VALUE "FileDescription", "m3u8Ƶع\0"