From cf9f9da47a4b4f9db4f01575f0add919669bb784 Mon Sep 17 00:00:00 2001 From: orestonce Date: Mon, 7 Oct 2024 08:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20setft=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=EF=BC=9A?= =?UTF-8?q?https://github.com/xiaoqidun/setft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 18 +----------------- go.mod | 1 + go.sum | 2 ++ mp4time.go | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/api.go b/api.go index db1ad6c..baf1544 100644 --- a/api.go +++ b/api.go @@ -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 { diff --git a/go.mod b/go.mod index 1da3901..28a38dc 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index ed34721..6002a73 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/mp4time.go b/mp4time.go index e163aa9..f50028a 100644 --- a/mp4time.go +++ b/mp4time.go @@ -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[:]) }