Skip to content

Commit

Permalink
支持自动识别url
Browse files Browse the repository at this point in the history
  • Loading branch information
orestonce committed Jun 2, 2024
1 parent e9d48a5 commit 6f0606e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -432,3 +433,8 @@ func (this *StartDownload_Req) getVideoId() (id string) {
tmp1 := sha256.Sum256([]byte(this.M3u8Url))
return hex.EncodeToString(tmp1[:])
}

func FindUrlInStr(str string) string {
re := regexp.MustCompile(`https?://[^\s/$.?#].\S*`)
return re.FindString(str)
}
15 changes: 15 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package m3u8d

import (
"fmt"
"strconv"
"testing"
)

func TestFindUrlInStr(t *testing.T) {
urlStr := FindUrlInStr(" https://www.baidu.com/url1.jsp?sxjs=1&s=2&io=%%112 xs")
if urlStr != "https://www.baidu.com/url1.jsp?sxjs=1&s=2&io=%%112" {
fmt.Println(strconv.Quote(urlStr))
t.Fail()
}
}
1 change: 1 addition & 0 deletions export/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func CreateLibForQtUi(mode string) {
ctx.Generate1(m3u8dcpp.MergeTsDir)
ctx.Generate1(m3u8dcpp.MergeStop)
ctx.Generate1(m3u8dcpp.MergeGetProgressPercent)
ctx.Generate1(m3u8d.FindUrlInStr)
if mode == "amd64-static" {
ctx.MustCreateAmd64LibraryInDir("m3u8d-qt")
} else if mode == "386-static" {
Expand Down
35 changes: 35 additions & 0 deletions m3u8d-qt/m3u8d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern __declspec(dllexport) void Go2cppFn_GetFileNameFromUrl(char* in, int inLe
extern __declspec(dllexport) void Go2cppFn_MergeTsDir(char* in, int inLen, char** out, int* outLen);
extern __declspec(dllexport) void Go2cppFn_MergeStop(char* in, int inLen, char** out, int* outLen);
extern __declspec(dllexport) void Go2cppFn_MergeGetProgressPercent(char* in, int inLen, char** out, int* outLen);
extern __declspec(dllexport) void Go2cppFn_FindUrlInStr(char* in, int inLen, char** out, int* outLen);

#ifdef __cplusplus
}
Expand Down Expand Up @@ -830,6 +831,40 @@ MergeGetProgressPercent_Resp MergeGetProgressPercent(){
return retValue;
}

std::string FindUrlInStr(std::string in0){
std::string in;
{
uint32_t tmp5 = in0.length();
char tmp6[4];
tmp6[0] = (uint32_t(tmp5) >> 24) & 0xFF;
tmp6[1] = (uint32_t(tmp5) >> 16) & 0xFF;
tmp6[2] = (uint32_t(tmp5) >> 8) & 0xFF;
tmp6[3] = (uint32_t(tmp5) >> 0) & 0xFF;
in.append(tmp6, 4);
in.append(in0);
}
char *out = NULL;
int outLen = 0;
Go2cppFn_FindUrlInStr((char *)in.data(), in.length(), &out, &outLen);
std::string retValue;
int outIdx = 0;
{
uint32_t tmp7 = 0;
uint32_t tmp8 = uint32_t(uint8_t(out[outIdx+0]) << 24);
uint32_t tmp9 = uint32_t(uint8_t(out[outIdx+1]) << 16);
uint32_t tmp10 = uint32_t(uint8_t(out[outIdx+2]) << 8);
uint32_t tmp11 = uint32_t(uint8_t(out[outIdx+3]) << 0);
tmp7 = tmp8 | tmp9 | tmp10 | tmp11;
outIdx+=4;
retValue = std::string(out+outIdx, out+outIdx+tmp7);
outIdx+=tmp7;
}
if (out != NULL) {
free(out);
}
return retValue;
}



// Qt:
Expand Down
1 change: 1 addition & 0 deletions m3u8d-qt/m3u8d.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct MergeGetProgressPercent_Resp{
MergeGetProgressPercent_Resp(): Percent(0),IsRunning(false){}
};
MergeGetProgressPercent_Resp MergeGetProgressPercent();
std::string FindUrlInStr(std::string in0);

#include <QObject>
#include <QVector>
Expand Down
5 changes: 4 additions & 1 deletion m3u8d-qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ void MainWindow::on_pushButton_curlMode_clicked()

void MainWindow::on_lineEdit_M3u8Url_textChanged(const QString &arg1)
{
if (ui->lineEdit_FileName->text().isEmpty()==false) {
QString urlStr = QString::fromStdString(FindUrlInStr(arg1.toStdString()));
if(urlStr != arg1) {
ui->lineEdit_M3u8Url->setText(urlStr);
Toast::Instance()->SetTips("自动识别修改了url");
return;
}
QString fileName = QString::fromStdString(GetFileNameFromUrl(arg1.toStdString()));
Expand Down

0 comments on commit 6f0606e

Please sign in to comment.