统计TS文件
This commit is contained in:
parent
57e0df0062
commit
7938f80b8e
33
main.go
33
main.go
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: BlackTeay
|
* @Author: BlackTeay
|
||||||
* @Date: 2024-04-30 09:37:39
|
* @Date: 2024-04-30 09:37:39
|
||||||
* @LastEditTime: 2024-05-06 17:24:31
|
* @LastEditTime: 2024-05-06 17:33:58
|
||||||
* @LastEditors: BlackTeay
|
* @LastEditors: BlackTeay
|
||||||
* @Description:
|
* @Description:
|
||||||
* @FilePath: /hls_builder/main.go
|
* @FilePath: /hls_builder/main.go
|
||||||
@ -366,6 +366,13 @@ func upload(localPath string, keyPath string, onComplete func()) {
|
|||||||
fmt.Println("上传到Ucloud")
|
fmt.Println("上传到Ucloud")
|
||||||
fmt.Println("localPath:", localPath)
|
fmt.Println("localPath:", localPath)
|
||||||
fmt.Println("keyPath:", keyPath)
|
fmt.Println("keyPath:", keyPath)
|
||||||
|
// 统计 .ts 文件数量
|
||||||
|
tsCount, err := countTSFiles(localPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to count .ts files: %s", err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Found %d .ts files in %s\n", tsCount, localPath)
|
||||||
|
}
|
||||||
|
|
||||||
us3cliPath := getUs3cliPath()
|
us3cliPath := getUs3cliPath()
|
||||||
bucket := "us3://jlntv-live/replay/" + keyPath
|
bucket := "us3://jlntv-live/replay/" + keyPath
|
||||||
@ -382,7 +389,7 @@ func upload(localPath string, keyPath string, onComplete func()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
buffer := make([]byte, 1024) // 创建一个足够大的buffer
|
buffer := make([]byte, 4096) // 创建一个足够大的buffer
|
||||||
for {
|
for {
|
||||||
n, err := stdout.Read(buffer)
|
n, err := stdout.Read(buffer)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
@ -402,3 +409,25 @@ func upload(localPath string, keyPath string, onComplete func()) {
|
|||||||
onComplete()
|
onComplete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// countTSFiles 统计指定目录下所有 .ts 文件的数量。
|
||||||
|
//
|
||||||
|
// 参数:
|
||||||
|
// directory - 需要统计的目录路径。
|
||||||
|
//
|
||||||
|
// 返回值:
|
||||||
|
// 返回 .ts 文件的数量以及可能出现的错误。
|
||||||
|
func countTSFiles(directory string) (int, error) {
|
||||||
|
var count int // 用于记录 .ts 文件数量
|
||||||
|
err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err // 如果遍历过程中出现错误,则返回该错误
|
||||||
|
}
|
||||||
|
// 检查当前路径项是否为文件且扩展名为 ".ts"
|
||||||
|
if !info.IsDir() && filepath.Ext(info.Name()) == ".ts" {
|
||||||
|
count++ // 如果满足条件,则计数加一
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return count, err // 返回计数结果和可能出现的错误
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user