Skip to content

Commit

Permalink
支持单个m3u8文件内不同ts文件使用不同的加密策略
Browse files Browse the repository at this point in the history
  • Loading branch information
orestonce committed Oct 12, 2024
1 parent 1d77b00 commit cf9a441
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 511 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* 提供macos的图形化界面
* 支持下载aes加密的m3u8
* 内部使用多线程下载ts文件
* 支持单个m3u8文件内不同ts文件使用不同的加密策略
* 支持设置代理: http/socks5
* http代理解释: 要访问的真实url是http协议, 使用代理服务器可见的GET/POST/HEAD...形式; 如果要访问的真实url是https协议, 使用代理服务器不可见的CONNECT形式
* 跳过ts的表达式使用英文逗号','隔开, 编写规则:
Expand Down
28 changes: 12 additions & 16 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/tls"
"encoding/hex"
"fmt"
"github.com/orestonce/m3u8d/mformat"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -160,9 +161,9 @@ func (this *DownloadEnv) runDownload(req StartDownload_Req, skipInfo SkipTsInfo)
}

this.status.SetProgressBarTitle("[1/4]嗅探m3u8")
var m3u8Body []byte
var info mformat.M3U8File
var errMsg string
req.M3u8Url, m3u8Body, errMsg = this.sniffM3u8(req.M3u8Url)
req.M3u8Url, info, errMsg = this.sniffM3u8(req.M3u8Url)
if errMsg != "" {
this.setErrMsg("sniffM3u8: " + errMsg)
return
Expand Down Expand Up @@ -194,24 +195,19 @@ func (this *DownloadEnv) runDownload(req StartDownload_Req, skipInfo SkipTsInfo)
this.logToFile("refresh m3u8 url: " + req.M3u8Url)
}

beginSeq := parseBeginSeq(m3u8Body)
// 获取m3u8地址的内容体
encInfo, err := this.getEncryptInfo(req.M3u8Url, string(m3u8Body))
if err != nil {
this.setErrMsg("getEncryptInfo: " + err.Error())
return
}
this.status.SetProgressBarTitle("[2/4]获取ts列表")
tsList, errMsg := getTsList(beginSeq, req.M3u8Url, string(m3u8Body))
if errMsg != "" {
this.setErrMsg("获取ts列表错误: " + errMsg)
return
}
tsList, skipTsList := skipApplyFilter(tsList, skipInfo, req.Skip_EXT_X_DISCONTINUITY)
tsList := info.GetTsList()
tsList, skipTsList := skipApplyFilter(tsList, skipInfo)
if len(tsList) <= 0 {
this.setErrMsg("需要下载的文件为空")
return
}
// 获取m3u8地址的内容体
err = this.updateMedia(req.M3u8Url, tsList)
if err != nil {
this.setErrMsg("getEncryptInfo: " + err.Error())
return
}

for _, ts := range skipTsList {
this.status.setTsNotWriteReason(&ts, "触发跳过表达式")
Expand All @@ -220,7 +216,7 @@ func (this *DownloadEnv) runDownload(req StartDownload_Req, skipInfo SkipTsInfo)
// 下载ts
this.status.SetProgressBarTitle("[3/4]下载ts")
this.status.SpeedResetBytes()
err = this.downloader(tsList, skipInfo, tsSaveDir, encInfo, req)
err = this.downloader(tsList, skipInfo, tsSaveDir, req)
this.status.SpeedResetBytes()
this.logToFile_TsNotWriteReason()
if err != nil {
Expand Down
Loading

0 comments on commit cf9a441

Please sign in to comment.