Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
fix: 密钥文件下载失败的问题
Browse files Browse the repository at this point in the history
fix: #42
fix: #38
  • Loading branch information
HarryWang29 committed Aug 1, 2022
1 parent 1dd87d0 commit 5f882c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NAME=tencentKeTang
BINDIR=bin
VERSION=v0.2.9
VERSION=v0.2.10
BUILDTIME=$(shell date -u)
GOBUILD=CGO_ENABLED=0 go build -ldflags '-w -s -X main.Version=${VERSION}'

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 项目的由来
哎,腾讯课堂的app太难用了,此工具仅仅只是为了将视频下载到本地,使用第三方播放器使用

# v0.2.10更新
* 修复视频密钥文件下载失败的问题

# v0.2.9更新
* 打脸来的太快,这两天实现了终端多行进度条……
* 最近尝试解决qq/微信扫码登录的问题,看来短时间内无法完成了,请采用cookie登录方式
Expand Down
48 changes: 35 additions & 13 deletions ffmpeg/mergeAndDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ func (f *Ffmpeg) downloadTs(vodUrl, dk string, bitrate int, mp4Path string) erro
if err != nil {
return errors.Wrapf(err, "os.MkdirAll(%s)", m3u8Dir)
}
key, err := base64.StdEncoding.DecodeString(dk)
if err != nil {
return errors.Wrap(err, "base64.StdEncoding.DecodeString")
}
keyFile, err := os.OpenFile(filepath.Join(m3u8Dir, "key"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return errors.Wrapf(err, "os.OpenFile(%s)", filepath.Join(m3u8Dir, "index.m3u8"))
}
_, err = keyFile.Write(key)
if err != nil {
return errors.Wrap(err, "keyFile.Write")
if dk != "" {
key, err := base64.StdEncoding.DecodeString(dk)
if err != nil {
return errors.Wrap(err, "base64.StdEncoding.DecodeString")
}
keyFile, err := os.OpenFile(filepath.Join(m3u8Dir, "key"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return errors.Wrapf(err, "os.OpenFile(%s)", filepath.Join(m3u8Dir, "index.m3u8"))
}
_, err = keyFile.Write(key)
if err != nil {
return errors.Wrap(err, "keyFile.Write")
}
_ = keyFile.Close()
}
_ = keyFile.Close()

m3u8, err := httplib.Get(vodUrl).String()
if err != nil {
Expand All @@ -59,14 +61,34 @@ func (f *Ffmpeg) downloadTs(vodUrl, dk string, bitrate int, mp4Path string) erro
//先用lines设置max
f.addDownloadBar(fileName, len(lines))

keys := make(map[string]string)
tsCount := 0
for _, line := range lines {
if strings.HasPrefix(line, "#EXT-X-KEY") {
reg1 := regexp.MustCompile(`URI="(.*)"`)
if reg1 == nil {
return errors.Wrap(err, "regexp.MustCompile")
}
line = reg1.ReplaceAllString(line, fmt.Sprintf(`URI="./%s"`, "key"))
//根据规则提取关键信息
result1 := reg1.FindAllStringSubmatch(line, -1)
if len(result1) == 0 {
return errors.Wrap(err, "regexp.FindAllStringSubmatch")
}
keyUrl := result1[0][1]
keyFileName := "key"
if dk == "" {
if v, ok := keys[keyUrl]; ok {
keyFileName = v
} else {
keyFileName = fmt.Sprintf("key%d", len(keys))
err := httplib.Get(keyUrl).ToFile(filepath.Join(m3u8Dir, keyFileName))
if err != nil {
return errors.Wrap(err, "httplib.Get")
}
keys[keyUrl] = keyFileName
}
}
line = reg1.ReplaceAllString(line, fmt.Sprintf(`URI="./%s"`, keyFileName))
} else if strings.HasPrefix(line, "#") {
} else {
parm := strings.Split(line, "?")
Expand Down

0 comments on commit 5f882c0

Please sign in to comment.