Skip to content

Commit

Permalink
使用 setft 更新文件创建时间:https://github.com/xiaoqidun/setft
Browse files Browse the repository at this point in the history
  • Loading branch information
orestonce committed Oct 7, 2024
1 parent 675a989 commit cf9f9da
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
18 changes: 1 addition & 17 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,25 +295,9 @@ func (this *DownloadEnv) runDownload(req StartDownload_Req, skipInfo SkipTsInfo)
return
}
if req.UseServerSideTime && len(tsFileList) > 0 {
var stat os.FileInfo
stat, err = os.Stat(tsFileList[0])
if err != nil {
this.setErrMsg("读取文件状态失败: " + err.Error())
return
}
mTime := stat.ModTime()
this.logToFile("更新文件时间为:" + mTime.String())
err = updateMp4CreateTime(name, mTime)
if err != nil {
this.setErrMsg("更新mp4创建时间失败: " + err.Error())
return
}
err = os.Chtimes(name, mTime, mTime)
if err != nil {
this.setErrMsg("更新文件创建时间失败: " + err.Error())
if this.updateMp4Time(tsFileList[0], name) == false {
return
}
this.logToFile("更新成功")
}

if skipByHttpCodeLog.Len() > 0 {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/orestonce/go2cpp v0.0.0-20240804085624-460ecb5af956
github.com/orestonce/gopool v0.0.0-20220508090328-d7d56d45b171
github.com/spf13/cobra v1.8.0
github.com/xiaoqidun/setft v0.0.0-20220310121541-be86327699ad
github.com/yapingcat/gomedia v0.0.0-20240823161909-e61bbaf17c9a
golang.org/x/text v0.3.3
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/xiaoqidun/setft v0.0.0-20220310121541-be86327699ad h1:QtuWk6dsrNXc/ugwCBEN0jG52q/4tXRzMvZm4fH6T9g=
github.com/xiaoqidun/setft v0.0.0-20220310121541-be86327699ad/go.mod h1:Jj8p9bgKGTPQ+M8CdUMS9p7Mmdoxa3OAcAjJQBu0CcI=
github.com/yapingcat/gomedia v0.0.0-20240823161909-e61bbaf17c9a h1:rJYjZAZclK++lHPKoW+5eYm1/0uEWbGWMOix3sASPNs=
github.com/yapingcat/gomedia v0.0.0-20240823161909-e61bbaf17c9a/go.mod h1:WSZ59bidJOO40JSJmLqlkBJrjZCtjbKKkygEMfzY/kc=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
Expand Down
24 changes: 24 additions & 0 deletions mp4time.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ package m3u8d
import (
"encoding/binary"
"errors"
"github.com/xiaoqidun/setft"
"github.com/yapingcat/gomedia/go-mp4"
"io"
"os"
"time"
)

func (this *DownloadEnv) updateMp4Time(firstTsName string, mp4FileName string) bool {
stat, err := os.Stat(firstTsName)
if err != nil {
this.setErrMsg("读取文件状态失败: " + err.Error())
return false
}
mTime := stat.ModTime()
this.logToFile("更新文件时间为:" + mTime.String())
err = updateMp4CreateTime(mp4FileName, mTime)
if err != nil {
this.setErrMsg("更新mp4创建时间失败: " + err.Error())
return false
}

err = setft.SetFileTime(mp4FileName, mTime, mTime, mTime)
if err != nil {
this.setErrMsg("更新文件时间属性失败: " + err.Error())
return false
}
this.logToFile("更新成功")
return true
}

func mov_tag(tag [4]byte) uint32 {
return binary.LittleEndian.Uint32(tag[:])
}
Expand Down

0 comments on commit cf9f9da

Please sign in to comment.